The thread base class. More...

#include "murl_system_thread.h"

Inheritance diagram for Murl::System::Thread:

Public Types

enum  SchedulingPriority { SCHEDULING_PRIORITY_LOWEST , SCHEDULING_PRIORITY_NORMAL , SCHEDULING_PRIORITY_HIGHEST }
 Thread scheduling priority enumeration. More...
 
enum  SchedulingPolicy { SCHEDULING_POLICY_OTHER , SCHEDULING_POLICY_FIFO , SCHEDULING_POLICY_ROUND_ROBIN }
 Thread scheduling policy enumeration. More...
 

Public Member Functions

virtual ~Thread ()
 The destructor.
 
virtual Bool Start ()
 Create and start the thread. More...
 
virtual void Stop ()
 Stop the thread. More...
 
virtual void Join ()
 Join and destroy the thread. More...
 
virtual void Flush ()
 Flush the autorelease memory pool. More...
 
virtual UInt64 GetId ()
 Get the thread identifier. More...
 

Static Public Member Functions

static Bool SetCurrentPriority (SchedulingPriority priority, SchedulingPolicy policy=SCHEDULING_POLICY_OTHER)
 Set the current thread's priority and scheduling policy. More...
 
static Bool SetCurrentAffinityMask (UInt32 mask)
 Set the current thread's CPU affinity mask. More...
 
static UInt64 GetCurrentId ()
 Get the current thread identifier. More...
 

Protected Member Functions

 Thread (const String &name)
 Constructor taking a thread name. More...
 
virtual Bool Run ()=0
 The abstract run method for overloading. More...
 

Protected Attributes

Bool mIsRunning
 The running state of the thread.
 
String mName
 The name of the thread.
 
UInt64 mThreadId
 The identifier of the thread.
 
ThreadHandle * mHandle
 The anonymous thread handle for internal use only.
 

Detailed Description

The thread base class.

The implementation of a thread class must derive from the thread base class and implement the Run() method.

(!) Important: To avoid destroying the thread object while the thread is running, it is required to implement the destructor.

class MyThread : public System::Thread
{
virtual ~MyThread()
{
Stop();
Join();
// now it is safe to destroy objects and free memory.
}
virtual Bool Run()
{
while (mIsRunning)
{
// do some stuff.
Flush();
}
return true;
}
};
Bool mIsRunning
The running state of the thread.
Definition: murl_system_thread.h:154
virtual void Flush()
Flush the autorelease memory pool.
virtual Bool Run()=0
The abstract run method for overloading.
virtual void Join()
Join and destroy the thread.
virtual void Stop()
Stop the thread.
bool Bool
Boolean data type This typedef represents a boolean value (true or false).
Definition: murl_types.h:158

Member Enumeration Documentation

◆ SchedulingPriority

Thread scheduling priority enumeration.

Enumerator
SCHEDULING_PRIORITY_LOWEST 

Lowest priority.

SCHEDULING_PRIORITY_NORMAL 

Normal priority.

SCHEDULING_PRIORITY_HIGHEST 

Highest priority.

◆ SchedulingPolicy

Thread scheduling policy enumeration.

Enumerator
SCHEDULING_POLICY_OTHER 

Unspecified policy.

SCHEDULING_POLICY_FIFO 

FIFO policy.

SCHEDULING_POLICY_ROUND_ROBIN 

Round robin policy.

Constructor & Destructor Documentation

◆ Thread()

Murl::System::Thread::Thread ( const String name)
protected

Constructor taking a thread name.

Parameters
nameThe name of the thread. On OSX/iOS systems the thread name is truncated to 63 characters.

Member Function Documentation

◆ Start()

virtual Bool Murl::System::Thread::Start ( )
virtual

Create and start the thread.

Set the mIsRunning state to true.

Returns
true if successful, false if starting failed or the thread is already created.

Reimplemented in Murl::Util::MessageThread.

◆ Stop()

virtual void Murl::System::Thread::Stop ( )
virtual

Stop the thread.

Set the mIsRunning state to false. After calling Stop() it is required to call Join(), otherwise it is not possible to call Start() again.

Reimplemented in Murl::Util::MessageThread.

◆ Join()

virtual void Murl::System::Thread::Join ( )
virtual

Join and destroy the thread.

Typically Stop() is called before to exit the main loop in the Run() method.

◆ Flush()

virtual void Murl::System::Thread::Flush ( )
virtual

Flush the autorelease memory pool.

Drain the AutoReleasePool on OSX/iOS systems.

◆ GetId()

virtual UInt64 Murl::System::Thread::GetId ( )
virtual

Get the thread identifier.

Directly after creation, the thread's identifier remains unknown until Start() is called. Only then a valid identifier is returned.

Returns
The thread identifier, or 0 if the thread has not been started yet.

◆ SetCurrentPriority()

static Bool Murl::System::Thread::SetCurrentPriority ( SchedulingPriority  priority,
SchedulingPolicy  policy = SCHEDULING_POLICY_OTHER 
)
static

Set the current thread's priority and scheduling policy.

Parameters
priorityOne of the available thread priority enum values.
policyA hint to the scheduling policy to use.
Returns
true if successful.

◆ SetCurrentAffinityMask()

static Bool Murl::System::Thread::SetCurrentAffinityMask ( UInt32  mask)
static

Set the current thread's CPU affinity mask.

Parameters
maskA bit mask representing individual CPUs (or CPU cores)
Returns
true if successful.

◆ GetCurrentId()

static UInt64 Murl::System::Thread::GetCurrentId ( )
static

Get the current thread identifier.

The current thread identifier is not necessarily the identifier of the thread class. Note the static declaration which means System::Thread::GetCurrentId() can be called without a class context.

Returns
The current thread identifier.

◆ Run()

virtual Bool Murl::System::Thread::Run ( )
protectedpure virtual

The abstract run method for overloading.

On OSX/iOS systems an AutoReleasePool is created before calling Run().

Returns
true if successful.

Implemented in Murl::Util::MessageThread.


The documentation for this class was generated from the following file:
  • murl_system_thread.h


Copyright © 2011-2024 Spraylight GmbH.