瀏覽代碼

protect from reentry

David Rose 16 年之前
父節點
當前提交
b71e4e1a35

+ 19 - 0
direct/src/plugin/p3dWinSplashWindow.cxx

@@ -209,6 +209,25 @@ unregister_window_class() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DWinSplashWindow::button_click_detected
+//       Access: Protected, Virtual
+//  Description: Called when a button click by the user is detected in
+//               set_mouse_data(), this method simply turns around and
+//               notifies the instance.  It's a virtual method to give
+//               subclasses a chance to redirect this message to the
+//               main thread or process, as necessary.
+////////////////////////////////////////////////////////////////////
+void P3DWinSplashWindow::
+button_click_detected() {
+  // Since this message is detected in the sub-thread in the Windows
+  // case, we have to protect ourselves from re-entry by grabbing the
+  // global _api_lock.
+  ACQUIRE_LOCK(_api_lock);
+  P3DSplashWindow::button_click_detected();
+  RELEASE_LOCK(_api_lock);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DWinSplashWindow::start_thread
 //       Access: Private

+ 3 - 0
direct/src/plugin/p3dWinSplashWindow.h

@@ -43,6 +43,9 @@ public:
   static void register_window_class();
   static void unregister_window_class();
 
+protected:
+  virtual void button_click_detected();
+
 private:
   void start_thread();
   void stop_thread();

+ 3 - 0
direct/src/plugin/p3d_plugin_common.h

@@ -42,6 +42,9 @@ using namespace std;
 extern ostream *nout_stream;
 #define nout (*nout_stream)
 
+// Appears in p3d_plugin.cxx.
+extern LOCK _api_lock;
+
 // A convenience function for formatting a generic P3D_object to an
 // ostream.
 inline ostream &