patch-2.1.9 linux/include/asm-sparc/semaphore.h
Next file: linux/include/asm-sparc/sigcontext.h
Previous file: linux/include/asm-sparc/segment.h
Back to the patch index
Back to the overall index
- Lines: 43
- Date:
Sat Nov 9 21:39:32 1996
- Orig file:
v2.1.8/linux/include/asm-sparc/semaphore.h
- Orig date:
Thu Jan 1 02:00:00 1970
diff -u --recursive --new-file v2.1.8/linux/include/asm-sparc/semaphore.h linux/include/asm-sparc/semaphore.h
@@ -0,0 +1,42 @@
+#ifndef _SPARC_SEMAPHORE_H
+#define _SPARC_SEMAPHORE_H
+
+/* Dinky, good for nothing, just barely irq safe, Sparc semaphores.
+ *
+ * I'll write better ones later.
+ */
+
+#include <asm/atomic.h>
+
+struct semaphore {
+ atomic_t count;
+ atomic_t waiting;
+ struct wait_queue * wait;
+};
+
+#define MUTEX ((struct semaphore) { 1, 0, NULL })
+#define MUTEX_LOCKED ((struct semaphore) { 0, 0, NULL })
+
+extern void __down(struct semaphore * sem);
+extern void __up(struct semaphore * sem);
+
+/*
+ * This isn't quite as clever as the x86 side, but the gp register
+ * makes things a bit more complicated on the alpha..
+ */
+extern inline void down(struct semaphore * sem)
+{
+ for (;;) {
+ if (atomic_dec_return(&sem->count) >= 0)
+ break;
+ __down(sem);
+ }
+}
+
+extern inline void up(struct semaphore * sem)
+{
+ if (atomic_inc_return(&sem->count) <= 0)
+ __up(sem);
+}
+
+#endif /* !(_SPARC_SEMAPHORE_H) */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov