Thread wrapper class to be used for attachment to an existing thread or a new to be created thread. This class can only be used to derive from since the constructor Thread::Thread() is protected by design. at least the run() function must be overridden.
More...
#include <Thread.h>
|
| enum | EStatus : int {
tsInvalid = 0
, tsCreated
, tsRunning
, tsFinished
,
tsTerminated
} |
| | Thread states enumeration. More...
|
| |
| enum | EPriority : int {
tpIdle = -15
, tpLowest = -2
, tpBelowNormal = -1
, tpNormal = 0
,
tpAboveNormal = 1
, tpHighest = 2
, tpTimeCritical = 15
} |
| | Enumeration of thread priorities. More...
|
| |
| typedef pthread_t | handle_type |
| | Local declaration of the handle type.
|
| |
| typedef pid_t | id_type |
| | Local declaration of the thread id type.
|
| |
|
| handle_type | start () |
| | Starts a thread with default attributes which calls on its turn the overridden run().
|
| |
| handle_type | start (const Attributes &attr) |
| | Starts a thread which calls on its turn the overridden function Run().
|
| |
| virtual void | terminate () |
| | Can be overridden to signal the thread to terminate.
|
| |
| void | terminateAndWait () |
| | Same as calling Terminate() and thereafter calling WaitForExit()
|
| |
| void | waitForExit () |
| | Waits for the thread to exit.
|
| |
| EStatus | getStatus () const |
| | Returns the status.
|
| |
| const char * | getStatusText (EStatus status=(EStatus) -1) const |
| | Returns the status a string.
|
| |
| int | getExitCode () const |
| | Returns the exist value of the thread function.
|
| |
| bool | isSelf () const |
| | Returns true if the calling thread is this thread.
|
| |
| id_type | getId () const |
| | Returns the thread ID. Is currently in Linux the same as the handle.
|
| |
| handle_type | getHandle () const |
| | Returns the handle of this instance.
|
| |
| | operator handle_type () const |
| | Casting operator for THandle type.
|
| |
| void | setName (const char *name) |
| | Sets the name of the thread available in the debugger. The name is clipped to the first 15 characters only.
|
| |
| std::string | getName () const |
| | Gets the name of the thread available in the debugger.
|
| |
| int | getPriority () const |
| | Gets the current priority of this instance.
|
| |
| bool | setPriority (int pri, int sp=Attributes::spScheduleOther) |
| | Can pass an enumerate EPriority for simplicity.
|
| |
| void | setTerminationTime (const TimeSpec &ts) |
| | Sets the time needed for the thread to terminate. Default is one 100 ms.
|
| |
| bool | shouldTerminate () const |
| | Call by the thread itself to determine if it should terminate. Another thread then this one it too but has no effect.
|
| |
| void | exit (int code) |
| | Alternative to returning from then run() method. Called from within the thread that wants to exit early. It save-guarded from other threads calling it.
|
| |
| void | setDebug (bool yn) |
| | Enables debug logging.
|
| |
| bool | sleep (const TimeSpec &ts, bool alertable=true) const |
| | Makes the current thread sleep for the given amount time until a signal interrupts when alertable is true.
|
| |
| | Thread (const Thread &)=delete |
| | Copying constructor disabled and not implemented.
|
| |
| const Thread & | operator= (const Thread &)=delete |
| | Copy constructor not implemented.
|
| |
| bool | isDebug () const |
| | Gets the debug flag.
|
| |
|
| | Thread (const std::string &name) |
| | Protected constructor which demands to derive a class.
|
| |
| | Thread (bool) |
| | Wraps this class around the main thread of the application. The boolean bogus argument is to be different from the default constructor.
|
| |
| virtual | ~Thread () |
| | Virtual Destructor.
|
| |
| virtual void | cleanup () |
| | Function which can be overridden in a derived class.
|
| |
| virtual int | run ()=0 |
| | Function which needs to be overridden in a derived class. This function is the actual thread function.
|
| |
| void | TerminationSignal () |
| | Called to unblock system functions.
|
| |
Thread wrapper class to be used for attachment to an existing thread or a new to be created thread. This class can only be used to derive from since the constructor Thread::Thread() is protected by design. at least the run() function must be overridden.
◆ handle_type
Local declaration of the handle type.
◆ id_type
Local declaration of the thread id type.
◆ EPriority
Enumeration of thread priorities.
| Enumerator |
|---|
| tpIdle | |
| tpLowest | |
| tpBelowNormal | |
| tpNormal | |
| tpAboveNormal | |
| tpHighest | |
| tpTimeCritical | |
◆ EStatus
Thread states enumeration.
- See also
- getStatus(), getStatusText()
| Enumerator |
|---|
| tsInvalid | The thread is not setup yet.
|
| tsCreated | The thread is created but not started.
|
| tsRunning | Thread is running.
|
| tsFinished | The thread has run and finished.
|
| tsTerminated | The thread was externally terminated.
|
◆ Thread() [1/3]
| sf::Thread::Thread |
( |
const Thread & |
| ) |
|
|
delete |
Copying constructor disabled and not implemented.
◆ Thread() [2/3]
| sf::Thread::Thread |
( |
const std::string & |
name | ) |
|
|
protected |
Protected constructor which demands to derive a class.
◆ Thread() [3/3]
| sf::Thread::Thread |
( |
bool |
| ) |
|
|
protected |
Wraps this class around the main thread of the application. The boolean bogus argument is to be different from the default constructor.
◆ ~Thread()
| virtual sf::Thread::~Thread |
( |
| ) |
|
|
protectedvirtual |
◆ cleanup()
| virtual void sf::Thread::cleanup |
( |
| ) |
|
|
protectedvirtual |
Function which can be overridden in a derived class.
Is called after a thread cancel.
◆ exit()
| void sf::Thread::exit |
( |
int |
code | ) |
|
Alternative to returning from then run() method. Called from within the thread that wants to exit early. It save-guarded from other threads calling it.
- See also
- run()
◆ getCurrent()
| static Thread & sf::Thread::getCurrent |
( |
| ) |
|
|
static |
Gets the sf::Thread instance reference of the current thread.
- Returns
◆ getCurrentHandle()
Return the current thread handle.
- Returns
- Thread handle.
◆ getCurrentId()
| static id_type sf::Thread::getCurrentId |
( |
| ) |
|
|
static |
Gets the current thread ID.
- Returns
- Current thread id.
◆ getCurrentStackSize()
| static size_t sf::Thread::getCurrentStackSize |
( |
| ) |
|
|
static |
Returns the current thread initial stack size.
- Returns
- The stack size.
- Exceptions
-
◆ getExitCode()
| int sf::Thread::getExitCode |
( |
| ) |
const |
Returns the exist value of the thread function.
◆ getHandle()
Returns the handle of this instance.
◆ getId()
| id_type sf::Thread::getId |
( |
| ) |
const |
Returns the thread ID. Is currently in Linux the same as the handle.
◆ getMainId()
| static id_type sf::Thread::getMainId |
( |
| ) |
|
|
static |
Gets the main thread ID.
- Returns
- Main thread Id.
◆ getName()
| std::string sf::Thread::getName |
( |
| ) |
const |
Gets the name of the thread available in the debugger.
- Note
- The thread must be created for this.
◆ getPriority()
| int sf::Thread::getPriority |
( |
| ) |
const |
Gets the current priority of this instance.
◆ getStatus()
| EStatus sf::Thread::getStatus |
( |
| ) |
const |
Returns the status.
- See also
- EStatus
◆ getStatusText()
| const char * sf::Thread::getStatusText |
( |
EStatus |
status = (EStatus) -1 | ) |
const |
Returns the status a string.
By default, the current state is returned.
- See also
- getStatus()
◆ getTerminationSignal()
| static int sf::Thread::getTerminationSignal |
( |
| ) |
|
|
static |
Returns the thread termination signal.
◆ isDebug()
| bool sf::Thread::isDebug |
( |
| ) |
const |
|
inline |
◆ isSelf()
| bool sf::Thread::isSelf |
( |
| ) |
const |
Returns true if the calling thread is this thread.
◆ operator handle_type()
Casting operator for THandle type.
◆ operator=()
Copy constructor not implemented.
◆ run()
| virtual int sf::Thread::run |
( |
| ) |
|
|
protectedpure virtual |
Function which needs to be overridden in a derived class. This function is the actual thread function.
Implemented in sf::ThreadMain, and sf::ThreadClosure.
◆ setDebug()
| void sf::Thread::setDebug |
( |
bool |
yn | ) |
|
|
inline |
Enables debug logging.
- Parameters
-
◆ setName()
| void sf::Thread::setName |
( |
const char * |
name | ) |
|
Sets the name of the thread available in the debugger. The name is clipped to the first 15 characters only.
- Note
- The thread must be created for this.
◆ setPriority()
Can pass an enumerate EPriority for simplicity.
- See also
- EPriority
◆ setTerminationTime()
| void sf::Thread::setTerminationTime |
( |
const TimeSpec & |
ts | ) |
|
Sets the time needed for the thread to terminate. Default is one 100 ms.
◆ shouldTerminate()
| bool sf::Thread::shouldTerminate |
( |
| ) |
const |
Call by the thread itself to determine if it should terminate. Another thread then this one it too but has no effect.
◆ sleep()
| bool sf::Thread::sleep |
( |
const TimeSpec & |
ts, |
|
|
bool |
alertable = true |
|
) |
| const |
Makes the current thread sleep for the given amount time until a signal interrupts when alertable is true.
- Returns
- True when completed and false when interrupted.
◆ start() [1/2]
Starts a thread with default attributes which calls on its turn the overridden run().
- See also
- run()
◆ start() [2/2]
Starts a thread which calls on its turn the overridden function Run().
- Parameters
-
| attr | Attributes for stack size and scheduling and prioritisation. |
- Returns
- Handle of the created thread.
◆ terminate()
| virtual void sf::Thread::terminate |
( |
| ) |
|
|
virtual |
◆ terminateAndWait()
| void sf::Thread::terminateAndWait |
( |
| ) |
|
◆ TerminationSignal()
| void sf::Thread::TerminationSignal |
( |
| ) |
|
|
protected |
Called to unblock system functions.
◆ waitForExit()
| void sf::Thread::waitForExit |
( |
| ) |
|
Waits for the thread to exit.
◆ yieldToOther()
| static bool sf::Thread::yieldToOther |
( |
| ) |
|
|
static |
Yield control of the current thread. The name 'Yield()' is defined as a macro in MingW.
- Returns
- True when successful.
◆ Condition
◆ installSignalHandlers
| void installSignalHandlers |
( |
| ) |
|
|
friend |
Allow access to privates to this class from functions or classes.
◆ Code
| intptr_t sf::Thread::Code |
◆ Ptr
The documentation for this class was generated from the following file: