Add PLATFORM_THREADS_LIMIT for maximum concurrency limiting
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
#include "Engine/Graphics/Models/SkeletonData.h"
|
#include "Engine/Graphics/Models/SkeletonData.h"
|
||||||
#include "Engine/Scripting/Scripting.h"
|
#include "Engine/Scripting/Scripting.h"
|
||||||
|
|
||||||
ThreadLocal<AnimGraphContext, 64> AnimGraphExecutor::Context;
|
ThreadLocal<AnimGraphContext> AnimGraphExecutor::Context;
|
||||||
|
|
||||||
RootMotionData RootMotionData::Identity = { Vector3(0.0f), Quaternion(0.0f, 0.0f, 0.0f, 1.0f) };
|
RootMotionData RootMotionData::Identity = { Vector3(0.0f), Quaternion(0.0f, 0.0f, 0.0f, 1.0f) };
|
||||||
|
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ private:
|
|||||||
int32 _skeletonNodesCount = 0;
|
int32 _skeletonNodesCount = 0;
|
||||||
|
|
||||||
// Per-thread context to allow async execution
|
// Per-thread context to allow async execution
|
||||||
static ThreadLocal<AnimGraphContext, 64> Context;
|
static ThreadLocal<AnimGraphContext> Context;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace
|
|||||||
VisualScripting::StackFrame* Stack;
|
VisualScripting::StackFrame* Stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
ThreadLocal<VisualScriptThread, 32> ThreadStacks;
|
ThreadLocal<VisualScriptThread> ThreadStacks;
|
||||||
VisualScriptingBinaryModule VisualScriptingModule;
|
VisualScriptingBinaryModule VisualScriptingModule;
|
||||||
VisualScriptExecutor VisualScriptingExecutor;
|
VisualScriptExecutor VisualScriptingExecutor;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "Engine/Threading/ThreadLocal.h"
|
#include "Engine/Threading/ThreadLocal.h"
|
||||||
|
|
||||||
// Use a cached storage for the sorting (one per thread to reduce locking)
|
// Use a cached storage for the sorting (one per thread to reduce locking)
|
||||||
ThreadLocal<Sorting::SortingStack, 64> SortingStacks;
|
ThreadLocal<Sorting::SortingStack> SortingStacks;
|
||||||
|
|
||||||
Sorting::SortingStack& Sorting::SortingStack::Get()
|
Sorting::SortingStack& Sorting::SortingStack::Get()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "Engine/Particles/ParticleEffect.h"
|
#include "Engine/Particles/ParticleEffect.h"
|
||||||
#include "Engine/Engine/Time.h"
|
#include "Engine/Engine/Time.h"
|
||||||
|
|
||||||
ThreadLocal<ParticleEmitterGraphCPUContext, 64> ParticleEmitterGraphCPUExecutor::Context;
|
ThreadLocal<ParticleEmitterGraphCPUContext> ParticleEmitterGraphCPUExecutor::Context;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ private:
|
|||||||
ParticleEmitterGraphCPU& _graph;
|
ParticleEmitterGraphCPU& _graph;
|
||||||
|
|
||||||
// Per-thread context to allow async execution
|
// Per-thread context to allow async execution
|
||||||
static ThreadLocal<ParticleEmitterGraphCPUContext, 64> Context;
|
static ThreadLocal<ParticleEmitterGraphCPUContext> Context;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,9 @@ API_ENUM() enum class ArchitectureType
|
|||||||
#ifndef PLATFORM_LINE_TERMINATOR
|
#ifndef PLATFORM_LINE_TERMINATOR
|
||||||
#define PLATFORM_LINE_TERMINATOR "\n"
|
#define PLATFORM_LINE_TERMINATOR "\n"
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef PLATFORM_THREADS_LIMIT
|
||||||
|
#define PLATFORM_THREADS_LIMIT 64
|
||||||
|
#endif
|
||||||
#define PLATFORM_32BITS (!PLATFORM_64BITS)
|
#define PLATFORM_32BITS (!PLATFORM_64BITS)
|
||||||
|
|
||||||
// Platform family defines
|
// Platform family defines
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ Action Scripting::ScriptsLoaded;
|
|||||||
Action Scripting::ScriptsUnload;
|
Action Scripting::ScriptsUnload;
|
||||||
Action Scripting::ScriptsReloading;
|
Action Scripting::ScriptsReloading;
|
||||||
Action Scripting::ScriptsReloaded;
|
Action Scripting::ScriptsReloaded;
|
||||||
ThreadLocal<Scripting::IdsMappingTable*, 32, true> Scripting::ObjectsLookupIdMapping;
|
ThreadLocal<Scripting::IdsMappingTable*, PLATFORM_THREADS_LIMIT, true> Scripting::ObjectsLookupIdMapping;
|
||||||
ScriptingService ScriptingServiceInstance;
|
ScriptingService ScriptingServiceInstance;
|
||||||
|
|
||||||
bool initFlaxEngine();
|
bool initFlaxEngine();
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The objects lookup identifier mapping used to override the object ids on FindObject call (used by the object references deserialization).
|
/// The objects lookup identifier mapping used to override the object ids on FindObject call (used by the object references deserialization).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static ThreadLocal<IdsMappingTable*, 32, true> ObjectsLookupIdMapping;
|
static ThreadLocal<IdsMappingTable*, PLATFORM_THREADS_LIMIT, true> ObjectsLookupIdMapping;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the object by the given identifier. Searches registered scene objects and optionally assets. Logs warning if fails.
|
/// Finds the object by the given identifier. Searches registered scene objects and optionally assets. Logs warning if fails.
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
JobSystemService JobSystemInstance;
|
JobSystemService JobSystemInstance;
|
||||||
Thread* Threads[32] = {};
|
Thread* Threads[PLATFORM_THREADS_LIMIT] = {};
|
||||||
int32 ThreadsCount = 0;
|
int32 ThreadsCount = 0;
|
||||||
bool JobStartingOnDispatch = true;
|
bool JobStartingOnDispatch = true;
|
||||||
volatile int64 ExitFlag = 0;
|
volatile int64 ExitFlag = 0;
|
||||||
|
|||||||
@@ -5,16 +5,14 @@
|
|||||||
#include "Engine/Core/Types/BaseTypes.h"
|
#include "Engine/Core/Types/BaseTypes.h"
|
||||||
#include "Engine/Core/Collections/Array.h"
|
#include "Engine/Core/Collections/Array.h"
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
|
#include "Engine/Platform/Platform.h"
|
||||||
// Maximum amount of threads with an access to the thread local variable (we use static limit due to engine threading design)
|
|
||||||
#define THREAD_LOCAL_MAX_CAPACITY 16
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Per-thread local variable storage.
|
/// Per-thread local variable storage.
|
||||||
/// Implemented using atomic with per-thread storage indexed via thread id hashing.
|
/// Implemented using atomic with per-thread storage indexed via thread id hashing.
|
||||||
/// ForConsider using 'THREADLOCAL' define before the variable instead.
|
/// ForConsider using 'THREADLOCAL' define before the variable instead.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template<typename T, int32 MaxThreads = THREAD_LOCAL_MAX_CAPACITY, bool ClearMemory = true>
|
template<typename T, int32 MaxThreads = PLATFORM_THREADS_LIMIT, bool ClearMemory = true>
|
||||||
class ThreadLocal
|
class ThreadLocal
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -104,7 +102,7 @@ protected:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Per thread local object
|
/// Per thread local object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template<typename T, int32 MaxThreads = THREAD_LOCAL_MAX_CAPACITY>
|
template<typename T, int32 MaxThreads = PLATFORM_THREADS_LIMIT>
|
||||||
class ThreadLocalObject : public ThreadLocal<T*, MaxThreads>
|
class ThreadLocalObject : public ThreadLocal<T*, MaxThreads>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ ThreadPoolService ThreadPoolServiceInstance;
|
|||||||
bool ThreadPoolService::Init()
|
bool ThreadPoolService::Init()
|
||||||
{
|
{
|
||||||
// Spawn threads
|
// Spawn threads
|
||||||
const int32 numThreads = Math::Max<int32>(2, Platform::GetCPUInfo().ProcessorCoreCount - 1);
|
const int32 numThreads = Math::Clamp<int32>(Platform::GetCPUInfo().ProcessorCoreCount - 1, 2, PLATFORM_THREADS_LIMIT);
|
||||||
LOG(Info, "Spawning {0} Thread Pool workers", numThreads);
|
LOG(Info, "Spawning {0} Thread Pool workers", numThreads);
|
||||||
for (int32 i = ThreadPoolImpl::Threads.Count(); i < numThreads; i++)
|
for (int32 i = ThreadPoolImpl::Threads.Count(); i < numThreads; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user