diff options
author | Christian Cunningham <cc@localhost> | 2022-02-01 20:36:30 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-02-01 20:36:30 -0700 |
commit | 7d3884b5cfc282dbdfe5d9a22d8b2b343280b8af (patch) | |
tree | a3e5e5376c35cce48d1e2d907720646448c5e2ba /src/sys/schedule.c | |
parent | 98793badc1c1d3e4bfd735fdecd3d2d731701ab3 (diff) |
Thread yield control to any other threads
Diffstat (limited to 'src/sys/schedule.c')
-rw-r--r-- | src/sys/schedule.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/sys/schedule.c b/src/sys/schedule.c index 6f2a72d..70aebb9 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -156,3 +156,16 @@ void* get_rthread_roffset(void) { return &scheduler.thread_queues[scheduler.rthread->priority].ready.roffset; } + +void yield(void) +{ + struct Thread* rthread = scheduler.rthread; + if (rthread == &usrloopthread) + return; + unsigned char priority = rthread->priority; + struct ThreadRotBuffer* trb = &scheduler.thread_queues[priority].ready; + trb->roffset += 1; + trb->roffset %= TQUEUE_MAX; + trb->queue[trb->woffset++] = rthread; + trb->roffset %= TQUEUE_MAX; +} |