Date: Thu, 12 Jul 2012 04:37:57 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239297 - in soc2012/gmiller/locking-head: . include lib/libwitness Message-ID: <20120712043757.A88B5106564A@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Thu Jul 12 04:37:56 2012 New Revision: 239297 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239297 Log: r239323@FreeBSD-dev: root | 2012-07-03 20:22:26 -0500 Implement LoR log retrieval functions: * pthread_lor_begin_np() * pthread_lor_next_np() * pthread_lor_end_np() Implement LoR log clearing function pthread_lor_clear_np(). Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/include/pthread_np.h soc2012/gmiller/locking-head/lib/libwitness/logs.c Modified: soc2012/gmiller/locking-head/include/pthread_np.h ============================================================================== --- soc2012/gmiller/locking-head/include/pthread_np.h Thu Jul 12 02:58:45 2012 (r239296) +++ soc2012/gmiller/locking-head/include/pthread_np.h Thu Jul 12 04:37:56 2012 (r239297) @@ -58,7 +58,10 @@ #endif +struct _pthread_lor_private; + struct pthread_lock_order_np { + struct _pthread_lor_private *_pvt; void *lock_first; void *lock_second; }; Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/logs.c Thu Jul 12 02:58:45 2012 (r239296) +++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Thu Jul 12 04:37:56 2012 (r239297) @@ -27,13 +27,74 @@ #include "witness.h" +STAILQ_HEAD(lor_head, lor_entry) lor_head = STAILQ_HEAD_INITIALIZER(lor_head); + +struct lor_entry { + STAILQ_ENTRY(lor_entry) lor_next; + void *lock_first; + void *lock_second; +}; + +struct _pthread_lor_private { + struct lor_entry *last_record; +}; + void log_reversal(void *lock, void *previous) { - struct pthread_lock_order_np *entry; + struct lor_entry *entry; - entry = malloc(sizeof(struct pthread_lock_order_np)); + entry = malloc(sizeof(struct lor_entry)); entry->lock_first = previous; entry->lock_second = lock; + + STAILQ_INSERT_TAIL(&lor_head, entry, lor_next); +} + +void +pthread_lor_begin_np(struct pthread_lock_order_np *lor) +{ + lor->_pvt = malloc(sizeof(struct _pthread_lor_private)); + lor->_pvt->last_record = NULL; +} + +int +pthread_lor_next_np(struct pthread_lock_order_np *lor) +{ + if (lor->_pvt->last_record == NULL) { + lor->_pvt->last_record = STAILQ_FIRST(&lor_head); + } else { + lor->_pvt->last_record = + STAILQ_NEXT(lor->_pvt->last_record, lor_next); + } + + if (lor->_pvt->last_record == NULL) { + return (0); + } + + lor->lock_first = lor->_pvt->last_record->lock_first; + lor->lock_second = lor->_pvt->last_record->lock_second; + + return (1); } +void +pthread_lor_end_np(struct pthread_lock_order_np *lor) +{ + if (lor->_pvt != NULL) { + free(lor->_pvt); + lor->_pvt = NULL; + } +} + +void +pthread_lor_clear_np(void) +{ + struct lor_entry *lor; + struct lor_entry *lor_temp; + + STAILQ_FOREACH_SAFE(lor, &lor_head, lor_next, lor_temp) { + STAILQ_REMOVE(&lor_head, lor, lor_entry, lor_next); + free(lor); + } +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120712043757.A88B5106564A>