patch-2.3.1 linux/include/asm-i386/semaphore.h
Next file: linux/include/asm-m68k/hdreg.h
Previous file: linux/include/asm-i386/io.h
Back to the patch index
Back to the overall index
- Lines: 118
- Date:
Thu May 13 14:52:36 1999
- Orig file:
v2.3.0/linux/include/asm-i386/semaphore.h
- Orig date:
Tue May 11 13:03:59 1999
diff -u --recursive --new-file v2.3.0/linux/include/asm-i386/semaphore.h linux/include/asm-i386/semaphore.h
@@ -27,15 +27,62 @@
#include <asm/system.h>
#include <asm/atomic.h>
#include <asm/spinlock.h>
+#include <linux/wait.h>
struct semaphore {
atomic_t count;
int waking;
- struct wait_queue * wait;
+ wait_queue_head_t wait;
+#if WAITQUEUE_DEBUG
+ long __magic;
+#endif
};
-#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), 0, NULL })
-#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), 0, NULL })
+#if WAITQUEUE_DEBUG
+# define __SEM_DEBUG_INIT(name) \
+ , (int)&(name).__magic
+#else
+# define __SEM_DEBUG_INIT(name)
+#endif
+
+#define __SEMAPHORE_INITIALIZER(name,count) \
+{ ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
+ __SEM_DEBUG_INIT(name) }
+
+#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)
+
+extern inline void sema_init (struct semaphore *sem, int val)
+{
+/*
+ * *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
+ *
+ * i'd rather use the more flexible initialization above, but sadly
+ * GCC 2.7.2.3 emits a bogus warning. EGCS doesnt. Oh well.
+ */
+ atomic_set(&sem->count, val);
+ sem->waking = 0;
+ init_waitqueue_head(&sem->wait);
+#if WAITQUEUE_DEBUG
+ sem->__magic = (int)&sem->__magic;
+#endif
+}
+
+static inline void init_MUTEX (struct semaphore *sem)
+{
+ sema_init(sem, 1);
+}
+
+static inline void init_MUTEX_LOCKED (struct semaphore *sem)
+{
+ sema_init(sem, 0);
+}
asmlinkage void __down_failed(void /* special register calling convention */);
asmlinkage int __down_failed_interruptible(void /* params in registers */);
@@ -49,8 +96,6 @@
extern spinlock_t semaphore_wake_lock;
-#define sema_init(sem, val) atomic_set(&((sem)->count), (val))
-
/*
* This is ugly, but we want the default case to fall through.
* "down_failed" is a special asm handler that calls the C
@@ -58,6 +103,10 @@
*/
extern inline void down(struct semaphore * sem)
{
+#if WAITQUEUE_DEBUG
+ CHECK_MAGIC(sem->__magic);
+#endif
+
__asm__ __volatile__(
"# atomic down operation\n\t"
#ifdef __SMP__
@@ -79,6 +128,10 @@
{
int result;
+#if WAITQUEUE_DEBUG
+ CHECK_MAGIC(sem->__magic);
+#endif
+
__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
#ifdef __SMP__
@@ -102,6 +155,10 @@
{
int result;
+#if WAITQUEUE_DEBUG
+ CHECK_MAGIC(sem->__magic);
+#endif
+
__asm__ __volatile__(
"# atomic interruptible down operation\n\t"
#ifdef __SMP__
@@ -129,6 +186,9 @@
*/
extern inline void up(struct semaphore * sem)
{
+#if WAITQUEUE_DEBUG
+ CHECK_MAGIC(sem->__magic);
+#endif
__asm__ __volatile__(
"# atomic up operation\n\t"
#ifdef __SMP__
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)