patch-2.0.30 linux/include/asm-alpha/semaphore.h

Next file: linux/include/asm-alpha/unistd.h
Previous file: linux/fs/super.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.29/linux/include/asm-alpha/semaphore.h linux/include/asm-alpha/semaphore.h
@@ -8,17 +8,20 @@
  */
 
 #include <asm/atomic.h>
+#include <asm/system.h>
 
 struct semaphore {
 	atomic_t count;
-	atomic_t waiting;
+	atomic_t waking;
+	int lock;			/* to make waking testing atomic */
 	struct wait_queue * wait;
 };
 
-#define MUTEX ((struct semaphore) { 1, 0, NULL })
-#define MUTEX_LOCKED ((struct semaphore) { 0, 0, NULL })
+#define MUTEX ((struct semaphore) { 1, 0, 0, NULL })
+#define MUTEX_LOCKED ((struct semaphore) { 0, 0, 0, NULL })
 
 extern void __down(struct semaphore * sem);
+extern int  __down_interruptible(struct semaphore * sem);
 extern void __up(struct semaphore * sem);
 
 /*
@@ -27,11 +30,33 @@
  */
 extern inline void down(struct semaphore * sem)
 {
-	for (;;) {
-		if (atomic_dec_return(&sem->count) >= 0)
-			break;
+	if (atomic_dec_return(&sem->count) < 0)
 		__down(sem);
-	}
+}
+
+/*
+ * Primitives to spin on a lock.  Needed only for SMP version.
+ */
+extern inline void get_buzz_lock(int *lock_ptr)
+{
+#ifdef __SMP__
+        while (xchg(lock_ptr,1) != 0) ;
+#endif
+} /* get_buzz_lock */
+
+extern inline void give_buzz_lock(int *lock_ptr)
+{
+#ifdef __SMP__
+        *lock_ptr = 0 ;
+#endif
+} /* give_buzz_lock */
+
+extern inline int down_interruptible(struct semaphore * sem)
+{
+	int ret = 0;
+	if (atomic_dec_return(&sem->count) < 0)
+		ret = __down_interruptible(sem);
+	return ret;
 }
 
 extern inline void up(struct semaphore * sem)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov