Skip to content

Commit

Permalink
Added GetIsRunningInt() for internal library use, and modified GetIsR…
Browse files Browse the repository at this point in the history
…unning() to call !GetIsShutdownRequested()

- fixes #128
  • Loading branch information
dougbinks committed May 29, 2024
1 parent 78b0a82 commit 9e588fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void TaskScheduler::TaskingThreadFunction( const ThreadArgs& args_ )

uint32_t spinCount = 0;
uint32_t hintPipeToCheck_io = threadNum + 1; // does not need to be clamped.
while( pTS->GetIsRunning() )
while( pTS->GetIsRunningInt() )
{
if( !pTS->TryRunTask( threadNum, hintPipeToCheck_io ) )
{
Expand Down Expand Up @@ -997,7 +997,7 @@ void TaskScheduler::WaitforTask( const ICompletable* pCompletable_, enki::Tas
// so we clamp the priorityOfLowestToRun_ to no smaller than the task we're waiting for
priorityOfLowestToRun_ = std::max( priorityOfLowestToRun_, pCompletable_->m_Priority );
uint32_t spinCount = 0;
while( !pCompletable_->GetIsComplete() && GetIsRunning() )
while( !pCompletable_->GetIsComplete() && GetIsRunningInt() )
{
++spinCount;
for( int priority = 0; priority <= priorityOfLowestToRun_; ++priority )
Expand Down Expand Up @@ -1056,7 +1056,7 @@ void TaskScheduler::WaitforAll()
uint32_t spinCount = 0;
TaskSchedulerWaitTask dummyWaitTask;
dummyWaitTask.threadNum = 0;
while( GetIsRunning() && ( bHaveTasks || otherThreadsRunning ) )
while( GetIsRunningInt() && ( bHaveTasks || otherThreadsRunning ) )
{
bHaveTasks = TryRunTask( ourThreadNum, hintPipeToCheck_io );
++spinCount;
Expand Down
4 changes: 3 additions & 1 deletion src/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ namespace enki
// DEPRECATED: use GetIsShutdownRequested() instead of GetIsRunning() in external code
// while( GetIsRunning() ) {} can be used in tasks which loop, to check if enkiTS has been shutdown.
// If GetIsRunning() returns false should then exit. Not required for finite tasks.
ENKI_DEPRECATED inline bool GetIsRunning() const { return m_bRunning.load( std::memory_order_acquire ); }
ENKI_DEPRECATED inline bool GetIsRunning() const { return !GetIsShutdownRequested(); }

// DEPRECATED - WaitforTaskSet, deprecated interface use WaitforTask.
ENKI_DEPRECATED inline void WaitforTaskSet( const ICompletable* pCompletable_ ) { WaitforTask( pCompletable_ ); }
Expand All @@ -451,6 +451,8 @@ namespace enki
void WakeThreadsForTaskCompletion();
bool WakeSuspendedThreadsWithPinnedTasks( uint32_t threadNum_ );
void InitDependencies( ICompletable* pCompletable_ );
inline bool GetIsRunningInt() const { return m_bRunning.load( std::memory_order_acquire ); }

ENKITS_API void TaskComplete( ICompletable* pTask_, bool bWakeThreads_, uint32_t threadNum_ );
ENKITS_API void AddTaskSetToPipeInt( ITaskSet* pTaskSet_, uint32_t threadNum_ );
ENKITS_API void AddPinnedTaskInt( IPinnedTask* pTask_ );
Expand Down

0 comments on commit 9e588fd

Please sign in to comment.