Changeset View
Changeset View
Standalone View
Standalone View
source/ps/ThreadUtil.cpp
Show All 14 Lines | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include <thread> | #include <thread> | ||||
#include "ThreadUtil.h" | #include "ThreadUtil.h" | ||||
#include "ConfigDB.h" | |||||
vladislavbelov: Wrong include order. | |||||
Not Done Inline ActionsThis one too #include "ConfigDB.h" #include "ThreadUtil.h" #include <thread> Stan: This one too
```lang=cpp
#include "ConfigDB.h"
#include "ThreadUtil.h"
#include <thread>
```
| |||||
static bool g_MainThreadSet; | static bool g_MainThreadSet; | ||||
static std::thread::id g_MainThread; | static std::thread::id g_MainThread; | ||||
bool ThreadUtil::IsMainThread() | bool ThreadUtil::IsMainThread() | ||||
{ | { | ||||
// If SetMainThread hasn't been called yet, this is probably being | // If SetMainThread hasn't been called yet, this is probably being | ||||
// called at static initialisation time, so it must be the main thread | // called at static initialisation time, so it must be the main thread | ||||
if (!g_MainThreadSet) | if (!g_MainThreadSet) | ||||
return true; | return true; | ||||
return g_MainThread == std::this_thread::get_id(); | return g_MainThread == std::this_thread::get_id(); | ||||
} | } | ||||
void ThreadUtil::SetMainThread() | void ThreadUtil::SetMainThread() | ||||
{ | { | ||||
g_MainThread = std::this_thread::get_id(); | g_MainThread = std::this_thread::get_id(); | ||||
g_MainThreadSet = true; | g_MainThreadSet = true; | ||||
} | } | ||||
u32 ThreadUtil::GetNumberOfPathfindingThreads() | |||||
{ | |||||
u32 wantedThreads = 0; | |||||
if (CConfigDB::IsInitialised()) | |||||
CFG_GET_VAL("multithreading.pathfinder", wantedThreads); | |||||
Done Inline Actionswell, RC except for this bit which I can now remove :p wraitii: well, RC except for this bit which I can now remove :p | |||||
Not Done Inline ActionsIs the todo above still to do ? Stan: Is the todo above still to do ? | |||||
Done Inline ActionsYes that can be removed now, just need to do it. wraitii: Yes that can be removed now, just need to do it. | |||||
// By default use (# of cores - 1) cores | |||||
if (wantedThreads == 0) | |||||
return std::thread::hardware_concurrency() - 1; | |||||
return wantedThreads; | |||||
Not Done Inline ActionsWhy it's not clamped by some reasonable value (like max thread count or CPU * ThreadsPerCPU? vladislavbelov: Why it's not clamped by some reasonable value (like max thread count or `CPU * ThreadsPerCPU`? | |||||
Not Done Inline Actions^ Stan: ^ | |||||
} | |||||
Not Done Inline ActionsShouldn't it be like when compiling where you type j(numberofcores +1) Stan: Shouldn't it be like when compiling where you type j(numberofcores +1) | |||||
Done Inline ActionsNah, we want one core left for the main thread to do its own thing if possible. wraitii: Nah, we want one core left for the main thread to do its own thing if possible. | |||||
Not Done Inline ActionsHow can we guarantee Oses will do that ? Stan: How can we guarantee Oses will do that ? | |||||
Done Inline ActionsThere's no such thing as guaranteeing with multithreaded code, but this leaves at least one core open for regular computations (such as graphics). wraitii: There's no such thing as guaranteeing with multithreaded code, but this leaves at least one… |
Wildfire Games · Phabricator
Wrong include order.