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;