Browse Source

Added support for SetProcessAffinityMask

Josh Yelon 19 years ago
parent
commit
2dca55d07e

+ 7 - 0
panda/src/express/config_express.cxx

@@ -60,6 +60,13 @@ ConfigVariableBool keep_temporary_files
           "default) to delete these.  Mainly useful for debugging "
           "when the process goes wrong."));
 
+ConfigVariableBool lock_to_one_cpu
+("lock-to-one-cpu", false,
+ PRC_DESC("Set this to true if you want the entire process to use one "
+          "CPU, even on multi-core and multi-CPU workstations. This is "
+          "mainly a hack to solve a bug in which QueryPerformanceCounter "
+          "returns inconsistent results on multi-core machines. "));
+
 ConfigVariableString encryption_algorithm
 ("encryption-algorithm", "bf-cbc",
  PRC_DESC("This defines the OpenSSL encryption algorithm which is used to "

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

@@ -63,6 +63,8 @@ extern ConfigVariableInt patchfile_zone_size;
 
 extern ConfigVariableBool keep_temporary_files;
 
+extern ConfigVariableBool lock_to_one_cpu;
+
 extern ConfigVariableString encryption_algorithm;
 extern ConfigVariableInt encryption_key_length;
 extern ConfigVariableInt encryption_iteration_count;

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

@@ -132,6 +132,8 @@ get_short_time() {
 //       Access: Protected
 //  Description: 
 ////////////////////////////////////////////////////////////////////
+typedef BOOL (WINAPI * PFNSETPROCESSAFFINITYMASK)(HANDLE, DWORD_PTR);
+
 TrueClock::
 TrueClock() {
   _error_count = 0;
@@ -144,6 +146,17 @@ TrueClock() {
   _last_reported_time_scale = 1.0;
   _report_time_scale_time = 0.0;
 
+  if (lock_to_one_cpu) {
+    HMODULE hker = GetModuleHandle("kernel32");
+    if (hker != 0) {
+      PFNSETPROCESSAFFINITYMASK sp = (PFNSETPROCESSAFFINITYMASK)
+        GetProcAddress(hker, "SetProcessAffinityMask");
+      if (sp != 0) {
+        sp(GetCurrentProcess(), 1);
+      }
+    }
+  }
+  
   if (get_use_high_res_clock()) {
     PN_int64 int_frequency;
     _has_high_res =