diff --git a/core/kthread.c b/core/kthread.c index 498f67b..85542c0 100644 --- a/core/kthread.c +++ b/core/kthread.c @@ -193,23 +193,30 @@ int kthreadYield() int kthreadMsleep(unsigned long msec) { uint32_t flags; + struct kthread *next, *current; + disable_IRQs(flags); - struct kthread *current = currentThread; + + current = currentThread; assertmsg(current->state == RUNNING, "thread %s is in state %d for %d\n", current->name, current->state, msec); - current->state = SLEEPING; - struct kthread *next = kthreadSelectNext(); - assert(next != current); + + current->state = SLEEPING; current->jiffiesSleeping = msecs_to_jiffies(msec); + next = kthreadSelectNext(); + + assert(next != current); assert(next->state == READY); + currentThread = next; currentThread->state = RUNNING; cpu_context_switch(¤t->cpuState, next->cpuState); + restore_IRQs(flags); return 0; } -struct kthread *getCurrenThread() +struct kthread *getCurrentThread() { return currentThread; } diff --git a/core/kthread.h b/core/kthread.h index 9dfc916..79c9ad0 100644 --- a/core/kthread.h +++ b/core/kthread.h @@ -39,6 +39,6 @@ int kthreadYield(); int kthreadSaveAndYield(struct kthread *); int kthreadMsleep(unsigned long msec); int kthreadOnJieffiesTick(); -struct kthread *getCurrenThread(); +struct kthread *getCurrentThread(); int kthreadAddThread(struct kthread *th); int kthreadUnsched(struct kthread *th); diff --git a/core/synchro.c b/core/synchro.c index f1c9ad0..b004a9e 100644 --- a/core/synchro.c +++ b/core/synchro.c @@ -37,7 +37,7 @@ int mutexFree(struct mutex *m) #ifdef DEBUG if (m->owner) { printf("Warning: freeing a owned mutex 0x%. owned by 0x%p 0x%p\n", m, m->owner, - getCurrenThread()); + getCurrentThread()); } #endif list_delete(waitQueues, m->wait); @@ -57,7 +57,7 @@ int mutexLock(struct mutex *m) struct kthread *current; disable_IRQs(flags); - current = getCurrenThread(); + current = getCurrentThread(); assert(m->owner != current); wait_event(m->wait, m->owner == NULL); m->owner = current; @@ -72,7 +72,7 @@ int mutexUnlock(struct mutex *m) uint32_t flags; disable_IRQs(flags); - assert(m->owner == getCurrenThread()); + assert(m->owner == getCurrentThread()); m->owner = NULL; diff --git a/core/wait.c b/core/wait.c index dccf354..e9871ee 100644 --- a/core/wait.c +++ b/core/wait.c @@ -26,7 +26,7 @@ int wait(struct wait_queue *wq) disable_IRQs(flags); - current = getCurrenThread(); + current = getCurrentThread(); kthreadUnsched(current); list_add_tail(wq->thread, current); current->state = WAITING;