From f0d3e65d985c7a4d3626992de6999d73eba577cd Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 25 Mar 2009 01:55:00 +0000 Subject: [PATCH] more aggressively close threads (proper checkin this time) --- panda/src/net/connectionWriter.cxx | 30 +++++++++++++++++++++--------- panda/src/net/connectionWriter.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/panda/src/net/connectionWriter.cxx b/panda/src/net/connectionWriter.cxx index 97a2093be7..b429110d82 100644 --- a/panda/src/net/connectionWriter.cxx +++ b/panda/src/net/connectionWriter.cxx @@ -96,15 +96,7 @@ ConnectionWriter:: _manager->remove_writer(this); } - // First, shutdown the queue. This will tell our threads they're - // done. - _queue.shutdown(); - - // Now wait for all threads to terminate. - Threads::iterator ti; - for (ti = _threads.begin(); ti != _threads.end(); ++ti) { - (*ti)->join(); - } + shutdown(); } //////////////////////////////////////////////////////////////////// @@ -341,6 +333,7 @@ get_tcp_header_size() const { void ConnectionWriter:: clear_manager() { _manager = (ConnectionManager *)NULL; + shutdown(); } //////////////////////////////////////////////////////////////////// @@ -362,3 +355,22 @@ thread_run(int thread_index) { } } } + +//////////////////////////////////////////////////////////////////// +// Function: ConnectionWriter::shutdown +// Access: Private +// Description: Stops all the threads and cleans them up. +//////////////////////////////////////////////////////////////////// +void ConnectionWriter:: +shutdown() { + // First, shutdown the queue. This will tell our threads they're + // done. + _queue.shutdown(); + + // Now wait for all threads to terminate. + Threads::iterator ti; + for (ti = _threads.begin(); ti != _threads.end(); ++ti) { + (*ti)->join(); + } + _threads.clear(); +} diff --git a/panda/src/net/connectionWriter.h b/panda/src/net/connectionWriter.h index 9ab4c875e1..30a1ac9322 100644 --- a/panda/src/net/connectionWriter.h +++ b/panda/src/net/connectionWriter.h @@ -71,6 +71,7 @@ protected: private: void thread_run(int thread_index); bool send_datagram(const NetDatagram &datagram); + void shutdown(); protected: ConnectionManager *_manager;