MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Init

Method Init

Source/Engine/Threading/ThreadPool.cpp:67–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65ThreadPoolService ThreadPoolServiceInstance;
66
67bool ThreadPoolService::Init()
68{
69 PROFILE_MEM(EngineThreading);
70
71 // Spawn threads
72 const CPUInfo cpuInfo = Platform::GetCPUInfo();
73 const int32 count = Math::Clamp<int32>(cpuInfo.ProcessorCoreCount - 1, 2, PLATFORM_THREADS_LIMIT / 2);
74 LOG(Info, "Spawning {0} Thread Pool workers", count);
75 ThreadPoolImpl::Threads.Resize(count);
76 for (int32 i = 0; i < count; i++)
77 {
78 auto runnable = New<SimpleRunnable>(true);
79 runnable->OnWork.Bind(ThreadPool::ThreadProc);
80 auto thread = Thread::Create(runnable, String::Format(TEXT("Thread Pool {0}"), i));
81 if (thread == nullptr)
82 {
83 LOG(Error, "Failed to spawn {0} thread in the Thread Pool", i + 1);
84 return true;
85 }
86 ThreadPoolImpl::Threads[i] = thread;
87 }
88
89 return false;
90}
91
92void ThreadPoolService::BeforeExit()
93{

Callers

nothing calls this directly

Calls 4

CreateFunction · 0.50
FormatFunction · 0.50
ResizeMethod · 0.45
BindMethod · 0.45

Tested by

no test coverage detected