Browse Source

more aggressively close threads (proper checkin this time)

David Rose 16 years ago
parent
commit
f0d3e65d98
2 changed files with 22 additions and 9 deletions
  1. 21 9
      panda/src/net/connectionWriter.cxx
  2. 1 0
      panda/src/net/connectionWriter.h

+ 21 - 9
panda/src/net/connectionWriter.cxx

@@ -96,15 +96,7 @@ ConnectionWriter::
     _manager->remove_writer(this);
     _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::
 void ConnectionWriter::
 clear_manager() {
 clear_manager() {
   _manager = (ConnectionManager *)NULL;
   _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();
+}

+ 1 - 0
panda/src/net/connectionWriter.h

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