From 2dca55d07ee858c86c01bf7f7e53c84f8ca5c67f Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 22 Aug 2006 21:13:25 +0000 Subject: [PATCH] Added support for SetProcessAffinityMask --- panda/src/express/config_express.cxx | 7 +++++++ panda/src/express/config_express.h | 2 ++ panda/src/express/trueClock.cxx | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/panda/src/express/config_express.cxx b/panda/src/express/config_express.cxx index 2c7c453ba1..3469fbfa63 100644 --- a/panda/src/express/config_express.cxx +++ b/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 " diff --git a/panda/src/express/config_express.h b/panda/src/express/config_express.h index 171c753e3f..3741c584e9 100644 --- a/panda/src/express/config_express.h +++ b/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; diff --git a/panda/src/express/trueClock.cxx b/panda/src/express/trueClock.cxx index 3c24e2e9e3..5bfdecd5b5 100644 --- a/panda/src/express/trueClock.cxx +++ b/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 =