|
to:爱德华德
Haha, the code is written in great detail. Dude has worked hard. Tell me about my views, I hope I can advise you more if it is wrong.
Let me talk about the single item first. In this case, I do not support or oppose it.
Not supported: First, it is too penetrating, and it is not a good idea to appear in every device. For your code, I prefer this way:
class CDevice1:public IDevice //No misunderstanding, right? Huh
{
public:
CDevice1(IDeviceInterrupt* kernalFace);
protected:
IDeviceInterrupt* _kernalFace;
void OnInterrupt(void* parameter)
{
_kernalFace->OnDeviceInterrupt(parameter);
}
...
}
int main()
{...; IDevice* devFace1 = new CDevice1(CKernel::GetInstance()); ...}
For the two, you must bother to consider synchronization issues. Too many devices have their own threads, and if they all call back to CWhat, synchronization.. For single
In terms of not only locking synchronization in the construction and destructuring, but also considering more complicated synchronization problems in OnDeviceInterrupt(void*): You can't lock it all at once, so that more than 10 threads are waiting in line during concurrency, which is too inefficient. , Can't do this.
No objection: A single piece is a scorpion shit-only one, the resource consumption is small, and many calls are simple to operate. If you can handle the synchronization problem, it is also a good choice.
Let’s talk about the problem of IDevice. We can’t get a very beautiful IDevice just because we call it "device".
This is ideal. What CWhat wants to do is very practical, and call the work in a targeted manner, just like the OS tells VGA to draw me a pie.
It doesn’t make sense if the OS calls "painting pie" to the sound card, memory, and network card, because although the VGA sound card and the memory are all "devices", they
In terms of the realized functions, there is no commonality. This is what I have always said "This situation determines that an interface like IDeviceFace cannot be extracted for all devices, and it cannot be realized!"
Hehe, I am not born in C, but the actual work is a bit hardware inclined. |
|