[netfilter-cvslog] r4140 - in trunk/nfsim/kernelenv: . include

rusty at netfilter.org rusty at netfilter.org
Wed Jul 20 17:47:32 CEST 2005


Author: rusty at netfilter.org
Date: 2005-07-20 17:47:04 +0200 (Wed, 20 Jul 2005)
New Revision: 4140

Modified:
   trunk/nfsim/kernelenv/include/kernelenv.h
   trunk/nfsim/kernelenv/kernelenv.c
Log:
Simply use the spinlock code for semaphores: that gets better leak reporting

Modified: trunk/nfsim/kernelenv/include/kernelenv.h
===================================================================
--- trunk/nfsim/kernelenv/include/kernelenv.h	2005-07-20 09:17:34 UTC (rev 4139)
+++ trunk/nfsim/kernelenv/include/kernelenv.h	2005-07-20 15:47:04 UTC (rev 4140)
@@ -956,12 +956,11 @@
 
 /* semaphore.h */
 
-/* We don't support generic semaphores: we use a simple talloc to track use */
+/* Just like a spinlock, but type-incompatible. */
 struct semaphore {
-	unsigned int count;
-	unsigned int limit;
+	spinlock_t lock;
 };
-#define DECLARE_MUTEX(name) struct semaphore name = { 1, 1 }
+#define DECLARE_MUTEX(name) struct semaphore name = { SPIN_LOCK_UNLOCKED }
 
 #define down(x) __down((x),__location__)
 #define down_interruptible(x) __down_interruptible((x),__location__)

Modified: trunk/nfsim/kernelenv/kernelenv.c
===================================================================
--- trunk/nfsim/kernelenv/kernelenv.c	2005-07-20 09:17:34 UTC (rev 4139)
+++ trunk/nfsim/kernelenv/kernelenv.c	2005-07-20 15:47:04 UTC (rev 4140)
@@ -676,10 +676,7 @@
 /* semaphore */
 void __down(struct semaphore *sem, const char *location)
 {
-	if (!(sem->count)--)
-		barf("down() unavailable at %s\n", location);
-
-	field_attach_static(sem, location, NULL);
+	__generic_write_lock(&sem->lock, location);
 }
 
 int __down_interruptible(struct semaphore *sem, const char *location)
@@ -687,34 +684,28 @@
 	if (should_i_fail(location))
 		return -EINTR;
 
-	if (!(sem->count)--)
-		barf("down() unavailable at %s\n", location);
-
-	field_attach_static(sem, location, NULL);
+	__down(sem, location);
 	return 0;
 }
 
 void __up(struct semaphore *sem, const char *location)
 {
-	if (++(sem->count) > sem->limit)
-		panic("up() unavailable at %s\n", location);
-	field_detach_all(sem);
+	__generic_write_unlock(&sem->lock, location);
 }
 
 int __down_trylock(struct semaphore *sem, const char *location)
 {
-	if (sem->count) {
-		sem->count--;
-		field_attach_static(sem, location, NULL);
+	if (sem->lock.lock)
 		return 0;
-	}
+	__down(sem, location);
 	return 1;
 }
 
 void sema_init(struct semaphore *sem, int val)
 {
-	sem->count = val;
-	sem->limit = val;
+	if (val)
+		barf("Non-zero-init semaphores not supported");
+	spin_lock_init(&sem->lock);
 }
 
 /* bitops.h */




More information about the netfilter-cvslog mailing list