patch-2.1.36 linux/include/asm-sparc64/semaphore.h

Next file: linux/include/asm-sparc64/signal.h
Previous file: linux/include/asm-sparc64/processor.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.35/linux/include/asm-sparc64/semaphore.h linux/include/asm-sparc64/semaphore.h
@@ -2,8 +2,10 @@
 #define _SPARC64_SEMAPHORE_H
 
 /* These are actually reasonable on the V9. */
+#ifdef __KERNEL__
 
 #include <asm/atomic.h>
+#include <asm/system.h>
 
 struct semaphore {
 	atomic_t count;
@@ -11,8 +13,8 @@
 	struct wait_queue * wait;
 };
 
-#define MUTEX ((struct semaphore) { { 1 }, { 0 }, NULL })
-#define MUTEX_LOCKED ((struct semaphore) { { 0 }, { 0 }, NULL })
+#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), ATOMIC_INIT(0), NULL })
+#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), ATOMIC_INIT(0), NULL })
 
 extern void __down(struct semaphore * sem);
 extern int  __down_interruptible(struct semaphore * sem);
@@ -20,6 +22,23 @@
 
 #define sema_init(sem, val)	atomic_set(&((sem)->count), val)
 
+#define wake_one_more(sem)      atomic_inc(&sem->waking);
+
+extern __inline__ int waking_non_zero(struct semaphore *sem)
+{
+        unsigned long flags;
+        int ret = 0;
+
+        save_flags(flags);
+        cli();
+        if (atomic_read(&sem->waking) > 0) {
+                atomic_dec(&sem->waking);
+                ret = 1;
+        }
+        restore_flags(flags);
+        return ret;
+}
+
 extern __inline__ void down(struct semaphore * sem)
 {
 	if (atomic_dec_return(&sem->count) < 0)
@@ -39,5 +58,7 @@
 	if (atomic_inc_return(&sem->count) <= 0)
 		__up(sem);
 }	
+
+#endif /* __KERNEL__ */
 
 #endif /* !(_SPARC64_SEMAPHORE_H) */

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