Browse Source

insist on main thread behavior in prepare_for_exit()

David Rose 18 years ago
parent
commit
4a34bda966
1 changed files with 10 additions and 3 deletions
  1. 10 3
      panda/src/pipeline/threadSimpleManager.cxx

+ 10 - 3
panda/src/pipeline/threadSimpleManager.cxx

@@ -22,6 +22,7 @@
 
 
 #include "threadSimpleImpl.h"
 #include "threadSimpleImpl.h"
 #include "blockerSimple.h"
 #include "blockerSimple.h"
+#include "mainThread.h"
 
 
 #ifdef WIN32
 #ifdef WIN32
 #define WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
@@ -232,11 +233,16 @@ next_context() {
 //     Function: ThreadSimpleManager::prepare_for_exit
 //     Function: ThreadSimpleManager::prepare_for_exit
 //       Access: Public
 //       Access: Public
 //  Description: Blocks until all running threads (other than the
 //  Description: Blocks until all running threads (other than the
-//               current thread) have finished.  You should probably
-//               only call this from the main thread.
+//               current thread) have finished.  This only works when
+//               called from the main thread; if called on any other
+//               thread, nothing will happen.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void ThreadSimpleManager::
 void ThreadSimpleManager::
 prepare_for_exit() {
 prepare_for_exit() {
+  if (!_current_thread->_parent_obj->is_exact_type(MainThread::get_class_type())) {
+    return;
+  }
+
   nassertv(_waiting_for_exit == NULL);
   nassertv(_waiting_for_exit == NULL);
   _waiting_for_exit = _current_thread;
   _waiting_for_exit = _current_thread;
 
 
@@ -480,7 +486,8 @@ choose_next_context() {
     
     
     thread_cat.debug()
     thread_cat.debug()
       << "Switching to " << *_current_thread->_parent_obj
       << "Switching to " << *_current_thread->_parent_obj
-      << " (" << _ready.size() << " other threads ready, " << blocked_count
+      << " (" << _ready.size() + _next_ready.size()
+      << " other threads ready, " << blocked_count
       << " blocked, " << _sleeping.size() << " sleeping)\n";
       << " blocked, " << _sleeping.size() << " sleeping)\n";
   }
   }