diff options
author | Keir Fraser <keir@xen.org> | 2010-11-17 16:42:37 +0000 |
---|---|---|
committer | Keir Fraser <keir@xen.org> | 2010-11-17 16:42:37 +0000 |
commit | 9b231b6bc20bc55e55ed5511eb1b74ad3686ad94 (patch) | |
tree | c8bf7ae675e6a0b4e9aac4c0ebd691fd29f71572 /xen/include/xen/wait.h | |
parent | 89b31d1255573286bab1853f47bfa50ff9d89801 (diff) | |
download | xen-9b231b6bc20bc55e55ed5511eb1b74ad3686ad94.tar.gz xen-9b231b6bc20bc55e55ed5511eb1b74ad3686ad94.tar.bz2 xen-9b231b6bc20bc55e55ed5511eb1b74ad3686ad94.zip |
Wait queues, allowing conditional sleep in hypervisor context.
Signed-off-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/include/xen/wait.h')
-rw-r--r-- | xen/include/xen/wait.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/xen/include/xen/wait.h b/xen/include/xen/wait.h new file mode 100644 index 0000000000..c1793fd304 --- /dev/null +++ b/xen/include/xen/wait.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * wait.h + * + * Sleep in hypervisor context for some event to occur. + */ + +#ifndef __XEN_WAIT_H__ +#define __XEN_WAIT_H__ + +#include <xen/types.h> +#include <xen/list.h> +#include <xen/spinlock.h> + +struct waitqueue_head { + spinlock_t lock; + struct list_head list; +}; + +/* Statically define and initialise a waitqueue. */ +#define DEFINE_WAITQUEUE_HEAD(name) \ + struct waitqueue_head name = { \ + .lock = SPIN_LOCK_UNLOCKED, \ + .list = LIST_HEAD_INIT((name).list) \ + } + +/* Dynamically initialise a waitqueue. */ +void init_waitqueue_head(struct waitqueue_head *wq); + +/* Wake all VCPUs waiting on specified waitqueue. */ +void wake_up(struct waitqueue_head *wq); + +/* Wait on specified waitqueue until @condition is true. */ +#define wait_event(wq, condition) \ +do { \ + if ( condition ) \ + break; \ + for ( ; ; ) { \ + prepare_to_wait(&wq); \ + if ( condition ) \ + break; \ + wait(); \ + } \ + finish_wait(&wq); \ +} while (0) + +/* Private functions. */ +int init_waitqueue_vcpu(struct vcpu *v); +void destroy_waitqueue_vcpu(struct vcpu *v); +void prepare_to_wait(struct waitqueue_head *wq); +void wait(void); +void finish_wait(struct waitqueue_head *wq); +void check_wakeup_from_wait(void); + +#endif /* __XEN_WAIT_H__ */ |