aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/include/wait.h
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-09-09 09:24:25 +0000
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2005-09-09 09:24:25 +0000
commitcdb8b09f6b67b270b1c21f1a7f42d5e8a604caa8 (patch)
tree414d05b171df34e0125f29731a8ba12e280297d9 /extras/mini-os/include/wait.h
parentc125eb9c047b908b2bb18e5cf4a88355a1526a25 (diff)
downloadxen-cdb8b09f6b67b270b1c21f1a7f42d5e8a604caa8.tar.gz
xen-cdb8b09f6b67b270b1c21f1a7f42d5e8a604caa8.tar.bz2
xen-cdb8b09f6b67b270b1c21f1a7f42d5e8a604caa8.zip
Xenbus implementation ported from Linux to Mini-os, simple thread support introduced
to simplify the porting. 64 bit version of Mini-os now compiles, but does not work because of the pagetables and some bits of scheduler not being written. Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
Diffstat (limited to 'extras/mini-os/include/wait.h')
-rw-r--r--extras/mini-os/include/wait.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/extras/mini-os/include/wait.h b/extras/mini-os/include/wait.h
new file mode 100644
index 0000000000..4c23855620
--- /dev/null
+++ b/extras/mini-os/include/wait.h
@@ -0,0 +1,91 @@
+#ifndef __WAIT_H__
+#define __WAIT_H__
+
+#include <sched.h>
+#include <list.h>
+#include <lib.h>
+#include <os.h>
+
+struct wait_queue
+{
+ struct thread *thread;
+ struct list_head thread_list;
+};
+
+struct wait_queue_head
+{
+ /* TODO - lock required? */
+ struct list_head thread_list;
+};
+
+#define DECLARE_WAIT_QUEUE_HEAD(name) \
+ struct wait_queue_head name = \
+ { .thread_list = { &(name).thread_list, &(name).thread_list} }
+
+#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
+ .thread_list = { &(name).thread_list, &(name).thread_list } }
+
+
+#define DEFINE_WAIT(name) \
+struct wait_queue name = { \
+ .thread = current, \
+ .thread_list = LIST_HEAD_INIT((name).thread_list), \
+}
+
+
+
+static inline void init_waitqueue_entry(struct wait_queue *q, struct thread *thread)
+{
+ q->thread = thread;
+}
+
+
+static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
+{
+ if (list_empty(&q->thread_list))
+ list_add(&q->thread_list, &h->thread_list);
+}
+
+static inline void remove_wait_queue(struct wait_queue *q)
+{
+ list_del(&q->thread_list);
+}
+
+static inline void wake_up(struct wait_queue_head *head)
+{
+ struct list_head *tmp, *next;
+ list_for_each_safe(tmp, next, &head->thread_list)
+ {
+ struct wait_queue *curr;
+ curr = list_entry(tmp, struct wait_queue, thread_list);
+ wake(curr->thread);
+ }
+}
+
+#define wait_event(wq, condition) do{ \
+ unsigned long flags; \
+ if(condition) \
+ break; \
+ DEFINE_WAIT(__wait); \
+ for(;;) \
+ { \
+ /* protect the list */ \
+ local_irq_save(flags); \
+ add_wait_queue(&wq, &__wait); \
+ block(current); \
+ local_irq_restore(flags); \
+ if(condition) \
+ break; \
+ schedule(); \
+ } \
+ local_irq_save(flags); \
+ /* need to wake up */ \
+ wake(current); \
+ remove_wait_queue(&__wait); \
+ local_irq_restore(flags); \
+} while(0)
+
+
+
+
+#endif /* __WAIT_H__ */