Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2012 12:04:18 +0000
From:      gmiller@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r238470 - in soc2012/gmiller/locking-head: . lib/libwitness
Message-ID:  <20120628120418.827D4106567B@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gmiller
Date: Thu Jun 28 12:04:18 2012
New Revision: 238470
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238470

Log:
   r238358@FreeBSD-dev:  root | 2012-06-19 22:26:14 -0500
   * Add pthread_mutex_unlock() wrapper
   * Add calls to add_lock() and remove_lock() in the wrappers
   * Add temporary debugging code to make sure the wrapped functions are
     tracking the locks held by the current thread correctly.

Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/lib/libwitness/lists.c
  soc2012/gmiller/locking-head/lib/libwitness/wrappers.c

Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c	Thu Jun 28 11:58:10 2012	(r238469)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c	Thu Jun 28 12:04:18 2012	(r238470)
@@ -27,6 +27,7 @@
 
 #include <sys/queue.h>
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "lists.h"
@@ -34,6 +35,19 @@
 _Thread_local SLIST_HEAD(lock_head, lock_entry) lock_head =
     SLIST_HEAD_INITIALIZER(lock_head);
 
+// XXX: temporary debugging code
+static void
+dump_locks(void) {
+	struct lock_entry *entry;
+	int count = 1;
+
+	SLIST_FOREACH(entry, &lock_head, lock_next) {
+		printf("[%d] %p\n", count++, entry->lock);
+	}
+
+	puts("");
+}
+
 void
 add_lock(void *lock)
 {
@@ -43,6 +57,9 @@
 	entry->lock = lock;
 
 	SLIST_INSERT_HEAD(&lock_head, entry, lock_next);
+
+	printf("inserted lock %p\n", lock);
+	dump_locks();
 }
 
 void
@@ -58,4 +75,7 @@
 			break;
 		}
 	}
+
+	printf("removed lock %p\n", lock);
+	dump_locks();
 }

Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Thu Jun 28 11:58:10 2012	(r238469)
+++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Thu Jun 28 12:04:18 2012	(r238470)
@@ -25,12 +25,38 @@
  *
  */
 
+#include <sys/queue.h>
+
 #include <pthread.h>
+#include <stdio.h>
+
+#include "lists.h"
 
 int	_pthread_mutex_lock(pthread_mutex_t *mutex);
+int	_pthread_mutex_unlock(pthread_mutex_t *mutex);
 
 int
 pthread_mutex_lock(pthread_mutex_t *mutex)
 {
-  return _pthread_mutex_lock(mutex);
+  int ret;
+
+  puts("pthread_mutex_lock()");
+
+  ret = _pthread_mutex_lock(mutex);
+  add_lock(mutex);
+
+  return ret;
+}
+
+int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+  int ret;
+
+  puts("pthread_mutex_unlock()");
+
+  ret = _pthread_mutex_unlock(mutex);
+  remove_lock(mutex);
+
+  return ret;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120628120418.827D4106567B>