From cdb8b09f6b67b270b1c21f1a7f42d5e8a604caa8 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 9 Sep 2005 09:24:25 +0000 Subject: 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 --- extras/mini-os/include/semaphore.h | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 extras/mini-os/include/semaphore.h (limited to 'extras/mini-os/include/semaphore.h') diff --git a/extras/mini-os/include/semaphore.h b/extras/mini-os/include/semaphore.h new file mode 100644 index 0000000000..d30c81e674 --- /dev/null +++ b/extras/mini-os/include/semaphore.h @@ -0,0 +1,46 @@ +#ifndef _SEMAPHORE_H_ +#define _SEMAPHORE_H_ + +#include + +/* + * Implementation of semaphore in Mini-os is simple, because + * there are no preemptive threads, the atomicity is guaranteed. + */ + +struct semaphore +{ + int count; + struct wait_queue_head wait; +}; + + +#define __SEMAPHORE_INITIALIZER(name, n) \ +{ \ + .count = n, \ + .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \ +} + +#define __MUTEX_INITIALIZER(name) \ + __SEMAPHORE_INITIALIZER(name,1) + +#define __DECLARE_SEMAPHORE_GENERIC(name,count) \ + struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) + +#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) + +#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) + +static void inline down(struct semaphore *sem) +{ + wait_event(sem->wait, sem->count > 0); + sem->count--; +} + +static void inline up(struct semaphore *sem) +{ + sem->count++; + wake_up(&sem->wait); +} + +#endif /* _SEMAPHORE_H */ -- cgit v1.2.3