Browse Source

x11display: add x-init-threads var to call XInitThreads()

This is off by default, but could be used if you stumble upon a race condition issue with X11 and threading.
rdb 7 years ago
parent
commit
bafb0ac3db

+ 5 - 0
panda/src/x11display/config_x11display.cxx

@@ -40,6 +40,11 @@ ConfigVariableBool x_error_abort
           "of an error from the X window system.  This can make it easier "
           "of an error from the X window system.  This can make it easier "
           "to discover where these errors are generated."));
           "to discover where these errors are generated."));
 
 
+ConfigVariableBool x_init_threads
+("x-init-threads", false,
+ PRC_DESC("Set this true to ask Panda3D to call XInitThreads() upon loading "
+          "the display module, which may help with some threading issues."));
+
 ConfigVariableInt x_wheel_up_button
 ConfigVariableInt x_wheel_up_button
 ("x-wheel-up-button", 4,
 ("x-wheel-up-button", 4,
  PRC_DESC("This is the mouse button index of the wheel_up event: which "
  PRC_DESC("This is the mouse button index of the wheel_up event: which "

+ 1 - 0
panda/src/x11display/config_x11display.h

@@ -26,6 +26,7 @@ extern EXPCL_PANDAX11 void init_libx11display();
 
 
 extern ConfigVariableString display_cfg;
 extern ConfigVariableString display_cfg;
 extern ConfigVariableBool x_error_abort;
 extern ConfigVariableBool x_error_abort;
+extern ConfigVariableBool x_init_threads;
 
 
 extern ConfigVariableInt x_wheel_up_button;
 extern ConfigVariableInt x_wheel_up_button;
 extern ConfigVariableInt x_wheel_down_button;
 extern ConfigVariableInt x_wheel_down_button;

+ 6 - 0
panda/src/x11display/x11GraphicsPipe.cxx

@@ -66,6 +66,12 @@ x11GraphicsPipe(const std::string &display) :
   _im = (XIM)nullptr;
   _im = (XIM)nullptr;
   _hidden_cursor = None;
   _hidden_cursor = None;
 
 
+  // According to the documentation, we should call this before making any
+  // other Xlib calls if we wish to use the Xlib locking system.
+  if (x_init_threads) {
+    XInitThreads();
+  }
+
   install_error_handlers();
   install_error_handlers();
 
 
   _display = XOpenDisplay(display_spec.c_str());
   _display = XOpenDisplay(display_spec.c_str());