linuxsampler 2.3.1
|
Abstract base class for classes that need to run in an own thread. More...
#include <Thread.h>
Public Member Functions | |
Thread (bool LockMemory, bool RealTime, int PriorityMax, int PriorityDelta) | |
virtual | ~Thread () |
virtual int | StartThread () |
virtual int | StopThread () |
virtual int | SignalStopThread () |
virtual bool | IsRunning () |
std::string | name () |
Static Public Member Functions | |
static void * | allocAlignedMem (size_t boundary, size_t size) |
Allocates an aligned block of memory. | |
static void | freeAlignedMem (void *ptr) |
Frees an aligned block of memory allocated with allocAlignedMem() | |
static bool | lockMemory (void *addr, size_t size) |
Locks a region of memory in physical RAM. | |
static bool | unlockMemory (void *addr, size_t size) |
Unlocks a region of memory in physical RAM. | |
static void | pushCancelable (bool cancel) |
static void | popCancelable () |
static std::string | nameOfCaller () |
static void | setNameOfCaller (std::string name) |
Protected Member Functions | |
virtual int | Main ()=0 |
This method needs to be implemented by the descending class and is the entry point for the new thread. | |
void | TestCancel () |
Synchronization point for potentially terminating the thread. | |
virtual int | SignalStartThread () |
virtual int | SetSchedulingPriority () |
virtual int | LockMemory () |
virtual void | EnableDestructor () |
virtual int | onThreadEnd () |
Abstract base class for classes that need to run in an own thread.
The deriving class needs to implement the abstract method Main() for the actual task of the thread to be implemented.
IMPORTANT: You MUST call StopThread() before destructing a running Thread object! Destructing the Thread object without stopping it first can lead to undefined behavior! The destructor will detect if the thread is still running and will stop it automatically in this case, however once the destructor is entered, this Thread object's vpointer is already been modified, so if the thread is still running at this point this would cause a data race condition since the active thread is calling virtual methods and thus this can lead to undefined behavior.
|
virtual |
Allocates an aligned block of memory.
Allocated memory blocks need to be freed using freeAlignedMem().
boundary | - the alignement boundary, usually a power of 2 e.g. 4 but it can be an arbitrary number between 1 and 128 |
size | - size in bytes to be allocated |
Definition at line 83 of file Thread.h.
Referenced by LinuxSampler::AudioChannel::AudioChannel().
Frees an aligned block of memory allocated with allocAlignedMem()
ptr | - pointer to the memory block |
Definition at line 95 of file Thread.h.
Referenced by LinuxSampler::AudioChannel::~AudioChannel().
This method needs to be implemented by the descending class and is the entry point for the new thread.
NOTE: If your thread runs for a longer time, i.e. if it is running a loop, then you should explicitly call TestCancel() once in a while in your Main() implementation, especially if your implementation does not use any system calls.
Implemented in LinuxSampler::InstrumentEditor.
std::string LinuxSampler::Thread::name | ( | ) |
|
static |
|
protected |
Synchronization point for potentially terminating the thread.
Like already described in Main() you should call TestCancel() in your Main() implementation once in a while to provide the system a chance to perform a clean termination of your thread. Depending on the underlying OS, and also depending on whether your are using any system call in your Main() implementation, it might otherwise be possible that the thread cannot be terminated at all! And even if the underlying OS supports terminating busy threads which do not call TestCancel(), this might still cause undefined behavior on such OSes!