Explorar o código

attempt to protect paranoid_clock from multithread

David Rose %!s(int64=18) %!d(string=hai) anos
pai
achega
97f794be0e
Modificáronse 2 ficheiros con 7 adicións e 0 borrados
  1. 5 0
      panda/src/express/trueClock.cxx
  2. 2 0
      panda/src/express/trueClock.h

+ 5 - 0
panda/src/express/trueClock.cxx

@@ -94,6 +94,10 @@ double TrueClock::
 get_short_time() {
 get_short_time() {
   double time;
   double time;
 
 
+  if (_paranoid_clock) {
+    _lock.lock();
+  }
+
   if (_has_high_res) {
   if (_has_high_res) {
     // Use the high-resolution clock.  This is of questionable value,
     // Use the high-resolution clock.  This is of questionable value,
     // since (a) on some OS's and hardware, the low 24 bits can
     // since (a) on some OS's and hardware, the low 24 bits can
@@ -123,6 +127,7 @@ get_short_time() {
     // Check for rollforwards, rollbacks, and compensate for Speed
     // Check for rollforwards, rollbacks, and compensate for Speed
     // Gear type programs by verifying against the time of day clock.
     // Gear type programs by verifying against the time of day clock.
     time = correct_time(time);
     time = correct_time(time);
+    _lock.release();
   }
   }
 
 
   return time;
   return time;

+ 2 - 0
panda/src/express/trueClock.h

@@ -22,6 +22,7 @@
 #include "pandabase.h"
 #include "pandabase.h"
 #include "typedef.h"
 #include "typedef.h"
 #include "pdeque.h"
 #include "pdeque.h"
+#include "mutexImpl.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : TrueClock
 //       Class : TrueClock
@@ -100,6 +101,7 @@ protected:
     CC_speed_up,
     CC_speed_up,
   };
   };
   ChaseClock _chase_clock;
   ChaseClock _chase_clock;
+  MutexImpl _lock;
 #endif  // WIN32
 #endif  // WIN32
 };
 };