socsvn commit: r239443 - in soc2012/gmiller/locking-head: .
lib/libwitness
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Sun Jul 15 22:05:52 UTC 2012
Author: gmiller
Date: Sun Jul 15 22:05:49 2012
New Revision: 239443
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239443
Log:
r239384 at FreeBSD-dev: root | 2012-07-13 19:06:36 -0500
Fix the insert_lock() and log_reversal() calls to correctly use the address of
the lock, not the address of the list entry referring to the lock.
Modified:
soc2012/gmiller/locking-head/ (props changed)
soc2012/gmiller/locking-head/lib/libwitness/graph.c
soc2012/gmiller/locking-head/lib/libwitness/lists.c
soc2012/gmiller/locking-head/lib/libwitness/logs.c
Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/graph.c Sun Jul 15 22:05:38 2012 (r239442)
+++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Sun Jul 15 22:05:49 2012 (r239443)
@@ -33,23 +33,21 @@
scan_graph(struct graph_node *graph, void *lock)
{
struct graph_node *ret;
- struct graph_node *child;
+
+ if (graph == NULL) {
+ return (NULL);
+ }
if (graph->lock == lock) {
return (graph);
}
- child = graph->child;
- while (child != NULL) {
- ret = scan_graph(child, lock);
- if (ret != NULL) {
- return (ret);
- }
-
- child = child->sibling;
+ ret = scan_graph(graph->child, lock);
+ if (ret == NULL) {
+ ret = scan_graph(graph->sibling, lock);
}
- return (NULL);
+ return (ret);
}
static void
@@ -95,7 +93,8 @@
node = malloc(sizeof(struct graph_node));
node->lock = lock;
node->child = NULL;
- node->sibling = NULL;
+ node->sibling = root;
+ root = node;
}
return (node);
Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c Sun Jul 15 22:05:38 2012 (r239442)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c Sun Jul 15 22:05:49 2012 (r239443)
@@ -43,8 +43,8 @@
SLIST_INSERT_HEAD(&lock_head, entry, lock_next);
- if (next != NULL && insert_lock(entry, next) < 0) {
- log_reversal(entry, next);
+ if (next != NULL && insert_lock(entry->lock, next->lock) < 0) {
+ log_reversal(entry->lock, next->lock);
}
}
Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/logs.c Sun Jul 15 22:05:38 2012 (r239442)
+++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Sun Jul 15 22:05:49 2012 (r239443)
@@ -54,13 +54,26 @@
void
pthread_lor_begin_np(struct pthread_lock_order_np *lor)
{
+ /*
+ The lock isn't needed to prevent races, but it is needed to ensure
+ that any locks grabbed by malloc() don't get logged.
+ */
+
+ pthread_mutex_lock(&witness_mtx);
+
lor->_pvt = malloc(sizeof(struct _pthread_lor_private));
lor->_pvt->last_record = NULL;
+
+ pthread_mutex_unlock(&witness_mtx);
}
int
pthread_lor_next_np(struct pthread_lock_order_np *lor)
{
+ int res = 0;
+
+ pthread_mutex_lock(&witness_mtx);
+
if (lor->_pvt->last_record == NULL) {
lor->_pvt->last_record = STAILQ_FIRST(&lor_head);
} else {
@@ -68,14 +81,16 @@
STAILQ_NEXT(lor->_pvt->last_record, lor_next);
}
- if (lor->_pvt->last_record == NULL) {
- return (0);
+ if (lor->_pvt->last_record != NULL) {
+ lor->lock_first = lor->_pvt->last_record->lock_first;
+ lor->lock_second = lor->_pvt->last_record->lock_second;
+
+ res = 1;
}
- lor->lock_first = lor->_pvt->last_record->lock_first;
- lor->lock_second = lor->_pvt->last_record->lock_second;
+ pthread_mutex_unlock(&witness_mtx);
- return (1);
+ return (res);
}
void
@@ -93,8 +108,12 @@
struct lor_entry *lor;
struct lor_entry *lor_temp;
+ pthread_mutex_lock(&witness_mtx);
+
STAILQ_FOREACH_SAFE(lor, &lor_head, lor_next, lor_temp) {
STAILQ_REMOVE(&lor_head, lor, lor_entry, lor_next);
free(lor);
}
+
+ pthread_mutex_unlock(&witness_mtx);
}
More information about the svn-soc-all
mailing list