File tree Expand file tree Collapse file tree 6 files changed +36
-8
lines changed Expand file tree Collapse file tree 6 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -300,7 +300,7 @@ struct RunPinnedTaskLoopTask : enki::IPinnedTask
300
300
{
301
301
void Execute() override
302
302
{
303
- while( g_TS.GetIsRunning () )
303
+ while( ! g_TS.GetIsShutdownRequested () )
304
304
{
305
305
g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks
306
306
g_TS.RunPinnedTasks();
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ struct RunPinnedTaskLoopTask : IPinnedTask
57
57
{
58
58
void Execute () override
59
59
{
60
- while ( g_TS.GetIsRunning () )
60
+ while ( ! g_TS.GetIsShutdownRequested () )
61
61
{
62
62
g_TS.WaitForNewPinnedTasks (); // this thread will 'sleep' until there are new pinned tasks
63
63
g_TS.RunPinnedTasks ();
@@ -133,7 +133,7 @@ int main(int argc, const char * argv[])
133
133
g_TS.AddPinnedTask ( &pretendDoNetworkIO[ ioThreadID - (uint32_t )IOThreadId::NETWORK_IO_0 ] );
134
134
}
135
135
136
- g_TS.WaitforTaskSet ( ¶llelTaskSet );
136
+ g_TS.WaitforTask ( ¶llelTaskSet );
137
137
138
138
// in this example we need to wait for IO tasks to complete before running next loop
139
139
g_TS.WaitforTask ( &pretendDoFileIO );
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ void PinnedTaskRunPinnedTaskLoop( void* pArgs_ )
38
38
assert ( threadNum == threadNumDesired );
39
39
printf ("PinnedTaskRunPinnedTaskLoop running on thread %d (should be thread %d)\n" , threadNum , threadNumDesired );
40
40
41
- while ( enkiGetIsRunning ( pETS ) )
41
+ while ( ! enkiGetIsShutdownRequested ( pETS ) )
42
42
{
43
43
enkiWaitForNewPinnedTasks ( pETS );
44
44
enkiRunPinnedTasks ( pETS );
@@ -83,7 +83,7 @@ int main(int argc, const char * argv[])
83
83
enkiDeletePinnedTask ( pETS , pPinnedTaskPretendIO );
84
84
85
85
86
- // Shutdown enkiTS, which will cause pPinnedTaskRunPinnedTaskLoop to exit as enkiGetIsRunning will return false
86
+ // Shutdown enkiTS, which will cause pPinnedTaskRunPinnedTaskLoop to exit as enkiGetIsShutdownRequested will return true
87
87
enkiWaitforAllAndShutdown ( pETS );
88
88
89
89
// delete the tasks before the scheduler
Original file line number Diff line number Diff line change 58
58
#define ENKI_ASSERT (x ) assert(x)
59
59
#endif
60
60
61
+ #if (!defined(_MSVC_LANG) && __cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
62
+ #define ENKI_DEPRECATED [[deprecated]]
63
+ #else
64
+ #define ENKI_DEPRECATED
65
+ #endif
66
+
61
67
namespace enki
62
68
{
63
69
struct TaskSetPartition
@@ -418,15 +424,15 @@ namespace enki
418
424
// DEPRECATED: use GetIsShutdownRequested() instead of GetIsRunning() in external code
419
425
// while( GetIsRunning() ) {} can be used in tasks which loop, to check if enkiTS has been shutdown.
420
426
// If GetIsRunning() returns false should then exit. Not required for finite tasks.
421
- inline bool GetIsRunning () const { return m_bRunning.load ( std::memory_order_acquire ); }
427
+ ENKI_DEPRECATED inline bool GetIsRunning () const { return m_bRunning.load ( std::memory_order_acquire ); }
422
428
423
429
// DEPRECATED - WaitforTaskSet, deprecated interface use WaitforTask.
424
- inline void WaitforTaskSet ( const ICompletable* pCompletable_ ) { WaitforTask ( pCompletable_ ); }
430
+ ENKI_DEPRECATED inline void WaitforTaskSet ( const ICompletable* pCompletable_ ) { WaitforTask ( pCompletable_ ); }
425
431
426
432
// DEPRECATED - GetProfilerCallbacks. Use TaskSchedulerConfig instead.
427
433
// Returns the ProfilerCallbacks structure so that it can be modified to
428
434
// set the callbacks. Should be set prior to initialization.
429
- inline ProfilerCallbacks* GetProfilerCallbacks () { return &m_Config.profilerCallbacks ; }
435
+ ENKI_DEPRECATED inline ProfilerCallbacks* GetProfilerCallbacks () { return &m_Config.profilerCallbacks ; }
430
436
// ------------- End DEPRECATED Functions -------------
431
437
432
438
private:
Original file line number Diff line number Diff line change @@ -158,6 +158,16 @@ int enkiGetIsRunning( enkiTaskScheduler* pETS_ )
158
158
return (int )pETS_->GetIsRunning ();
159
159
}
160
160
161
+ int enkiGetIsShutdownRequested (enkiTaskScheduler* pETS_)
162
+ {
163
+ return (int )pETS_->GetIsShutdownRequested ();
164
+ }
165
+
166
+ int enkiGetIsWaitforAllCalled ( enkiTaskScheduler* pETS_ )
167
+ {
168
+ return (int )pETS_->GetIsWaitforAllCalled ();
169
+ }
170
+
161
171
void enkiInitTaskScheduler ( enkiTaskScheduler* pETS_ )
162
172
{
163
173
pETS_->Initialize ();
Original file line number Diff line number Diff line change @@ -145,6 +145,18 @@ ENKITS_API struct enkiTaskSchedulerConfig enkiGetTaskSchedulerConfig( enkiTaskSc
145
145
// If enkiGetIsRunning() returns false should then exit. Not required for finite tasks
146
146
ENKITS_API int enkiGetIsRunning ( enkiTaskScheduler * pETS_ );
147
147
148
+ // while( !enkiGetIsShutdownRequested() ) {} can be used in tasks which loop, to check if enkiTS has been requested to shutdown.
149
+ // If enkiGetIsShutdownRequested() returns true should then exit. Not required for finite tasks
150
+ // Safe to use with enkiWaitforAllAndShutdown() where this will be set
151
+ // Not safe to use with enkiWaitforAll(), use enkiGetIsWaitforAllCalled() instead.
152
+ ENKITS_API int enkiGetIsShutdownRequested ( enkiTaskScheduler * pETS_ );
153
+
154
+ // while( !enkiGetIsWaitforAllCalled() ) {} can be used in tasks which loop, to check if enkiWaitforAll() has been called.
155
+ // If enkiGetIsWaitforAllCalled() returns false should then exit. Not required for finite tasks
156
+ // This is intended to be used with code which calls enkiWaitforAll().
157
+ // This is also set when the task manager is shutting down, so no need to have an additional check for enkiGetIsShutdownRequested()
158
+ ENKITS_API int enkiGetIsWaitforAllCalled ( enkiTaskScheduler * pETS_ );
159
+
148
160
// Initialize task scheduler - will create GetNumHardwareThreads()-1 threads, which is
149
161
// sufficient to fill the system when including the main thread.
150
162
// Initialize can be called multiple times - it will wait for completion
You can’t perform that action at this time.
0 commit comments