mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
scheduler: handle interruptions in sched_yield() when sleeping as to prevent lost wakeup
This commit is contained in:
@@ -44,6 +44,7 @@ typedef struct thread_t {
|
|||||||
bool sleepintstatus;
|
bool sleepintstatus;
|
||||||
spinlock_t sleeplock;
|
spinlock_t sleeplock;
|
||||||
int wakeupreason;
|
int wakeupreason;
|
||||||
|
bool shouldexit;
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
|
||||||
typedef struct proc_t {
|
typedef struct proc_t {
|
||||||
|
|||||||
@@ -262,6 +262,14 @@ static void yield(context_t *context) {
|
|||||||
|
|
||||||
thread_t *next = runqueuenext(sleeping ? 0x0fffffff : thread->priority);
|
thread_t *next = runqueuenext(sleeping ? 0x0fffffff : thread->priority);
|
||||||
|
|
||||||
|
if (sleeping && thread->shouldexit && (thread->flags & SCHED_THREAD_FLAGS_INTERRUPTIBLE)) {
|
||||||
|
sleeping = false;
|
||||||
|
next = NULL;
|
||||||
|
thread->flags &= ~(SCHED_THREAD_FLAGS_SLEEP | SCHED_THREAD_FLAGS_INTERRUPTIBLE);
|
||||||
|
thread->wakeupreason = SCHED_WAKEUP_REASON_INTERRUPTED;
|
||||||
|
spinlock_release(&thread->sleeplock);
|
||||||
|
}
|
||||||
|
|
||||||
if (next || sleeping) {
|
if (next || sleeping) {
|
||||||
ARCH_CONTEXT_THREADSAVE(thread, context);
|
ARCH_CONTEXT_THREADSAVE(thread, context);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user