Fix performance of MSVC OpenMP builds
Instead of idling at 100% CPU usage, we're back at 4-5%. For VC2010, an additional hotfix has to be applied to the dll files: http://support.microsoft.com/en-us/kb/2689322
This commit is contained in:
parent
77666ccb2c
commit
c61167472b
1 changed files with 11 additions and 1 deletions
12
src/game.cpp
12
src/game.cpp
|
@ -25,6 +25,9 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#if defined(_OPENMP) && _MSC_VER >= 1600
|
||||
#include <process.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
|
@ -738,7 +741,7 @@ int main(int argc, char** argv)
|
|||
VLDEnable();
|
||||
#endif
|
||||
|
||||
#if defined(_OPENMP) && !defined(_WIN32) && !defined(__APPLE__)
|
||||
#ifdef _OPENMP
|
||||
// Wesnoth is a special case for OMP
|
||||
// OMP wait strategy is to have threads busy-loop for 100ms
|
||||
// if there is nothing to do, they then go to sleep.
|
||||
|
@ -751,11 +754,18 @@ int main(int argc, char** argv)
|
|||
// To avoid that problem, we need to set the OMP_WAIT_POLICY env var
|
||||
// but that var is read by OMP at library loading time (before main)
|
||||
// thus the relaunching of ourselves after setting the variable.
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
if (!getenv("OMP_WAIT_POLICY")) {
|
||||
setenv("OMP_WAIT_POLICY", "PASSIVE", 1);
|
||||
execv(argv[0], argv);
|
||||
}
|
||||
#elif _MSC_VER >= 1600
|
||||
if (!getenv("OMP_WAIT_POLICY")) {
|
||||
_putenv_s("OMP_WAIT_POLICY", "PASSIVE");
|
||||
_execv(argv[0], argv);
|
||||
}
|
||||
#endif
|
||||
#endif //_OPENMP
|
||||
#ifdef _WIN32
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
|
Loading…
Add table
Reference in a new issue