ia64/xen-unstable

view extras/mini-os/include/wait.h @ 10843:4f6d858ea570

[PCI] Per-device permissive flag (replaces global permissive flag).
Signed-off-by: Chris Bookholt <hap10@tycho.ncsc.mil>
author kfraser@localhost.localdomain
date Fri Jul 28 12:56:10 2006 +0100 (2006-07-28)
parents 8c21c8ea5fff
children f40079acf646
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 }
47 static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
48 {
49 if (list_empty(&q->thread_list))
50 list_add(&q->thread_list, &h->thread_list);
51 }
53 static inline void remove_wait_queue(struct wait_queue *q)
54 {
55 list_del(&q->thread_list);
56 }
58 static inline void wake_up(struct wait_queue_head *head)
59 {
60 struct list_head *tmp, *next;
61 list_for_each_safe(tmp, next, &head->thread_list)
62 {
63 struct wait_queue *curr;
64 curr = list_entry(tmp, struct wait_queue, thread_list);
65 wake(curr->thread);
66 }
67 }
69 #define add_waiter(w, wq) do { \
70 unsigned long flags; \
71 local_irq_save(flags); \
72 add_wait_queue(&wq, &w); \
73 block(current); \
74 local_irq_restore(flags); \
75 } while (0)
77 #define wait_event(wq, condition) do{ \
78 unsigned long flags; \
79 if(condition) \
80 break; \
81 DEFINE_WAIT(__wait); \
82 for(;;) \
83 { \
84 /* protect the list */ \
85 local_irq_save(flags); \
86 add_wait_queue(&wq, &__wait); \
87 block(current); \
88 local_irq_restore(flags); \
89 if(condition) \
90 break; \
91 schedule(); \
92 } \
93 local_irq_save(flags); \
94 /* need to wake up */ \
95 wake(current); \
96 remove_wait_queue(&__wait); \
97 local_irq_restore(flags); \
98 } while(0)
103 #endif /* __WAIT_H__ */