diff options
author | dwight <dwight@10gen.com> | 2011-04-30 14:59:10 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2011-04-30 14:59:10 -0400 |
commit | 1773ba2f5e6c7358e200450f93900b787179132b (patch) | |
tree | 5e451a6a5778a2203a0def1028ad489b4d9d2dbf /util | |
parent | 227e25c55ef47c54fb899579e2325a41782d8b7a (diff) | |
download | mongo-1773ba2f5e6c7358e200450f93900b787179132b.tar.gz |
List1 test and fix case where orphan called on an empty lsit
Diffstat (limited to 'util')
-rw-r--r-- | util/concurrency/list.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/util/concurrency/list.h b/util/concurrency/list.h index 79a357a89d6..dfbeeefac12 100644 --- a/util/concurrency/list.h +++ b/util/concurrency/list.h @@ -43,10 +43,21 @@ namespace mongo { T *_next; public: Base() : _next(0){} - ~Base(){ assert(0); /* we never want this to happen */ } + ~Base() { assert(false); } // we never want this to happen T* next() const { return _next; } }; + /** note this is safe: + + T* p = mylist.head(); + if( p ) + use(p); + + and this is not: + + if( mylist.head() ) + use( mylist.head() ); // could become 0 + */ T* head() const { return _head; } void push(T* t) { @@ -56,8 +67,9 @@ namespace mongo { _head = t; } - // intentionally leak. + // intentionally leaks. void orphanAll() { + scoped_lock lk(_m); _head = 0; } @@ -67,13 +79,13 @@ namespace mongo { T *&prev = _head; T *n = prev; while( n != t ) { + uassert( 14050 , "List1: item to orphan not in list", n ); prev = n->_next; n = prev; - uassert( 14050 , "item not in list" , n ); } prev = t->_next; if( ++_orphans > 500 ) - log() << "warning orphans=" << _orphans << '\n'; + log() << "warning List1 orphans=" << _orphans << '\n'; } private: |