Skip to content

Commit

Permalink
Merge pull request #94 from pr0g/typos-grammar
Browse files Browse the repository at this point in the history
Typo and grammar fixes
  • Loading branch information
dougbinks committed Jun 10, 2023
2 parents e215376 + 6a56f71 commit d7d4e5b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
30 changes: 15 additions & 15 deletions src/TaskScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace enki
static const int32_t gc_TaskAlmostCompleteCount = 1; // GetIsComplete() will return false, but execution is done and about to complete
static const uint32_t gc_PipeSizeLog2 = 8;
static const uint32_t gc_SpinCount = 10;
static const uint32_t gc_SpinBackOffMulitplier = 100;
static const uint32_t gc_SpinBackOffMultiplier = 100;
static const uint32_t gc_MaxNumInitialPartitions = 8;
static const uint32_t gc_MaxStolenPartitions = 1 << gc_PipeSizeLog2;
static const uint32_t gc_CacheLineSize = 64;
Expand All @@ -86,7 +86,7 @@ namespace enki
#endif


// each software thread gets it's own copy of gtl_threadNum, so this is safe to use as a static variable
// each software thread gets its own copy of gtl_threadNum, so this is safe to use as a static variable
static thread_local uint32_t gtl_threadNum = enki::NO_THREAD_NUM;

namespace enki
Expand Down Expand Up @@ -292,7 +292,7 @@ void TaskScheduler::TaskingThreadFunction( const ThreadArgs& args_ )
}
else
{
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMulitplier;
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMultiplier;
SpinWait( spinBackoffCount );
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ void TaskScheduler::StartThreads()
}

