ia64/xen-unstable

view extras/mini-os/include/wait.h @ 16520:a583f3a7eafc

Revert 16498:d2bef6551c1263e457aef75ce403ba53652a803f.
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 04 22:54:58 2007 +0000 (2007-12-04)
parents 2fd1ead7fdf5
children 1101ca828ad9
line source
1 #ifndef __WAIT_H__
2 #define __WAIT_H__
4 #include <sched.h>
5 #include <list.h>
6 #include <lib.h>
7 #include <os.h>
9 struct wait_queue
10 {
11 struct thread *thread;
12 struct list_head thread_list;
13 };
15 struct wait_queue_head
16 {
17 /* TODO - lock required? */
18 struct list_head thread_list;
19 };
21 #define DECLARE_WAIT_QUEUE_HEAD(name) \
22 struct wait_queue_head name = \
23 { .thread_list = { &(name).thread_list, &(name).thread_list} }
25 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
26 .thread_list = { &(name).thread_list, &(name).thread_list } }
29 #define DEFINE_WAIT(name) \
30 struct wait_queue name = { \
31 .thread = current, \
32 .thread_list = LIST_HEAD_INIT((name).thread_list), \
33 }
36 static inline void init_waitqueue_head(struct wait_queue_head *h)
37 {
38 INIT_LIST_HEAD(&h->thread_list);
39 }
41 static inline void init_waitqueue_entry(struct wait_queue *q, struct thread *thread)
42 {
43 q->thread = thread;
44 INIT_LIST_HEAD(&q->thread_list);
45 }
48 static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
49 {
50 if (list_empty(&q->thread_list))
51 list_add(&q->thread_list, &h->thread_list);
52 }
54 static inline void remove_wait_queue(struct wait_queue *q)
55 {
56 list_del(&q->thread_list);
57 }
59 static inline void wake_up(struct wait_queue_head *head)
60 {
61 unsigned long flags;
62 struct list_head *tmp, *next;
63 local_irq_save(flags);
64 list_for_each_safe(tmp, next, &head->thread_list)
65 {
66 struct wait_queue *curr;
67 curr = list_entry(tmp, struct wait_queue, thread_list);
68 wake(curr->thread);
69 }
70 local_irq_restore(flags);
71 }
73 #define add_waiter(w, wq) do { \
74 unsigned long flags; \
75 local_irq_save(flags); \
76 add_wait_queue(&wq, &w); \
77 block(current); \
78 local_irq_restore(flags); \
79 } while (0)
81 #define remove_waiter(w) do { \
82 unsigned long flags; \
83 local_irq_save(flags); \
84 remove_wait_queue(&w); \
85 local_irq_restore(flags); \
86 } while (0)
88 #define wait_event(wq, condition) do{ \
89 unsigned long flags; \
90 if(condition) \
91 break; \
92 DEFINE_WAIT(__wait); \
93 for(;;) \
94 { \
95 /* protect the list */ \
96 local_irq_save(flags); \
97 add_wait_queue(&wq, &__wait); \
98 block(current); \
99 local_irq_restore(flags); \
100 if(condition) \
101 break; \
102 schedule(); \
103 } \
104 local_irq_save(flags); \
105 /* need to wake up */ \
106 wake(current); \
107 remove_wait_queue(&__wait); \
108 local_irq_restore(flags); \
109 } while(0)
114 #endif /* __WAIT_H__ */