16 #include <sys/eventfd.h>
139 spScheduleOther = SCHED_OTHER,
141 spScheduleFifo = SCHED_FIFO,
143 spScheduleRoundRobin = SCHED_RR,
145 spScheduleBatch = spScheduleOther,
146 spScheduleIdle = spScheduleOther,
147 spScheduleResetOnFork = spScheduleOther
149 spScheduleBatch = SCHED_BATCH,
150 spScheduleIdle = SCHED_IDLE,
151 spScheduleResetOnFork = SCHED_RESET_ON_FORK
318 inline void setDebug(
bool yn);
340 formatMessage(message);
346 template<
typename... Args>
350 formatMessage(format, args...);
417 [[nodiscard]]
inline bool isDebug()
const;
464 void setConditionWaiting(
Condition* condition);
473 Mutex _mutex{
"thread"};
481 handle_type _handle{0};
485 EStatus _status{EStatus::tsInvalid};
489 bool _terminationRequested{
false};
493 TimeSpec _terminationTime{};
497 TimeSpec _startupTime{0.3};
503 Condition* _condition{
nullptr};
510 Condition* _condition_waiting{
nullptr};
522 } _exitCode{
nullptr};
Wrapper for the pthread_cond mechanism.
Definition Condition.h:16
Exception implementation inherited from std::exception.
Definition Exception.h:18
Lightweight intra process thread synchronization.
Definition Mutex.h:17
Wrapper class for the main thread.
Definition Thread.h:560
int run() override
Overrides run function but does nothing since it is the main thread.
Definition Thread.h:576
ThreadMain()
Calls on protected boolean constructor.
Definition Thread.h:572
Thread attributes used internally for starting a thread.
Definition Thread.h:76
Attributes(Thread::handle_type th)
Initialize using the passed thread handle.
::pthread_attr_t * handle_type
Definition Thread.h:81
Attributes & operator=(const Attributes &)=delete
Prevent assignment.
ESchedulePolicy
Thread schedule policies.
Definition Thread.h:137
Attributes(const Attributes &)=delete
Prevent copying.
void setup(Thread::handle_type th=0)
When the handle is '0' the current thread is used.
Attributes()
Default Constructor.
size_t getStackSize() const
Gets the stack size of the thread which initialized it.
ESchedulePolicy getSchedulePolicy() const
Gets the current set scheduling priority.
void setStackSize(size_t sz)
Sets the stack size for a new thread.
void setSchedulePolicy(ESchedulePolicy policy)
Sets scheduling priority for the to be started thread.
Special thread exception thrown by system blocking functions to terminate the thread.
Definition Thread.h:359
TerminateException(const std::string &from)
Definition Thread.h:361
Thread exception.
Definition Thread.h:332
ThreadException(const char *format, Args &&... args) noexcept
Formatting constructor.
Definition Thread.h:347
ThreadException(const char *message) noexcept
Constructor initializing message.
Definition Thread.h:337
Thread wrapper class to be used for attachment to an existing thread or a new to be created thread....
Definition Thread.h:28
void waitForExit()
Waits for the thread to exit.
EStatus
Thread states enumeration.
Definition Thread.h:49
@ tsRunning
Thread is running.
Definition Thread.h:61
@ tsCreated
The thread is created but not started.
Definition Thread.h:57
@ tsFinished
The thread has run and finished.
Definition Thread.h:65
bool isDebug() const
Gets the debug flag.
Definition Thread.h:551
intptr_t Code
Definition Thread.h:521
bool shouldTerminate() const
Call by the thread itself to determine if it should terminate. Another thread then this one it too bu...
const char * getStatusText(EStatus status=(EStatus) -1) const
Returns the status a string.
Thread(const Thread &)=delete
Copying constructor disabled and not implemented.
static int getTerminationSignal()
Returns the thread termination signal.
handle_type getHandle() const
Returns the handle of this instance.
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 ...
bool isSelf() const
Returns true if the calling thread is this thread.
pthread_t handle_type
Local declaration of the handle type.
Definition Thread.h:33
static id_type getCurrentId()
Gets the current thread ID.
Thread(const std::string &name)
Protected constructor which demands to derive a class.
virtual void cleanup()
Function which can be overloaded in a derived class.
virtual ~Thread()
Virtual Destructor.
static id_type getMainId()
Gets the main thread ID.
int getPriority() const
Gets the current priority of this instance.
std::string getName() const
Gets the name of the thread available in the debugger.
bool setPriority(int pri, int sp=Attributes::spScheduleOther)
Can pass an enumerate EPriority for simplicity.
EStatus getStatus() const
Returns the status.
virtual int run()=0
Function which needs to be overloaded in a derived class. This function is the actual thread function...
void * Ptr
Definition Thread.h:520
void setTerminationTime(const TimeSpec &ts)
Sets the time needed for the thread to terminate. Default is one 100 ms.
static size_t getCurrentStackSize()
Returns the current thread initial stack size.
void setName(const char *name)
Sets the name of the thread available in the debugger. The name is clipped to the first 15 characters...
Thread(bool)
Wraps this class around the main thread of the application. The boolean bogus argument is to be diffe...
static bool yieldToOther()
Yield control of the current thread. The name 'Yield()' is defined as a macro in MingW.
static Thread & getCurrent()
Gets the sf::Thread instance reference of the current thread.
void TerminationSignal()
Called to unblock system functions.
void terminateAndWait()
Same as calling Terminate() and thereafter calling WaitForExit()
EPriority
Enumeration of thread priorities.
Definition Thread.h:259
int getExitCode() const
Returns the exist value of the thread function.
const Thread & operator=(const Thread &)=delete
Copy constructor not implemented.
void exit(int code)
Alternative to returning from then run() method. Called from within the thread that wants to exit ear...
void setDebug(bool yn)
Enables debug logging.
Definition Thread.h:546
virtual void terminate()
Can be overloaded to signal the thread to terminate.
handle_type start(const Attributes &attr)
Starts a thread which calls on its turn the overridden function Run().
id_type getId() const
Returns the thread ID. Is currently in Linux the same as the handle.
pid_t id_type
Local declaration of the thread id type.
Definition Thread.h:41
static handle_type getCurrentHandle()
Return the current thread handle.
handle_type start()
Starts a thread with default attributes which calls on its turn the overridden run().
friend void installSignalHandlers()
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
_MISC_FUNC bool isDebug()
Gets the debug status.
Class wrapper for timespec structure to modify.
Definition TimeSpec.h:12