Date: Mon, 23 Jul 2012 20:20:25 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239708 - in soc2012/gmiller/locking-head: . lib/libwitness Message-ID: <20120723202025.5B8D710657F4@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Mon Jul 23 20:20:25 2012 New Revision: 239708 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239708 Log: r239742@FreeBSD-dev: root | 2012-07-23 12:54:43 -0500 Re-implement pthread_lockorder_begin_np(), pthread_lockorder_next_np(), and pthread_lockorder_end_np() using the lock_info structure. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libwitness/graph.c soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 23 20:20:04 2012 (r239707) +++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 23 20:20:25 2012 (r239708) @@ -27,17 +27,6 @@ #include "witness.h" -struct lock_iter { - SLIST_ENTRY(lock_iter) iter_next; - void *lock; -}; - -struct _pthread_lockorder_private { - SLIST_HEAD(lock_iter_head, lock_iter) lock_iter_head; -}; - -struct lock_info *root = NULL; - static int scan_graph(struct lock_info *graph, struct lock_info *lock) { @@ -88,72 +77,3 @@ return (0); } - -static void -add_graph(struct pthread_lockorder_np *iter_node, struct lock_info *graph_node) -{ - struct lock_iter *iter; - - if (graph_node != NULL) { - iter = malloc(sizeof(struct pthread_lockorder_np)); - iter->lock = graph_node->lock; - SLIST_INSERT_HEAD(&iter_node->_pvt->lock_iter_head, iter, - iter_next); - - add_graph(iter_node, graph_node->sibling); - add_graph(iter_node, graph_node->child); - } -} - -void -pthread_lockorder_begin_np(struct pthread_lockorder_np *node) -{ - /* - 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); - - node->_pvt = malloc(sizeof(struct _pthread_lockorder_private)); - - add_graph(node, root); - - pthread_mutex_unlock(&witness_mtx); -} - -int -pthread_lockorder_next_np(struct pthread_lockorder_np *node) -{ - struct lock_iter *iter; - - iter = SLIST_FIRST(&node->_pvt->lock_iter_head); - if (iter != NULL) { - SLIST_REMOVE_HEAD(&node->_pvt->lock_iter_head, iter_next); - - node->lock = iter->lock; - - free(iter); - - return (1); - } else { - return (0); - } -} - -void -pthread_lockorder_end_np(struct pthread_lockorder_np *node) -{ - struct lock_iter *iter; - - if (node->_pvt != NULL) { - while (!SLIST_EMPTY(&node->_pvt->lock_iter_head)) { - iter = SLIST_FIRST(&node->_pvt->lock_iter_head); - SLIST_REMOVE_HEAD(&node->_pvt->lock_iter_head, - iter_next); - free(iter); - } - - free(node->_pvt); - node->_pvt = NULL; - } -} Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:20:04 2012 (r239707) +++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:20:25 2012 (r239708) @@ -32,6 +32,10 @@ static SLIST_HEAD(lock_info_head, lock_info) lock_info_head = SLIST_HEAD_INITIALIZER(lock_info_head); +struct _pthread_lockorder_private { + struct lock_info *last_record; +}; + struct lock_info * lookup_lock(void *lock) { @@ -120,3 +124,44 @@ } } } + +void +pthread_lockorder_begin_np(struct pthread_lockorder_np *node) +{ + /* + 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); + + node->_pvt = malloc(sizeof(struct _pthread_lockorder_private)); + node->_pvt->last_record = NULL; + + pthread_mutex_unlock(&witness_mtx); +} + +int +pthread_lockorder_next_np(struct pthread_lockorder_np *node) +{ + if (node->_pvt->last_record == NULL) { + node->_pvt->last_record = SLIST_FIRST(&lock_info_head); + } else { + node->_pvt->last_record = SLIST_NEXT(node->_pvt->last_record, + lock_info_next); + } + + if (node->_pvt->last_record != NULL) { + node->lock = node->_pvt->last_record->lock; + + return (1); + } else { + return (0); + } +} + +void +pthread_lockorder_end_np(struct pthread_lockorder_np *node) +{ + free(node->_pvt); + node->_pvt = NULL; +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120723202025.5B8D710657F4>