Skip to content

Commit

Permalink
proc: Handle usleep(0) (yield)
Browse files Browse the repository at this point in the history
DONE: RTOS-677
  • Loading branch information
agkaminski committed Nov 13, 2023
1 parent dcfb262 commit 778e508
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions proc/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,21 +1183,26 @@ int proc_threadSleep(time_t us)

hal_spinlockSet(&threads_common.spinlock, &sc);

now = _proc_gettimeRaw();
/* Handle usleep(0) (yield) */
if (us != 0) {
now = _proc_gettimeRaw();

current = _proc_current();
current->state = SLEEP;
current->wait = NULL;
current->wakeup = now + us;
current->interruptible = 1;
current = _proc_current();
current->state = SLEEP;
current->wait = NULL;
current->wakeup = now + us;
current->interruptible = 1;

lib_rbInsert(&threads_common.sleeping, &current->sleeplinkage);
lib_rbInsert(&threads_common.sleeping, &current->sleeplinkage);

_perf_enqueued(current);
_threads_updateWakeup(now, NULL);
_perf_enqueued(current);
_threads_updateWakeup(now, NULL);
}

if ((err = hal_cpuReschedule(&threads_common.spinlock, &sc)) == -ETIME)
err = hal_cpuReschedule(&threads_common.spinlock, &sc);
if (err == -ETIME) {
err = EOK;
}

return err;
}
Expand Down

0 comments on commit 778e508

Please sign in to comment.