more aggressively close threads (proper checkin this time)

This commit is contained in:
David Rose 2009-03-25 01:55:00 +00:00
parent 233503776c
commit f0d3e65d98
2 changed files with 22 additions and 9 deletions

View File

@ -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();
}

View File

@ -71,6 +71,7 @@ protected:
private:
void thread_run(int thread_index);
bool send_datagram(const NetDatagram &datagram);
void shutdown();
protected:
ConnectionManager *_manager;