ia64/xen-unstable

view extras/mini-os/include/wait.h @ 19836:d9890e67d2b7

tools: add SHAREDIR to buildmakevars2file

c/s 19818 dropped SHAREDIR from xen/util/path.py, which broke the "xm
new" command. This patch adds SHAREDIR back to the new
buildmakevars2file-closure function.

Signed-off-by: Ryan O'Connor <rjo@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:05:10 2009 +0100 (2009-06-25)
parents 8d41996e6897
children
line source
1 #ifndef __WAIT_H__
2 #define __WAIT_H__
4 #include <mini-os/sched.h>
5 #include <mini-os/os.h>
6 #include <mini-os/waittypes.h>
8 #define DEFINE_WAIT(name) \
9 struct wait_queue name = { \
10 .thread = get_current(), \
11 .thread_list = MINIOS_LIST_HEAD_INIT((name).thread_list), \
12 }
15 static inline void init_waitqueue_head(struct wait_queue_head *h)
16 {
17 MINIOS_INIT_LIST_HEAD(&h->thread_list);
18 }
20 static inline void init_waitqueue_entry(struct wait_queue *q, struct thread *thread)
21 {
22 q->thread = thread;
23 MINIOS_INIT_LIST_HEAD(&q->thread_list);
24 }
27 static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
28 {
29 if (minios_list_empty(&q->thread_list))
30 minios_list_add(&q->thread_list, &h->thread_list);
31 }
33 static inline void remove_wait_queue(struct wait_queue *q)
34 {
35 minios_list_del(&q->thread_list);
36 }
38 static inline void wake_up(struct wait_queue_head *head)
39 {
40 unsigned long flags;
41 struct minios_list_head *tmp, *next;
42 local_irq_save(flags);
43 minios_list_for_each_safe(tmp, next, &head->thread_list)
44 {
45 struct wait_queue *curr;
46 curr = minios_list_entry(tmp, struct wait_queue, thread_list);
47 wake(curr->thread);
48 }
49 local_irq_restore(flags);
50 }
52 #define add_waiter(w, wq) do { \
53 unsigned long flags; \
54 local_irq_save(flags); \
55 add_wait_queue(&wq, &w); \
56 block(get_current()); \
57 local_irq_restore(flags); \
58 } while (0)
60 #define remove_waiter(w) do { \
61 unsigned long flags; \
62 local_irq_save(flags); \
63 remove_wait_queue(&w); \
64 local_irq_restore(flags); \
65 } while (0)
67 #define wait_event_deadline(wq, condition, deadline) do { \
68 unsigned long flags; \
69 DEFINE_WAIT(__wait); \
70 if(condition) \
71 break; \
72 for(;;) \
73 { \
74 /* protect the list */ \
75 local_irq_save(flags); \
76 add_wait_queue(&wq, &__wait); \
77 get_current()->wakeup_time = deadline; \
78 clear_runnable(get_current()); \
79 local_irq_restore(flags); \
80 if((condition) || (deadline && NOW() >= deadline)) \
81 break; \
82 schedule(); \
83 } \
84 local_irq_save(flags); \
85 /* need to wake up */ \
86 wake(get_current()); \
87 remove_wait_queue(&__wait); \
88 local_irq_restore(flags); \
89 } while(0)
91 #define wait_event(wq, condition) wait_event_deadline(wq, condition, 0)
95 #endif /* __WAIT_H__ */