diff options
-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. |