Open Lighting Architecture  Latest Git
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ola::thread::Thread Class Referenceabstract

Detailed Description

A thread object that can be subclassed.

Inheritance diagram for ola::thread::Thread:
Inheritance graph
[legend]

Classes

struct  Options
 Thread options. More...
 

Public Member Functions

 Thread (const Options &options=Options())
 Create a new thread with the specified thread options. More...
 
virtual ~Thread ()
 Destructor.
 
virtual bool Start ()
 Start the thread and wait for the thread to be running. More...
 
virtual bool FastStart ()
 Start the thread and return immediately. More...
 
virtual bool Join (void *ptr=NULL)
 Join this thread. More...
 
bool IsRunning ()
 Check if the thread is running. More...
 
ThreadId Id () const
 Return the thread id. More...
 
std::string Name () const
 Return the thread name. More...
 

Static Public Member Functions

static ThreadId Self ()
 Returns the current thread's id. More...
 

Protected Member Functions

virtual void * Run ()=0
 The entry point for the new thread. More...
 

Constructor & Destructor Documentation

◆ Thread()

ola::thread::Thread::Thread ( const Options options = Options())
explicit

Create a new thread with the specified thread options.

Parameters
optionsthe thread's options

Member Function Documentation

◆ FastStart()

bool ola::thread::Thread::FastStart ( )
virtual

Start the thread and return immediately.

Returns
true if the thread started, false otherwise.

Don't use this unless you know what you're doing, since it introduces a race condition with Join().

◆ Id()

ThreadId ola::thread::Thread::Id ( ) const
inline

Return the thread id.

Returns
the thread id.

◆ IsRunning()

bool ola::thread::Thread::IsRunning ( )

Check if the thread is running.

Returns
true if the thread was running at some point in the past.

This is best-effort only, since the thread may stop after IsRunning() returns.

◆ Join()

bool ola::thread::Thread::Join ( void *  ptr = NULL)
virtual

Join this thread.

Parameters
[out]ptrThe value returned from the thread.
Returns
false if the thread wasn't running or didn't stop, true otherwise.

Reimplemented in ola::FilePreferenceSaverThread, and ola::plugin::usbpro::WidgetDetectorThread.

◆ Name()

std::string ola::thread::Thread::Name ( ) const
inline

Return the thread name.

Returns
the thread name.

This may differ from the name assigned with pthread_setname, since the latter has a limit of 16 characters.

◆ Run()

virtual void* ola::thread::Thread::Run ( )
protectedpure virtual

◆ Self()

static ThreadId ola::thread::Thread::Self ( )
inlinestatic

Returns the current thread's id.

Returns
the current thread's id.

◆ Start()

bool ola::thread::Thread::Start ( )
virtual

Start the thread and wait for the thread to be running.

Returns
true if the thread started, false otherwise.

This will block until the thread is running. Use FastStart() if you don't want to block.

Reimplemented in ola::plugin::usbdmx::ThreadedUsbReceiver, ola::plugin::usbdmx::ThreadedUsbSender, and OlaThread.


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