Skip to content

Commit 78b0a82

Browse files
authored
Fix: Mark deprecated functions [[deprecated]] (#129)
This additionally replaces usages of GetIsRunning with GetIsShutdownRequested, and exposes the latter in the C API.
1 parent 03e6a2c commit 78b0a82

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct RunPinnedTaskLoopTask : enki::IPinnedTask
300300
{
301301
void Execute() override
302302
{
303-
while( g_TS.GetIsRunning() )
303+
while( !g_TS.GetIsShutdownRequested() )
304304
{
305305
g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks
306306
g_TS.RunPinnedTasks();

example/WaitForNewPinnedTasks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct RunPinnedTaskLoopTask : IPinnedTask
5757
{
5858
void Execute() override
5959
{
60-
while( g_TS.GetIsRunning() )
60+
while( !g_TS.GetIsShutdownRequested() )
6161
{
6262
g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks
6363
g_TS.RunPinnedTasks();
@@ -133,7 +133,7 @@ int main(int argc, const char * argv[])
133133
g_TS.AddPinnedTask( &pretendDoNetworkIO[ ioThreadID - (uint32_t)IOThreadId::NETWORK_IO_0 ] );
134134
}
135135

136-
g_TS.WaitforTaskSet( &parallelTaskSet );
136+
g_TS.WaitforTask( &parallelTaskSet );
137137

138138
// in this example we need to wait for IO tasks to complete before running next loop
139139
g_TS.WaitforTask( &pretendDoFileIO );

example/WaitForNewPinnedTasks_c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void PinnedTaskRunPinnedTaskLoop( void* pArgs_ )
3838
assert( threadNum == threadNumDesired );
3939
printf("PinnedTaskRunPinnedTaskLoop running on thread %d (should be thread %d)\n", threadNum, threadNumDesired );
4040

41-
while( enkiGetIsRunning( pETS ) )
41+
while( !enkiGetIsShutdownRequested( pETS ) )
4242
{
4343
enkiWaitForNewPinnedTasks( pETS );
4444
enkiRunPinnedTasks( pETS );
@@ -83,7 +83,7 @@ int main(int argc, const char * argv[])
8383
enkiDeletePinnedTask( pETS, pPinnedTaskPretendIO );
8484

8585

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
8787
enkiWaitforAllAndShutdown( pETS );
8888

8989
// delete the tasks before the scheduler

src/TaskScheduler.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
#define ENKI_ASSERT(x) assert(x)
5959
#endif
6060

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+
6167
namespace enki
6268
{
6369
struct TaskSetPartition
@@ -418,15 +424,15 @@ namespace enki
418424
// DEPRECATED: use GetIsShutdownRequested() instead of GetIsRunning() in external code
419425
// while( GetIsRunning() ) {} can be used in tasks which loop, to check if enkiTS has been shutdown.
420426
// 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 ); }
422428

423429
// 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_ ); }
425431

426432
// DEPRECATED - GetProfilerCallbacks. Use TaskSchedulerConfig instead.
427433
// Returns the ProfilerCallbacks structure so that it can be modified to
428434
// 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; }
430436
// ------------- End DEPRECATED Functions -------------
431437

432438
private:

src/TaskScheduler_c.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ int enkiGetIsRunning( enkiTaskScheduler* pETS_ )
158158
return (int)pETS_->GetIsRunning();
159159
}
160160

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+
161171
void enkiInitTaskScheduler( enkiTaskScheduler* pETS_ )
162172
{
163173
pETS_->Initialize();

src/TaskScheduler_c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ ENKITS_API struct enkiTaskSchedulerConfig enkiGetTaskSchedulerConfig( enkiTaskSc
145145
// If enkiGetIsRunning() returns false should then exit. Not required for finite tasks
146146
ENKITS_API int enkiGetIsRunning( enkiTaskScheduler* pETS_ );
147147

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+
148160
// Initialize task scheduler - will create GetNumHardwareThreads()-1 threads, which is
149161
// sufficient to fill the system when including the main thread.
150162
// Initialize can be called multiple times - it will wait for completion

0 commit comments

Comments
 (0)