diff options
author | Richard Braun <rbraun@sceen.net> | 2017-08-27 16:45:37 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-08-27 16:45:37 +0200 |
commit | 791a6563cd955f59e04084f1fc20aadbbc6ae25f (patch) | |
tree | 914569337e26f75f5294007507f44ab65b807864 /kern/condition.h | |
parent | d3d0b5245942055aa7478d2adb20f1359ef772f7 (diff) |
kern/condition: implement timed waits
Diffstat (limited to 'kern/condition.h')
-rw-r--r-- | kern/condition.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/kern/condition.h b/kern/condition.h index 0ce8d94..90a59f0 100644 --- a/kern/condition.h +++ b/kern/condition.h @@ -27,6 +27,8 @@ #ifndef _KERN_CONDITION_H #define _KERN_CONDITION_H +#include <stdint.h> + #include <kern/condition_types.h> #include <kern/mutex_types.h> @@ -35,20 +37,21 @@ struct condition; /* * Initialize a condition variable. */ -static inline void -condition_init(struct condition *condition) -{ - condition->nr_sleeping_waiters = 0; - condition->nr_pending_waiters = 0; -} +#define condition_init(c) ((void)(c)) /* - * Wait for a wake-up on the given condition variable. + * Wait for a signal on the given condition variable. * * The associated mutex must be locked when calling this function. * It is unlocked before waiting and relocked before returning. + * + * When bounding the duration of the wait, the caller must pass an absolute + * time in ticks, and ERROR_TIMEDOUT is returned if that time is reached + * before the sleep queue is signalled. */ void condition_wait(struct condition *condition, struct mutex *mutex); +int condition_timedwait(struct condition *condition, + struct mutex *mutex, uint64_t ticks); /* * Wake up one (signal) or all (broadcast) threads waiting on a |