This commit is contained in:
Mathieu Maret 2020-08-16 00:24:59 +02:00
parent 6922f6dfa4
commit 9c6c4f3470
4 changed files with 17 additions and 10 deletions

View File

@ -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(&current->cpuState, next->cpuState);
restore_IRQs(flags);
return 0;
}
struct kthread *getCurrenThread()
struct kthread *getCurrentThread()
{
return currentThread;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;