diff options
author | Richard Braun <rbraun@sceen.net> | 2017-08-27 17:10:04 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-08-27 17:10:04 +0200 |
commit | 20aa997e8347d5b37e1b3e39f79ac0b2309b506e (patch) | |
tree | 2e74103532ffa382be35b05ddbe1063237a2b4d6 | |
parent | dd43dd17d7fd82af9001a28709320dac7348f223 (diff) |
kern/thread: add the thread_delay function
-rw-r--r-- | kern/thread.c | 15 | ||||
-rw-r--r-- | kern/thread.h | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/kern/thread.c b/kern/thread.c index 73e1cfb8..043f14de 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -2555,6 +2555,21 @@ thread_timedsleep(struct spinlock *interlock, const void *wchan_addr, return thread_sleep_common(interlock, wchan_addr, wchan_desc, true, ticks); } +void +thread_delay(uint64_t ticks, bool absolute) +{ + thread_preempt_disable(); + + if (!absolute) { + /* Add a tick to avoid quantization errors */ + ticks += clock_get_time() + 1; + } + + thread_timedsleep(NULL, thread_self(), "delay", ticks); + + thread_preempt_enable(); +} + void __init thread_run_scheduler(void) { diff --git a/kern/thread.h b/kern/thread.h index 04eea2b5..e84300c9 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -231,6 +231,11 @@ int thread_timedsleep(struct spinlock *interlock, const void *wchan_addr, int thread_wakeup(struct thread *thread); /* + * Suspend execution of the calling thread. + */ +void thread_delay(uint64_t ticks, bool absolute); + +/* * Start running threads on the local processor. * * Interrupts must be disabled when calling this function. |