Browse Source

add yield-timeslice

David Rose 22 years ago
parent
commit
91451f3f80

+ 4 - 0
panda/src/display/config_display.cxx

@@ -63,6 +63,10 @@ const string threading_model = config_display.GetString("threading-model", "");
 // until an explicit call to flip_frame() or the next render_frame().
 const bool auto_flip = config_display.GetBool("auto-flip", true);
 
+// Set this true to yield the timeslice at the end of the frame to be
+// more polite to other applications that are trying to run.
+const bool yield_timeslice = config_display.GetBool("yield-timeslice", false);
+
 // Use the variable load-display to specifiy the name of the default
 // graphics display library or GraphicsPipe to load.  It is the name
 // of a shared library (or * for all libraries named in aux-display),

+ 1 - 0
panda/src/display/config_display.h

@@ -35,6 +35,7 @@ extern const bool pstats_unused_states;
 
 extern const string threading_model;
 extern const bool auto_flip;
+extern const bool yield_timeslice;
 
 extern EXPCL_PANDA void init_libdisplay();
 

+ 17 - 0
panda/src/display/graphicsEngine.cxx

@@ -30,6 +30,14 @@
 #include "mutexHolder.h"
 #include "string_utils.h"
 
+#if defined(WIN32)
+  #define WINDOWS_LEAN_AND_MEAN
+  #include <wtypes.h>
+  #undef WINDOWS_LEAN_AND_MEAN  
+#else
+  #include <sys/time.h>
+#endif
+
 #ifndef CPPPARSER
 PStatCollector GraphicsEngine::_cull_pcollector("Cull");
 PStatCollector GraphicsEngine::_draw_pcollector("Draw");
@@ -347,6 +355,15 @@ render_frame() {
   if (_threads.empty() && _auto_flip) {
     do_flip_frame();
   }
+
+  if (yield_timeslice) { 
+    // Nap for a moment to yield the timeslice, to be polite to other
+    // running applications.
+    struct timeval tv;
+    tv.tv_sec = 0;
+    tv.tv_usec = 0;
+    select(0, NULL, NULL, NULL, &tv);
+  }
 }
 
 ////////////////////////////////////////////////////////////////////