|
Yate
|
#include <yateclass.h>
Public Types | |
| enum | Priority { Lowest , Low , Normal , High , Highest } |
Public Member Functions | |
| virtual void | cleanup () |
| bool | startup () |
| bool | error () const |
| bool | running () const |
| int | getAffinity (DataBlock &outCpuMask) |
| int | setAffinity (const String &cpus) |
| int | setAffinity (const DataBlock &mask) |
| int | locks () const |
| bool | locked () const |
| const char * | name () const |
| void | cancel (bool hard=false) |
| bool | isCurrent () const |
| NamedCounter * | getObjCounter () const |
| NamedCounter * | setObjCounter (NamedCounter *counter) |
Public Member Functions inherited from Runnable | |
| virtual void | run ()=0 |
| virtual | ~Runnable () |
Static Public Member Functions | |
| static const char * | currentName () |
| static int | getCurrentAffinity (DataBlock &outCpuMask) |
| static int | getCurrentAffinity (String &outCpus, bool hex=false) |
| static int | setCurrentAffinity (const String &cpus) |
| static int | setCurrentAffinity (const DataBlock &mask) |
| static bool | parseCPUMask (const String &cpus, DataBlock &mask) |
| static void | printCPUMask (const DataBlock &mask, String &str, bool hexa=true) |
| static void | yield (bool exitCheck=false) |
| static void | idle (bool exitCheck=false) |
| static void | sleep (unsigned int sec, bool exitCheck=false) |
| static void | msleep (unsigned long msec, bool exitCheck=false) |
| static void | usleep (unsigned long usec, bool exitCheck=false) |
| static unsigned long | idleUsec () |
| static unsigned long | idleMsec () |
| static void | idleMsec (unsigned long msec) |
| static Thread * | current () |
| static int | count () |
| static bool | check (bool exitNow=true) |
| static void | exit () |
| static NamedCounter * | getCurrentObjCounter (bool always=false) |
| static NamedCounter * | setCurrentObjCounter (NamedCounter *counter) |
| static Priority | priority (const char *name, Priority defvalue=Normal) |
| static const char * | priority (Priority prio) |
| static void | killall () |
| static void | preExec () |
| static int | lastError () |
| static bool | errorString (String &buffer) |
| static bool | errorString (String &buffer, int code) |
Protected Member Functions | |
| Thread (const char *name=0, Priority prio=Normal) | |
| Thread (const char *name, const char *prio) | |
| virtual | ~Thread () |
Friends | |
| class | ThreadPrivate |
| class | MutexPrivate |
| class | SemaphorePrivate |
Thread support class.
A thread is a separate execution context that exists in the same address space. Threads make better use of multiple processor machines and allow blocking one execution thread while allowing other to run.
| enum Priority |
Running priorities, their mapping is operating system dependent
|
protected |
|
protectedvirtual |
The destructor is called when the thread terminates
| void cancel | ( | bool | hard = false | ) |
Terminates the specified thread.
| hard | Kill the thread the hard way rather than just setting an exit check marker |
|
static |
Check if the current thread was asked to terminate.
| exitNow | If thread is marked as cancelled then terminate immediately |
|
virtual |
|
static |
Get the number of Yate created threads
|
static |
Get a pointer to the currently running thread
References Thread().
Referenced by isCurrent().
|
static |
Get the name of the currently running thread
| bool error | ( | ) | const |
Check if the thread creation failed
|
inlinestatic |
Get the last thread error's string from system.
| buffer | The destination string |
References errorString(), and lastError().
Referenced by errorString().
|
static |
Get an error string from system. On Windows the code parameter must be a code returned by GetLastError(). Otherwise, the error code should be a valid value for the C library 'errno' variable
| buffer | The destination string |
| code | The error code |
|
static |
Terminates the current thread.
| int getAffinity | ( | DataBlock & | outCpuMask | ) |
Get the affinity mask of this thread
| outCpuMask | Bit mask specifying CPUs on which the thread is running on. Bit 0 of octet 0 in DataBlock is CPU 0, bit 1 in octet 0 is CPU 1,..., bit 0 in octet 2 is CPU 8, etc. |
|
static |
Get the affinity mask of current thread
| outCpuMask | Bit mask specifying CPUs on which the current thread is running on. Bit 0 of octet 0 in DataBlock is CPU 0, bit 1 in octet 0 is CPU 1,..., bit 0 in octet 1 is CPU 8, etc. |
|
static |
Get the affinity mask of current thread
| outCpus | String into which to put the affinity |
| hex | True to put it as octet string, false as comma-separated list of CPUs |
|
static |
Get the object counter of the current thread
| always | Return the object even if counting is disabled |
Referenced by TranslatorFactory::TranslatorFactory().
| NamedCounter * getObjCounter | ( | ) | const |
Get the object counter of this thread
|
static |
Sleep for a system dependent period adequate for an idle thread. On most operating systems this is a 5 msec sleep.
| exitCheck | Terminate the thread if asked so |
|
static |
Get the platform dependent idle sleep interval in milliseconds
|
static |
Set the idle sleep interval or reset to platform default
| msec | Sleep interval in milliseconds, platform default if zero |
|
static |
Get the platform dependent idle sleep interval in microseconds
|
inline |
Check if this thread is the currently running thread
References current().
|
static |
Kills all other running threads. Ouch! Must be called from the main thread or it does nothing.
|
static |
Get the last thread error
Referenced by errorString().
|
inline |
Check if the thread is currently helding or attempting to lock a mutex
|
inline |
Count how many Yate mutexes are kept locked by this thread
|
static |
Sleep for a number of milliseconds
| msec | Number of milliseconds to sleep |
| exitCheck | Terminate the thread if asked so |
| const char * name | ( | ) | const |
Get the name of this thread
Referenced by priority(), Thread(), and Thread().
Parse a CPU list into a bitmask held in a DataBlock. String is formated as a list of integers or integer ranges separated by commas.. Mixing ranges with list is allowed (e.g. 0,2,5-6,10)
| cpus | String specifying CPUs |
| mask | Output bitmask resulted from parsing. |
|
static |
On some platforms this method kills all other running threads. Must be called after fork() but before any exec*() call.
Stringify the CPU mask
| mask | Mask to stringify |
| str | Output string |
| hexa | Output as hexadecimal string if set, otherwise build a list of comma separated CPUs |
|
static |
Convert a priority level to a textual name
| prio | Priority level to convert |
| bool running | ( | ) | const |
Check if the thread is running or not
| int setAffinity | ( | const DataBlock & | mask | ) |
| int setAffinity | ( | const String & | cpus | ) |
Set the affinity of this thread by using a string that specifies the allowed CPUs by listing them separated with commas or as ranges. Mixing ranges with list is allowed (e.g. 0,2,5-6,10)
| cpus | String specifying CPUs on which this thread should run. |
|
static |
|
static |
Set the affinity of the current thread by using a string that specifies the allowed CPUs by listing them separated with commas or as ranges. Mixing ranges with list is allowed (e.g. 0,2,5-6,10)
| cpus | String specifying CPUs on which this thread should run. |
|
static |
Set the object counter of the current thread
| counter | New counter object or NULL |
Referenced by TempObjectCounter::TempObjectCounter(), TempObjectCounter::TempObjectCounter(), TempObjectCounter::TempObjectCounter(), and TempObjectCounter::~TempObjectCounter().
| NamedCounter * setObjCounter | ( | NamedCounter * | counter | ) |
Set the object counter of this thread
| counter | New counter object or NULL |
|
static |
Sleep for a number of seconds
| sec | Number of seconds to sleep |
| exitCheck | Terminate the thread if asked so |
| bool startup | ( | ) |
Actually starts running the new thread which lingers after creation
|
static |
Sleep for a number of microseconds
| usec | Number of microseconds to sleep, may be rounded to milliseconds on some platforms |
| exitCheck | Terminate the thread if asked so |
|
static |
Give up the currently running timeslice. Note that on some platforms it also sleeps for the operating system's scheduler resolution
| exitCheck | Terminate the thread if asked so |