// ensure we have sufficient tasks to equally fill either all threads including main
// or just the threads we've launched, this is outside the firstinit as we want to be able
// or just the threads we've launched, this is outside the first init as we want to be able
// to runtime change it
if( 1 == m_NumThreads )
{
Expand All @@ -387,7 +387,7 @@ void TaskScheduler::StartThreads()
// We need to detect this and distribute threads accordingly
if( GetNumHardwareThreads() > 64 && // only have processor groups if > 64 hardware threads
std::thread::hardware_concurrency() < GetNumHardwareThreads() && // if std::thread sees > 64 hardware threads no need to distribute
std::thread::hardware_concurrency() < m_NumThreads ) // no need to distrbute if number of threads requested lower than std::thread sees
std::thread::hardware_concurrency() < m_NumThreads ) // no need to distribute if number of threads requested lower than std::thread sees
{
uint32_t numProcessorGroups = GetActiveProcessorGroupCount();
GROUP_AFFINITY mainThreadAffinity;
Expand All @@ -399,7 +399,7 @@ void TaskScheduler::StartThreads()
uint32_t currLogicalProcess = GetActiveProcessorCount( mainProcessorGroup ); // we start iteration at end of current process group's threads

// If more threads are created than there are logical processors then we still want to distribute them evenly amongst groups
// so we iterate continously around the groups until we reach m_NumThreads
// so we iterate continuously around the groups until we reach m_NumThreads
uint32_t group = 0;
while( currLogicalProcess < m_NumThreads )
{
Expand Down Expand Up @@ -537,7 +537,7 @@ static inline uint32_t Hash32( uint32_t in_ )
// simple hash of nodes, does not check if nodePool is compressed or not.
uint32_t acc = SEED + PRIME32_5;

// add node types to map, and also ensure that fully empty nodes are well distrubuted by hashing the pointer.
// add node types to map, and also ensure that fully empty nodes are well distributed by hashing the pointer.
acc += in_;
acc = acc ^ (acc >> 15);
acc = acc * PRIME32_2;
Expand Down Expand Up @@ -626,7 +626,7 @@ bool TaskScheduler::TryRunTask( uint32_t threadNum_, uint32_t priority_, uint32_
void TaskScheduler::TaskComplete( ICompletable* pTask_, bool bWakeThreads_, uint32_t threadNum_ )
{
// It must be impossible for a thread to enter the sleeping wait prior to the load of m_WaitingForTaskCount
// in this function, so we introduce an gc_TaskAlmostCompleteCount to prevent this.
// in this function, so we introduce a gc_TaskAlmostCompleteCount to prevent this.
ENKI_ASSERT( gc_TaskAlmostCompleteCount == pTask_->m_RunningCount.load( std::memory_order_acquire ) );
bool bCallWakeThreads = bWakeThreads_ && pTask_->m_WaitingForTaskCount.load( std::memory_order_acquire );

Expand Down Expand Up @@ -692,7 +692,7 @@ void TaskScheduler::WaitForNewTasks( uint32_t threadNum_ )
return;
}

// We incrememt the number of threads waiting here in order
// We increment the number of threads waiting here in order
// to ensure that the check for tasks occurs after the increment
// to prevent a task being added after a check, then the thread waiting.
// This will occasionally result in threads being mistakenly awoken,
Expand Down Expand Up @@ -923,8 +923,8 @@ void TaskScheduler::AddPinnedTask( IPinnedTask* pTask_ )

void TaskScheduler::InitDependencies( ICompletable* pCompletable_ )
{
// go through any dependencies and set thier running count so they show as not complete
// and increment depedency count
// go through any dependencies and set their running count so they show as not complete
// and increment dependency count
if( pCompletable_->m_RunningCount.load( std::memory_order_relaxed ) )
{
// already initialized
Expand Down Expand Up @@ -1006,7 +1006,7 @@ void TaskScheduler::WaitforTask( const ICompletable* pCompletable_, enki::Tas
}
else
{
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMulitplier;
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMultiplier;
SpinWait( spinBackoffCount );
}
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ void TaskScheduler::WaitforAll()
dummyWaitTask.threadNum = ( dummyWaitTask.threadNum + 1 ) % m_NumThreads;

// We can only add a pinned task to wait on if we find an enki Task Thread which isn't this thread.
// Otherwise we have to busy wait.
// Otherwise, we have to busy wait.
if( dummyWaitTask.threadNum != ourThreadNum && dummyWaitTask.threadNum > m_Config.numExternalTaskThreads )
{
ThreadState state = m_pThreadDataStore[ dummyWaitTask.threadNum ].threadState.load( std::memory_order_acquire );
Expand All @@ -1088,7 +1088,7 @@ void TaskScheduler::WaitforAll()
}
else
{
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMulitplier;
uint32_t spinBackoffCount = spinCount * gc_SpinBackOffMultiplier;
SpinWait( spinBackoffCount );
}

Expand Down Expand Up @@ -1354,7 +1354,7 @@ namespace enki

// OS X does not have POSIX semaphores
// Mach semaphores can now only be created by the kernel
// Named sempahores work, but would require unique name construction to ensure
// Named semaphores work, but would require unique name construction to ensure
// they are isolated to this process.
// Dispatch semaphores appear to be the way other developers use OSX Semaphores, e.g. Boost
// However the API could change
Expand Down
58 changes: 29 additions & 29 deletions src/TaskScheduler.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) 2013 Doug Binks
//
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgement in the product documentation would be
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace enki
#endif
#if ( ENKITS_TASK_PRIORITIES_NUM > 4 )
TASK_PRIORITY_MED_LO,
#endif
#endif
#if ( ENKITS_TASK_PRIORITIES_NUM > 1 )
TASK_PRIORITY_LOW,
#endif
Expand Down Expand Up @@ -156,16 +156,16 @@ namespace enki
// range_ where range.start >= 0; range.start < range.end; and range.end < m_SetSize;
// The range values should be mapped so that linearly processing them in order is cache friendly
// i.e. neighbouring values should be close together.
// threadnum should not be used for changing processing of data, it's intended purpose
// threadnum_ should not be used for changing processing of data, its intended purpose
// is to allow per-thread data buckets for output.
virtual void ExecuteRange( TaskSetPartition range_, uint32_t threadnum_ ) = 0;

// Set Size - usually the number of data items to be processed, see ExecuteRange. Defaults to 1
uint32_t m_SetSize = 1;

// Min Range - Minimum size of of TaskSetPartition range when splitting a task set into partitions.
// Min Range - Minimum size of TaskSetPartition range when splitting a task set into partitions.
// Designed for reducing scheduling overhead by preventing set being
// divided up too small. Ranges passed to ExecuteRange will *not* be a mulitple of this,
// divided up too small. Ranges passed to ExecuteRange will *not* be a multiple of this,
// only attempts to deliver range sizes larger than this most of the time.
// This should be set to a value which results in computation effort of at least 10k
// clock cycles to minimize task scheduler overhead.
Expand All @@ -187,8 +187,8 @@ namespace enki
IPinnedTask() = default;
IPinnedTask( uint32_t threadNum_ ) : threadNum(threadNum_) {} // default is to run a task on main thread

// IPinnedTask needs to be non abstract for intrusive list functionality.
// Should never be called as should be overridden.
// IPinnedTask needs to be non-abstract for intrusive list functionality.
// Should never be called as is, should be overridden.
virtual void Execute() { ENKI_ASSERT(false); }

uint32_t threadNum = 0; // thread to run this pinned task on
Expand All @@ -197,7 +197,7 @@ namespace enki
void OnDependenciesComplete( TaskScheduler* pTaskScheduler_, uint32_t threadNum_ ) override final;
};

// TaskSet - a utility task set for creating tasks based on std::func.
// TaskSet - a utility task set for creating tasks based on std::function.
typedef std::function<void (TaskSetPartition range, uint32_t threadnum )> TaskSetFunction;
class TaskSet : public ITaskSet
{
Expand Down Expand Up @@ -226,9 +226,9 @@ namespace enki
class Dependency
{
public:
Dependency() = default;
Dependency() = default;
Dependency( const Dependency& ) = delete;
ENKITS_API Dependency( Dependency&& ) noexcept;
ENKITS_API Dependency( Dependency&& ) noexcept;
ENKITS_API Dependency( const ICompletable* pDependencyTask_, ICompletable* pTaskToRunOnCompletion_ );
ENKITS_API ~Dependency();

Expand Down Expand Up @@ -280,7 +280,7 @@ namespace enki
// See TaskScheduler::RegisterExternalTaskThread() for usage.
// Defaults to 0. The thread used to initialize the TaskScheduler can also use the TaskScheduler API.
// Thus there are (numTaskThreadsToCreate + numExternalTaskThreads + 1) able to use the API, with this
// defaulting to the number of harware threads available to the system.
// defaulting to the number of hardware threads available to the system.
uint32_t numExternalTaskThreads = 0;

ProfilerCallbacks profilerCallbacks = {};
Expand Down Expand Up @@ -317,13 +317,13 @@ namespace enki
// while( !GetIsShutdownRequested() ) {} can be used in tasks which loop, to check if enkiTS has been requested to shutdown.
// If GetIsShutdownRequested() returns true should then exit. Not required for finite tasks
// Safe to use with WaitforAllAndShutdown() and ShutdownNow() where this will be set
// Not safe to use with WaitforAll().
// Not safe to use with WaitforAll().
inline bool GetIsShutdownRequested() const { return m_bShutdownRequested.load( std::memory_order_acquire ); }

// while( !GetIsWaitforAllCalled() ) {} can be used in tasks which loop, to check if WaitforAll() has been called.
// If GetIsWaitforAllCalled() returns false should then exit. Not required for finite tasks
// This is intended to be used with code which calls WaitforAll() with flag WAITFORALLFLAGS_INC_WAIT_NEW_PINNED_TASKS set.
// This is also set when the the task manager is shutting down, so no need to have an additional check for GetIsShutdownRequested()
// This is also set when the task manager is shutting down, so no need to have an additional check for GetIsShutdownRequested()
inline bool GetIsWaitforAllCalled() const { return m_bWaitforAllCalled.load( std::memory_order_acquire ); }

// Adds the TaskSet to pipe and returns if the pipe is not full.
Expand All @@ -336,22 +336,22 @@ namespace enki
ENKITS_API void AddPinnedTask( IPinnedTask* pTask_ );

// This function will run any IPinnedTask* for current thread, but not run other
// Main thread should call this or use a wait to ensure it's tasks are run.
// Main thread should call this or use a wait to ensure its tasks are run.
ENKITS_API void RunPinnedTasks();

// Runs the TaskSets in pipe until true == pTaskSet->GetIsComplete();
// should only be called from thread which created the taskscheduler , or within a task
// if called with 0 it will try to run tasks, and return if none available.
// Should only be called from thread which created the task scheduler, or within a task.
// If called with 0 it will try to run tasks, and return if none are available.
// To run only a subset of tasks, set priorityOfLowestToRun_ to a high priority.
// Default is lowest priority available.
// Only wait for child tasks of the current task otherwise a deadlock could occur.
// WaitforTask will exit if ShutdownNow() is called even if pCompletable_ is not complete
// WaitforTask will exit if ShutdownNow() is called even if pCompletable_ is not complete.
ENKITS_API void WaitforTask( const ICompletable* pCompletable_, enki::TaskPriority priorityOfLowestToRun_ = TaskPriority(TASK_PRIORITY_NUM - 1) );

// Waits for all task sets to complete - not guaranteed to work unless we know we
// are in a situation where tasks aren't being continuously added.
// If you are running tasks which loop, make sure to check GetIsWaitforAllCalled() and exit
// WaitfoAll will exit if ShutdownNow() is called even if there are still tasks to run or currently running
// WaitforAll will exit if ShutdownNow() is called even if there are still tasks to run or currently running
ENKITS_API void WaitforAll();

// Waits for all task sets to complete and shutdown threads - not guaranteed to work unless we know we
Expand All @@ -367,11 +367,11 @@ namespace enki
// to be in an undefined state in which should not be re-launched.
ENKITS_API void ShutdownNow();

// Waits for the current thread to receive a PinnedTask
// Will not run any tasks - use with RunPinnedTasks()
// Waits for the current thread to receive a PinnedTask.
// Will not run any tasks - use with RunPinnedTasks().
// Can be used with both ExternalTaskThreads or with an enkiTS tasking thread to create
// a thread which only runs pinned tasks. If enkiTS threads are used can create
// extra enkiTS task threads to handle non blocking computation via normal tasks.
// extra enkiTS task threads to handle non-blocking computation via normal tasks.
ENKITS_API void WaitForNewPinnedTasks();

// Returns the number of threads created for running tasks + number of external threads
Expand All @@ -380,7 +380,7 @@ namespace enki
// It is guaranteed that GetThreadNum() < GetNumTaskThreads()
ENKITS_API uint32_t GetNumTaskThreads() const;

// Returns the current task threadNum
// Returns the current task threadNum.
// Will return 0 for thread which initialized the task scheduler,
// and NO_THREAD_NUM for all other non-enkiTS threads which have not been registered ( see RegisterExternalTaskThread() ),
// and < GetNumTaskThreads() for all registered and internal enkiTS threads.
Expand All @@ -390,14 +390,14 @@ namespace enki
// Call on a thread to register the thread to use the TaskScheduling API.
// This is implicitly done for the thread which initializes the TaskScheduler
// Intended for developers who have threads who need to call the TaskScheduler API
// Returns true if successfull, false if not.
// Returns true if successful, false if not.
// Can only have numExternalTaskThreads registered at any one time, which must be set
// at initialization time.
ENKITS_API bool RegisterExternalTaskThread();

// As RegisterExternalTaskThread() but explicitly requests a given thread number.
// threadNumToRegister_ must be >= GetNumFirstExternalTaskThread()
// and < ( GetNumFirstExternalTaskThread() + numExternalTaskThreads )
// and < ( GetNumFirstExternalTaskThread() + numExternalTaskThreads ).
ENKITS_API bool RegisterExternalTaskThread( uint32_t threadNumToRegister_ );

// Call on a thread on which RegisterExternalTaskThread has been called to deregister that thread.
Expand All @@ -418,13 +418,13 @@ namespace enki
// ------------- Start DEPRECATED Functions -------------
// 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
// If GetIsRunning() returns false should then exit. Not required for finite tasks.
inline bool GetIsRunning() const { return m_bRunning.load( std::memory_order_acquire ); }

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

// DEPRECATED - GetProfilerCallbacks. Use TaskSchedulerConfig instead
// 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; }
Expand Down
Loading

0 comments on commit d7d4e5b

Please sign in to comment.