|
From: Frank M. H. <fm...@us...> - 2007-03-01 19:06:12
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/thread_safe_signals/detail In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18067/boost/thread_safe_signals/detail Modified Files: signal_template.hpp Log Message: Tweaked constant-time garbage collection to clean up long contiguous blocks of dangling connections in one pass. Index: signal_template.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/thread_safe_signals/detail/signal_template.hpp,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- signal_template.hpp 1 Mar 2007 15:57:25 -0000 1.40 +++ signal_template.hpp 1 Mar 2007 19:06:09 -0000 1.41 @@ -290,15 +290,14 @@ // clean up disconnected connections void nolock_cleanup_connections(bool grab_tracked, - const typename connection_list_type::iterator &begin, const typename connection_list_type::iterator &end) const + const typename connection_list_type::iterator &begin, bool break_on_connected = false) const { - assert(_shared_state.unique()); + BOOST_ASSERT(_shared_state.unique()); typename connection_list_type::iterator it; - for(it = begin; it != end;) + for(it = begin; it != _shared_state->connection_bodies.end();) { bool connected; { - // skip over slots that are busy typename ConnectionBody<group_key_type, SlotFunction, ThreadingModel>::mutex_type::scoped_lock lock((*it)->mutex); if(grab_tracked) (*it)->nolock_slot_expired(); @@ -310,13 +309,15 @@ }else { ++it; + if(break_on_connected) break; } } - _garbage_collector_it = end; + _garbage_collector_it = it; } // clean up a few connections in constant time void nolock_cleanup_connections(bool grab_tracked) const { + BOOST_ASSERT(_shared_state.unique()); typename connection_list_type::iterator begin; if(_garbage_collector_it == _shared_state->connection_bodies.end()) { @@ -325,10 +326,7 @@ { begin = _garbage_collector_it; } - typename connection_list_type::iterator end = begin; - ++end; - if(end != _shared_state->connection_bodies.end()) ++end; - nolock_cleanup_connections(grab_tracked, begin, end); + nolock_cleanup_connections(grab_tracked, begin, true); } /* Make a new copy of the slot list if it is currently being read somewhere else */ @@ -338,7 +336,7 @@ { shared_ptr<invocation_state> newState(new invocation_state(*_shared_state)); _shared_state = newState; - nolock_cleanup_connections(true, _shared_state->connection_bodies.begin(), _shared_state->connection_bodies.end()); + nolock_cleanup_connections(true, _shared_state->connection_bodies.begin()); }else { nolock_cleanup_connections(true); |