patch-2.4.22 linux-2.4.22/include/asm-mips64/semaphore.h
Next file: linux-2.4.22/include/asm-mips64/serial.h
Previous file: linux-2.4.22/include/asm-mips64/semaphore-helper.h
Back to the patch index
Back to the overall index
- Lines: 92
- Date:
2003-08-25 04:44:44.000000000 -0700
- Orig file:
linux-2.4.21/include/asm-mips64/semaphore.h
- Orig date:
2002-11-28 15:53:15.000000000 -0800
diff -urN linux-2.4.21/include/asm-mips64/semaphore.h linux-2.4.22/include/asm-mips64/semaphore.h
@@ -1,14 +1,17 @@
/*
+ * This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (C) 1996 Linus Torvalds
- * Copyright (C) 1998, 1999, 2000, 2001 Ralf Baechle
- * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
+ * Copyright (C) 1998, 99, 2000, 01 Ralf Baechle
+ * Copyright (C) 1999, 2000, 01 Silicon Graphics, Inc.
+ * Copyright (C) 2000, 01 MIPS Technologies, Inc.
*/
#ifndef _ASM_SEMAPHORE_H
#define _ASM_SEMAPHORE_H
+#include <linux/config.h>
#include <asm/system.h>
#include <asm/atomic.h>
#include <linux/spinlock.h>
@@ -27,7 +30,7 @@
#if WAITQUEUE_DEBUG
long __magic;
#endif
-};
+} __attribute__((aligned(8)));
#if WAITQUEUE_DEBUG
# define __SEM_DEBUG_INIT(name) \
@@ -105,6 +108,22 @@
return ret;
}
+#ifndef CONFIG_CPU_HAS_LLDSCD
+
+/*
+ * Non-blockingly attempt to down() a semaphore.
+ * Returns zero if we acquired it
+ */
+static inline int down_trylock(struct semaphore * sem)
+{
+ int ret = 0;
+ if (atomic_dec_return(&sem->count) < 0)
+ ret = __down_trylock(sem);
+ return ret;
+}
+
+#else
+
/*
* down_trylock returns 0 on success, 1 if we failed to get the lock.
*
@@ -137,19 +156,19 @@
__asm__ __volatile__(
".set\tmips3\t\t\t# down_trylock\n"
"0:\tlld\t%1, %4\n\t"
- "\tdli\t%3, 0x0000000100000000\n\t"
- "\tdsubu\t%1, %3\n\t"
- "\tli\t%0, 0\n\t"
- "\tbgez\t%1, 2f\n\t"
- "\tsll\t%2, %1, 0\n\t"
- "\tblez\t%2, 1f\n\t"
- "\tdaddiu\t%1, %1, -1\n\t"
- "\tb\t2f\n"
+ "dli\t%3, 0x0000000100000000\n\t"
+ "dsubu\t%1, %3\n\t"
+ "li\t%0, 0\n\t"
+ "bgez\t%1, 2f\n\t"
+ "sll\t%2, %1, 0\n\t"
+ "blez\t%2, 1f\n\t"
+ "daddiu\t%1, %1, -1\n\t"
+ "b\t2f\n"
"1:\tdaddu\t%1, %1, %3\n\t"
- "\tli\t%0, 1\n"
+ "li\t%0, 1\n"
"2:\tscd\t%1, %4\n\t"
- "\tbeqz\t%1, 0b\n\t"
- "\t.set\tmips0"
+ "beqz\t%1, 0b\n\t"
+ ".set\tmips0"
: "=&r"(ret), "=&r"(tmp), "=&r"(tmp2), "=&r"(sub)
: "m"(*sem)
: "memory");
@@ -157,6 +176,8 @@
return ret;
}
+#endif /* CONFIG_CPU_HAS_LLDSCD */
+
/*
* Note! This is subtle. We jump to wake people up only if
* the semaphore was negative (== somebody was waiting on it).
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)