RADLib
RADical C++ application framework
RADCore::RADThread Class Reference

Thread object with an owned RADCore EventLoop. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADThread:
+ Collaboration diagram for RADCore::RADThread:

Public Member Functions

 RADThread ()
 Creates a stopped thread object. More...
 
virtual ~RADThread ()
 Quits and joins the thread when needed. More...
 
void start (LoopStrategy strategy=LoopStrategy::RADEVENT_LOCK)
 Starts the thread and its event loop. More...
 
void quit ()
 Requests the event loop to quit. More...
 
void wait ()
 Blocks until the thread exits. More...
 
EventLoopeventLoop ()
 Returns the thread's event loop after start(). More...
 
bool isRunning () const
 Returns true while the thread is running. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void() > started
 Raised when the thread starts running. More...
 
RADCore::Event< void() > finished
 Raised when the thread exits. More...
 

Protected Member Functions

virtual void run ()
 Override to run custom work before/around the event loop. More...
 

Detailed Description

Thread object with an owned RADCore EventLoop.

Constructor & Destructor Documentation

◆ RADThread()

RADCore::RADThread::RADThread ( )

Creates a stopped thread object.

◆ ~RADThread()

virtual RADCore::RADThread::~RADThread ( )
virtual

Quits and joins the thread when needed.

Member Function Documentation

◆ eventLoop()

EventLoop& RADCore::RADThread::eventLoop ( )

Returns the thread's event loop after start().

◆ isRunning()

bool RADCore::RADThread::isRunning ( ) const

Returns true while the thread is running.

◆ quit()

void RADCore::RADThread::quit ( )

Requests the event loop to quit.

◆ run()

virtual void RADCore::RADThread::run ( )
protectedvirtual

Override to run custom work before/around the event loop.

◆ start()

void RADCore::RADThread::start ( LoopStrategy  strategy = LoopStrategy::RADEVENT_LOCK)

Starts the thread and its event loop.

◆ wait()

void RADCore::RADThread::wait ( )

Blocks until the thread exits.

Member Data Documentation

◆ finished

RADCore::Event<void () > RADCore::RADThread::finished

Raised when the thread exits.

◆ started

RADCore::Event<void () > RADCore::RADThread::started

Raised when the thread starts running.


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