![]() |
NDEVR
API Documentation
|
A thread that executes a user-provided callback function concurrently. More...
Public Member Functions | |
| BasicThread (const StringView &name, const bool &is_loop, const std::function< void()> &callback) | |
| Constructs a BasicThread with a name, loop flag, and callback function. | |
| void | run () override |
| Executes the stored callback function. | |
| Public Member Functions inherited from Thread | |
| Thread () | |
| Constructs a Thread with a default name. | |
| Thread (const StringView &name) | |
| Constructs a Thread with the specified name. | |
| virtual | ~Thread () |
| Destroys the Thread and cleans up resources. | |
| void | detach () |
| Detaches the thread, allowing it to run independently. | |
| void | forceStop () |
| Forces the running flag to false without waiting for the thread to finish. | |
| bool | isPrimaryThread () const |
| Checks whether this thread is the primary thread. | |
| bool | isRunning () const |
| Checks whether the thread is currently running. | |
| void | join () |
| Blocks the calling thread until this thread finishes execution. | |
| virtual void | requestStopThread () |
| Requests the thread to stop without blocking. | |
| void | setIsPrimaryThread (bool is_primary_thread) |
| Sets whether this thread should be treated as the primary thread. | |
| void | setThreadName (const StringView &name) |
| Sets the name of this thread. | |
| virtual bool | shouldExitThread () const |
| Checks whether the thread has been requested to exit. | |
| void | start () |
| Starts the thread execution. | |
| virtual void | stopThread () |
| Stops the thread and waits for it to finish. | |
| const String & | threadName () const |
| Gets the name assigned to this thread. | |
Static Public Member Functions | |
| static void | splitThread (const std::function< void()> &callback_a, const std::function< void()> &callback_b) |
| Splits execution into two concurrent threads and waits for both to complete. | |
| static void | splitThread (const StringView &split_name, const std::function< void()> &callback_a, const std::function< void()> &callback_b) |
| Splits execution into two named concurrent threads and waits for both to complete. | |
| template<uint04 t_max_number_of_threads> | |
| static std::enable_if< t_max_number_of_threads<=32, void >::type | ThreadLoop (uint04 number_of_loops, const std::function< void(uint04 index)> &callback) |
| Distributes a loop across multiple threads up to t_max_number_of_threads. | |
| template<uint04 t_max_number_of_threads> | |
| static void | ThreadLoop (uint04 number_of_loops, volatile uint04 &loops_performed, const std::function< void(uint04 index)> &callback) |
| Executes a loop distributed across a fixed number of threads using recursive splitting. | |
| Static Public Member Functions inherited from Thread | |
| static Thread & | CurrentThread () |
| Gets a reference to the Thread object for the calling thread. | |
| static String | CurrentThreadName () |
| Gets the name of the current thread. | |
| static void | ServiceVirtualThreads () |
| Services any virtual threads that require periodic execution. | |
| static void | SetCurrentThreadName (const StringView &name) |
| Sets the name of the current thread. | |
| static void | StopAllThreads () |
| Stops all tracked threads. | |
Protected Attributes | |
| std::function< void()> | m_function |
| The callback function executed by this thread. | |
| Protected Attributes inherited from Thread | |
| volatile bool | m_is_running = false |
| Whether the thread is currently running. | |
| volatile bool | m_is_single_run = true |
| Whether the thread should execute only once before stopping. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Thread | |
| const std::thread & | self () |
| Gets a const reference to the underlying std::thread. | |
A thread that executes a user-provided callback function concurrently.
Definition at line 46 of file BasicThread.h.
|
explicit |
Constructs a BasicThread with a name, loop flag, and callback function.
| [in] | name | The name identifier for this thread. |
| [in] | is_loop | Whether the thread should loop continuously or run once. |
| [in] | callback | The function to execute on this thread. |
|
inlineoverridevirtual |
Executes the stored callback function.
Called when the thread is started.
Reimplemented from Thread.
Definition at line 60 of file BasicThread.h.
References m_function.
|
static |
Splits execution into two concurrent threads and waits for both to complete.
| [in] | callback_a | The function to execute on the first thread. |
| [in] | callback_b | The function to execute on the second thread. |
Referenced by ThreadLoop().
|
static |
Splits execution into two named concurrent threads and waits for both to complete.
| [in] | split_name | The name prefix for the spawned threads. |
| [in] | callback_a | The function to execute on the first thread. |
| [in] | callback_b | The function to execute on the second thread. |
|
inlinestatic |
Distributes a loop across multiple threads up to t_max_number_of_threads.
Selects the optimal thread count based on the number of loops and available OS threads, then delegates to the fixed-thread-count overload.
| [in] | number_of_loops | The total number of loop iterations to execute. |
| [in] | callback | The function to call for each loop index. |
Definition at line 87 of file BasicThread.h.
References getMin(), and ThreadLoop().
Referenced by ThreadLoop(), and ThreadLoop().
|
inlinestatic |
Executes a loop distributed across a fixed number of threads using recursive splitting.
When t_max_number_of_threads is 1, runs iterations sequentially with atomic index incrementing. Otherwise, recursively splits the work across threads.
| [in] | number_of_loops | The total number of loop iterations to execute. |
| [in] | loops_performed | A shared volatile counter tracking completed iterations. |
| [in] | callback | The function to call for each loop index. |
Definition at line 123 of file BasicThread.h.
References ConcurrentOperation::increment(), splitThread(), and ThreadLoop().