Open Lighting Architecture: ola::thread::Thread Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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:

## Classes
struct | Options
| Thread options. More...

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

## Static Public Member Functions
static ThreadId | Self ()
| Returns the current thread's id.

## Protected Member Functions
virtual void * | Run ()=0
| The entry point for the new thread.

## Constructor & Destructor Documentation

## ◆ Thread()

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

Create a new thread with the specified thread options.

Parameters

  options | the 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] | ptr | The 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

The entry point for the new thread.

Returns
  A value returned to Join().

Sub classes must implement this.

Implemented in ola::FilePreferenceSaverThread, ola::http::HTTPServer, ola::HTTPServer, ola::plugin::ftdidmx::FtdiDmxThread, ola::plugin::gpio::GPIODriver, ola::plugin::karate::KarateThread, ola::plugin::opendmx::OpenDmxThread, ola::plugin::spi::HardwareBackend, ola::plugin::spi::SoftwareBackend, ola::plugin::uartdmx::UartDmxThread, ola::plugin::usbdmx::ThreadedUsbReceiver, ola::plugin::usbdmx::ThreadedUsbSender, ola::plugin::usbpro::WidgetDetectorThread, ola::thread::CallbackThread, ola::thread::ConsumerThread, ola::thread::PeriodicThread, ola::thread::SignalThread, ola::usb::LibUsbThread, OlaThread, and SignalThread.

## ◆ Self()

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:

- include/ola/thread/Thread.h
- common/thread/Thread.cpp