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 /kern/thread.c | |
parent | dd43dd17d7fd82af9001a28709320dac7348f223 (diff) |
kern/thread: add the thread_delay function
Diffstat (limited to 'kern/thread.c')
-rw-r--r-- | kern/thread.c | 15 |
1 files changed, 15 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) { |