NDEVR
API Documentation
ThreadQueue

Executes a queue of callback functions sequentially on a dedicated thread. More...

Inheritance diagram for ThreadQueue:
[legend]
Collaboration diagram for ThreadQueue:
[legend]

Public Member Functions

 ThreadQueue (const String &name)
 Constructs a ThreadQueue with the given name.
void add (const std::function< void()> &callback)
 Adds a callback function to the queue and starts the thread if not already running.
void run () override
 Executes all queued functions sequentially in the thread.
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 StringthreadName () const
 Gets the name assigned to this thread.

Public Attributes

Resource< bool > sv_is_running
 Indicates whether the thread queue is currently running.

Protected Attributes

std::function< void(const char *const)> m_error_callback
 Optional callback invoked when an error occurs during execution.
Buffer< std::function< void()> > m_functions
 The queue of functions awaiting execution.
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

Static Public Member Functions inherited from Thread
static ThreadCurrentThread ()
 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 Member Functions inherited from Thread
const std::thread & self ()
 Gets a const reference to the underlying std::thread.

Detailed Description

Executes a queue of callback functions sequentially on a dedicated thread.


See also
Thread, BasicThread

Definition at line 44 of file ThreadQueue.h.

Constructor & Destructor Documentation

◆ ThreadQueue()

ThreadQueue::ThreadQueue ( const String & name)
explicit

Constructs a ThreadQueue with the given name.

Parameters
[in]nameThe name to assign to this thread queue.

Member Function Documentation

◆ add()

void ThreadQueue::add ( const std::function< void()> & callback)
inline

Adds a callback function to the queue and starts the thread if not already running.

Parameters
[in]callbackThe function to enqueue for execution.

Definition at line 64 of file ThreadQueue.h.

References m_functions, and Thread::start().


The documentation for this class was generated from the following file: