svn commit: r210790 - projects/ofed/head/sys/ofed/include/linux
Jeff Roberson
jeff at FreeBSD.org
Tue Aug 3 08:38:26 UTC 2010
Author: jeff
Date: Tue Aug 3 08:38:25 2010
New Revision: 210790
URL: http://svn.freebsd.org/changeset/base/210790
Log:
- Convert the linux semaphores to use BSD sempahores rather than sx locks.
There are places where we need counting semaphore semantics. This is
unfortunate since sema(9) is not implemented with the most expedient
possible mechanism.
Sponsored by: Isilon Systems, iX Systems, and Panasas.
Modified:
projects/ofed/head/sys/ofed/include/linux/semaphore.h
Modified: projects/ofed/head/sys/ofed/include/linux/semaphore.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/semaphore.h Tue Aug 3 08:37:16 2010 (r210789)
+++ projects/ofed/head/sys/ofed/include/linux/semaphore.h Tue Aug 3 08:38:25 2010 (r210790)
@@ -30,25 +30,35 @@
#include <sys/param.h>
#include <sys/lock.h>
-#include <sys/sx.h>
+#include <sys/sema.h>
+/*
+ * XXX BSD semaphores are disused and slow. They also do not provide a
+ * sema_wait_sig method. This must be resolved eventually.
+ */
struct semaphore {
- struct sx sx;
+ struct sema sema;
};
-#define init_MUTEX(_rw) sx_init_flags(&(_rw)->sx, \
- "lnxsema", SX_NOWITNESS)
-#define down(_rw) sx_xlock(&(_rw)->sx)
-#define down_interruptible(_rw) sx_xlock_sig(&(_rw)->sx)
-#define down_trylock(_rw) !sx_try_xlock(&(_rw)->sx)
-#define up(_rw) sx_xunlock(&(_rw)->sx)
+#define down(_sem) sema_wait(&(_sem)->sema)
+#define down_interruptible(_sem) sema_wait(&(_sem)->sema), 0
+#define down_trylock(_sem) !sema_trywait(&(_sem)->sema)
+#define up(_sem) sema_post(&(_sem)->sema)
static inline void
-sema_init(struct semaphore *sem, int val)
+linux_sema_init(struct semaphore *sem, int val)
{
- init_MUTEX(sem);
- if (val == 0)
- down(sem);
+
+ sema_init(&sem->sema, val, "lnxsema");
}
+static inline void
+init_MUTEX(struct semaphore *sem)
+{
+
+ sema_init(&sem->sema, 1, "lnxsema");
+}
+
+#define sema_init linux_sema_init
+
#endif /* _LINUX_SEMAPHORE_H_ */
More information about the svn-src-projects
mailing list