diff --git a/src/sys/sys/device.c b/src/sys/sys/device.c index b204237..112684a 100644 --- a/src/sys/sys/device.c +++ b/src/sys/sys/device.c @@ -28,10 +28,12 @@ *****************************************************************************************/ #include +#include #include /* Linked list of drivers loaded in the system accessable by the subsystem only */ static struct deviceNode *devices = 0x0; +static spinLock_t deviceSpinLock = SPIN_LOCK_INITIALIZER; /***************************************************************************************** @@ -45,13 +47,21 @@ *****************************************************************************************/ int deviceAdd(int minor,char type,struct deviceInterface *devInfo) { - struct deviceNode *tmpDev = kmalloc(sizeof(struct deviceNode)); + struct deviceNode *tmpDev = 0x0; + + spinLock(&deviceSpinLock); + + tmpDev = (struct deviceNode *)kmalloc(sizeof(struct deviceNode)); + tmpDev->prev = 0x0; tmpDev->minor = minor; tmpDev->type = type; tmpDev->devInfo = devInfo; tmpDev->next = devices; devices = tmpDev; + + spinUnlock(&deviceSpinLock); + return(tmpDev->devInfo->init(tmpDev)); } @@ -67,11 +77,18 @@ *****************************************************************************************/ struct deviceNode *deviceFind(int major,int minor) { - struct deviceNode *tmp = devices; - for (;tmp;tmp=tmp->next) { - if ((tmp->devInfo->major == major) && (tmp->minor == minor)) - return(tmp); + struct deviceNode *tmpDev = 0x0; + + spinLock(&deviceSpinLock); + + for (tmpDev = devices;tmpDev;tmpDev=tmpDev->next) { + if ((tmpDev->devInfo->major == major) && (tmpDev->minor == minor)) { + spinUnlock(&deviceSpinLock); + return(tmpDev); + } } + + spinUnlock(&deviceSpinLock); return(0x0); } @@ -86,6 +103,9 @@ int deviceRemove(struct deviceNode *deviceToDelete) { struct deviceNode *current, *previous; + +spinLock(&deviceSpinLock); + current = devices; previous=NULL; while(current != NULL) @@ -103,9 +123,11 @@ if(current == devices) devices = devices->next; else previous->next = current->next; kfree(current); + spinUnlock(&deviceSpinLock); return 1; } + spinUnlock(&deviceSpinLock); return 0x0; } @@ -113,6 +135,11 @@ /*** $Log$ + Revision 1.9 2004/05/22 02:40:04 ionix + + + fixed typo in device.h and initialized previous in device.c :) + Revision 1.8 2004/05/22 02:34:03 ionix