diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 3bced8f..28f8de8 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -42,6 +42,8 @@ #include #include +#include + static kTask_t *taskList = 0x0; static kTask_t *delList = 0x0; static uInt32 nextID = -1; @@ -49,7 +51,7 @@ kTask_t *_current = 0x0; kTask_t *_usedMath = 0x0; - +static spinLock_t schedulerSpinLock = SPIN_LOCK_INITIALIZER; /************************************************************************ @@ -80,7 +82,10 @@ void sched(){ uInt32 memAddr = 0x0; kTask_t *tmpTask = 0x0; - + + if (!spinTryLock(&schedulerSpinLock)) + return; + tmpTask = _current->next; schedStart: /* Yield the next task from the current prio queue */ @@ -116,10 +121,15 @@ ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); ubixGDT[4].descriptor.access = '\x89'; + spinUnlock(&schedulerSpinLock); asm("ljmp $0x20,$0\n"); asm("sti"); } - + else + { + spinUnlock(&schedulerSpinLock); + } + return; } @@ -136,10 +146,15 @@ tmpTask->state = NEW; tmpTask->oInfo.cwd = (char *)kmalloc(1024); + + spinLock(&schedulerSpinLock); + tmpTask->next = taskList; tmpTask->prev = 0x0; taskList->prev = tmpTask; taskList = tmpTask; + + spinUnlock(&schedulerSpinLock); return(tmpTask); } @@ -261,6 +276,9 @@ /*** $Log$ + Revision 1.54 2004/09/11 17:39:51 apwillia + CHRIS: Don't mess with scheduler structures outside the schedulergvim endtask.c Finally fixed the race condition. + Revision 1.53 2004/09/11 14:55:25 reddawg memset newly allocated tasks diff --git a/src/sys/net/net/sys_arch.c b/src/sys/net/net/sys_arch.c index 850750e..38d43bb 100644 --- a/src/sys/net/net/sys_arch.c +++ b/src/sys/net/net/sys_arch.c @@ -35,6 +35,9 @@ * Modified to work with the ubix operating system * * $Log$ + * Revision 1.5 2004/09/07 20:58:35 reddawg + * time to roll back i can't think straight by friday + * * Revision 1.4 2004/05/25 22:49:29 reddawg * Stupid Old CODE!!! * @@ -76,9 +79,12 @@ #include "net/opt.h" #include "net/stats.h" +#include + #define UMAX(a, b) ((a) > (b) ? (a) : (b)) static struct sys_thread *threads = 0x0; +static spinLock_t netThreadSpinlock = SPIN_LOCK_INITIALIZER; struct sys_mbox_msg { struct sys_mbox_msg *next; @@ -118,11 +124,14 @@ struct sys_thread *st; kTask_t *pt; pt = ubthread_self(); + spinLock(&netThreadSpinlock); for(st = threads; st != NULL; st = st->next) { if(st->ubthread == pt) { + spinUnlock(&netThreadSpinlock); return st; } } + spinUnlock(&netThreadSpinlock); kprintf("sys: current_thread: could not find current thread!\n"); kprintf("This is due to a race condition in the LinuxThreads\n"); kprintf("ubthreads implementation. Start the program again.\n"); @@ -155,10 +164,12 @@ thread = kmalloc(sizeof(struct sys_thread)); kprintf("THREAD: [0x%X]\n",thread); + spinLock(&netThreadSpinlock); thread->next = threads; thread->timeouts.next = NULL; thread->ubthread = 0x0; threads = thread; + spinUnlock(&netThreadSpinlock); /*