Browse Source

clean up ConnectionRepository on exit

David Rose 16 years ago
parent
commit
72da0ee5f1

+ 4 - 1
direct/src/distributed/ConnectionRepository.py

@@ -51,7 +51,9 @@ class ConnectionRepository(
         DoInterestManager.__init__(self)
         DoCollectionManager.__init__(self)
         self.setPythonRepository(self)
-        
+
+        base.finalExitCallbacks.append(self.shutdown)
+
         self.config = config
 
         if self.config.GetBool('verbose-repository'):
@@ -591,6 +593,7 @@ class ConnectionRepository(
     def readerPollUntilEmpty(self, task):
         while self.readerPollOnce():
             pass
+        Thread.forceYield()
         return Task.cont
 
     def readerPollOnce(self):

+ 16 - 0
direct/src/distributed/cConnectionRepository.cxx

@@ -665,6 +665,22 @@ disconnect() {
   _simulated_disconnect = false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CConnectionRepository::shutdown
+//       Access: Published
+//  Description: May be called at application shutdown to ensure all
+//               threads are cleaned up.
+////////////////////////////////////////////////////////////////////
+void CConnectionRepository::
+shutdown() {
+  disconnect();
+
+  #ifdef HAVE_NET
+  _cw.shutdown();
+  _qcr.shutdown();
+  #endif  // HAVE_NET
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CConnectionRepository::do_check_datagram
 //       Access: Private

+ 1 - 0
direct/src/distributed/cConnectionRepository.h

@@ -144,6 +144,7 @@ PUBLISHED:
   bool flush();
 
   void disconnect();
+  void shutdown();
 
   INLINE void set_simulated_disconnect(bool simulated_disconnect);
   INLINE bool get_simulated_disconnect() const;

+ 3 - 3
direct/src/showbase/ShowBase.py

@@ -429,6 +429,9 @@ class ShowBase(DirectObject.DirectObject):
 
         This function is designed to be safe to call multiple times."""
 
+        for cb in self.finalExitCallbacks:
+            cb()
+
         # [gjeon] restore sticky key settings
         if self.config.GetBool('disable-sticky-keys', 0):
             allowAccessibilityShortcutKeys(True)
@@ -457,9 +460,6 @@ class ShowBase(DirectObject.DirectObject):
 
         vfs = VirtualFileSystem.getGlobalPtr()
         vfs.unmountAll()
-
-        for cb in self.finalExitCallbacks:
-            cb()
         
 
     def exitfunc(self):