Skip to content

Commit

Permalink
Fix: Mark deprecated functions [[deprecated]] (#129)
Browse files Browse the repository at this point in the history
This additionally replaces usages of GetIsRunning with GetIsShutdownRequested, and exposes the latter in the C API.
  • Loading branch information
spnda committed May 29, 2024
1 parent 03e6a2c commit 78b0a82
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ struct RunPinnedTaskLoopTask : enki::IPinnedTask
{
void Execute() override
{
while( g_TS.GetIsRunning() )
while( !g_TS.GetIsShutdownRequested() )
{
g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks
g_TS.RunPinnedTasks();
Expand Down
4 changes: 2 additions & 2 deletions example/WaitForNewPinnedTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct RunPinnedTaskLoopTask : IPinnedTask
{
void Execute() override
{
while( g_TS.GetIsRunning() )
while( !g_TS.GetIsShutdownRequested() )
{
g_TS.WaitForNewPinnedTasks(); // this thread will 'sleep' until there are new pinned tasks
g_TS.RunPinnedTasks();
Expand Down Expand Up @@ -133,7 +133,7 @@ int main(int argc, const char * argv[])
g_TS.AddPinnedTask( &pretendDoNetworkIO[ ioThreadID - (uint32_t)IOThreadId::NETWORK_IO_0 ] );
}

g_TS.WaitforTaskSet( &parallelTaskSet );
g_TS.WaitforTask( &parallelTaskSet );

// in this example we need to wait for IO tasks to complete before running next loop
g_TS.WaitforTask( &pretendDoFileIO );
Expand Down
4 changes: 2 additions & 2 deletions example/WaitForNewPinnedTasks_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void PinnedTaskRunPinnedTaskLoop( void* pArgs_ )
assert( threadNum == threadNumDesired );
printf("PinnedTaskRunPinnedTaskLoop running on thread %d (should be thread %d)\n", threadNum, threadNumDesired );

while( enkiGetIsRunning( pETS ) )
while( !enkiGetIsShutdownRequested( pETS ) )
{
enkiWaitForNewPinnedTasks( pETS );
enkiRunPinnedTasks( pETS );
Expand Down Expand Up @@ -83,7 +83,7 @@ int main(int argc, const char * argv[])
enkiDeletePinnedTask( pETS, pPinnedTaskPretendIO );


// Shutdown enkiTS, which will cause pPinnedTaskRunPinnedTaskLoop to exit as enkiGetIsRunning will return false
// Shutdown enkiTS, which will cause pPinnedTaskRunPinnedTaskLoop to exit as enkiGetIsShutdownRequested will return true
enkiWaitforAllAndShutdown( pETS );

// delete the tasks before the scheduler
Expand Down
12 changes: 9 additions & 3 deletions src/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
#define ENKI_ASSERT(x) assert(x)
#endif

#if (!defined(_MSVC_LANG) && __cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
#define ENKI_DEPRECATED [[deprecated]]
#else
#define ENKI_DEPRECATED
#endif

namespace enki
{
struct TaskSetPartition
Expand Down Expand Up @@ -418,15 +424,15 @@ 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.
inline bool GetIsRunning() const { return m_bRunning.load( std::memory_order_acquire ); }
ENKI_DEPRECATED inline bool GetIsRunning() const { return m_bRunning.load( std::memory_order_acquire ); }

// DEPRECATED - WaitforTaskSet, deprecated interface use WaitforTask.
inline void WaitforTaskSet( const ICompletable* pCompletable_ ) { WaitforTask( pCompletable_ ); }
ENKI_DEPRECATED inline void WaitforTaskSet( const ICompletable* pCompletable_ ) { WaitforTask( pCompletable_ ); }

// DEPRECATED - GetProfilerCallbacks. Use TaskSchedulerConfig instead.
// Returns the ProfilerCallbacks structure so that it can be modified to
// set the callbacks. Should be set prior to initialization.
inline ProfilerCallbacks* GetProfilerCallbacks() { return &m_Config.profilerCallbacks; }
ENKI_DEPRECATED inline ProfilerCallbacks* GetProfilerCallbacks() { return &m_Config.profilerCallbacks; }
// ------------- End DEPRECATED Functions -------------

private:
Expand Down
10 changes: 10 additions & 0 deletions src/TaskScheduler_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ int enkiGetIsRunning( enkiTaskScheduler* pETS_ )
return (int)pETS_->GetIsRunning();
}

int enkiGetIsShutdownRequested(enkiTaskScheduler* pETS_)
{
return (int)pETS_->GetIsShutdownRequested();
}

int enkiGetIsWaitforAllCalled( enkiTaskScheduler* pETS_ )
{
return (int)pETS_->GetIsWaitforAllCalled();
}

void enkiInitTaskScheduler( enkiTaskScheduler* pETS_ )
{
pETS_->Initialize();
Expand Down
12 changes: 12 additions & 0 deletions src/TaskScheduler_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ ENKITS_API struct enkiTaskSchedulerConfig enkiGetTaskSchedulerConfig( enkiTaskSc
// If enkiGetIsRunning() returns false should then exit. Not required for finite tasks
ENKITS_API int enkiGetIsRunning( enkiTaskScheduler* pETS_ );

// while( !enkiGetIsShutdownRequested() ) {} can be used in tasks which loop, to check if enkiTS has been requested to shutdown.
// If enkiGetIsShutdownRequested() returns true should then exit. Not required for finite tasks
// Safe to use with enkiWaitforAllAndShutdown() where this will be set
// Not safe to use with enkiWaitforAll(), use enkiGetIsWaitforAllCalled() instead.
ENKITS_API int enkiGetIsShutdownRequested( enkiTaskScheduler* pETS_ );

// while( !enkiGetIsWaitforAllCalled() ) {} can be used in tasks which loop, to check if enkiWaitforAll() has been called.
// If enkiGetIsWaitforAllCalled() returns false should then exit. Not required for finite tasks
// This is intended to be used with code which calls enkiWaitforAll().
// This is also set when the task manager is shutting down, so no need to have an additional check for enkiGetIsShutdownRequested()
ENKITS_API int enkiGetIsWaitforAllCalled( enkiTaskScheduler* pETS_ );

// Initialize task scheduler - will create GetNumHardwareThreads()-1 threads, which is
// sufficient to fill the system when including the main thread.
// Initialize can be called multiple times - it will wait for completion
Expand Down

0 comments on commit 78b0a82

Please sign in to comment.