Skip to content

Commit

Permalink
Added toggles to modify behaviour inside the jobsystem, for advanced …
Browse files Browse the repository at this point in the history
…uses
  • Loading branch information
markoostveen committed Dec 16, 2023
1 parent d5528aa commit b172dad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions JobSystem/Src/JobSystem/JobSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,31 @@ namespace JbSystem
_enablePeriodicOptimization.store(option, std::memory_order_relaxed);
}

void JobSystem::TogglePreventAcceptingNewSchedules(bool option)
{
_preventIncomingScheduleCalls.store(option, std::memory_order_relaxed);
}

void JobSystem::IncreaseActiveWorkerCount()
{
uint32_t newActiveWorkerCount = _activeWorkerCount.load(std::memory_order_acquire) + 1;
if (newActiveWorkerCount >= _workerCount)
return;

while(_activeWorkerCount.exchange(newActiveWorkerCount, std::memory_order_release) != newActiveWorkerCount);

StartAllWorkers(true);
}

void JobSystem::DecreaseActiveWorkerCount()
{
uint32_t newActiveWorkerCount = _activeWorkerCount.load(std::memory_order_acquire) + 1;
if (newActiveWorkerCount <= _minimumActiveWorkers)
return;

while (_activeWorkerCount.exchange(newActiveWorkerCount, std::memory_order_release) != newActiveWorkerCount);
}

bool JobSystem::IsUsingBuiltInOptimization() const
{
return _enablePeriodicOptimization.load(std::memory_order_acquire);
Expand Down
3 changes: 3 additions & 0 deletions JobSystem/Src/JobSystem/JobSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ namespace JbSystem
/// <param name="option"></param>
void ShowStats(bool option = true);
void TogglePeriodicWorkerOptimization(bool option = true);
void TogglePreventAcceptingNewSchedules(bool option = true);
void IncreaseActiveWorkerCount();
void DecreaseActiveWorkerCount();

bool IsUsingBuiltInOptimization() const;
bool IsAcceptingNewJobs() const;
Expand Down
2 changes: 1 addition & 1 deletion JobSystem/Src/JobSystem/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace JbSystem
void JobSystemWorker::SetJobStealingToggle(bool enabled)
{
#ifdef JobSystem_WorkerStealToggle_Enabled
_jobStealingEnabled.store(enabled, std::memory_order_acquire);
_jobStealingEnabled.store(enabled, std::memory_order_release);
#endif
}

Expand Down

0 comments on commit b172dad

Please sign in to comment.