sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::Thread Class Referenceabstract

#include <Thread.h>

Inheritance diagram for sptk::Thread:
sptk::LogEngine sptk::SocketEvents sptk::TCPServerListener sptk::WorkerThread sptk::FileLogEngine sptk::SysLogEngine

Public Types

using Id = std::thread::id
 

Public Member Functions

 Thread (const String &name, const std::shared_ptr< ThreadManager > &threadManager=nullptr)
 
virtual ~Thread ()
 
virtual void run ()
 
bool running () const
 
virtual void threadFunction ()=0
 
virtual void terminate ()
 
virtual void onThreadExit ()
 
virtual bool terminated ()
 
virtual void join ()
 
Id id () const
 
const Stringname () const
 
virtual bool sleep_for (std::chrono::milliseconds interval)
 
virtual bool sleep_until (const DateTime &timestamp)
 

Detailed Description

Base thread object.

Should be used for deriving a user thread by overwriting threadFunction().

Member Typedef Documentation

◆ Id

using sptk::Thread::Id = std::thread::id

Thread ID type

Constructor & Destructor Documentation

◆ Thread()

sptk::Thread::Thread ( const String name,
const std::shared_ptr< ThreadManager > &  threadManager = nullptr 
)
explicit

Constructor

Parameters
nameName of the thread for future references.
threadManagerOptional thread manager. If provided, then it owns the created thread's memory.

◆ ~Thread()

virtual sptk::Thread::~Thread ( )
virtual

Destructor

Member Function Documentation

◆ id()

Id sptk::Thread::id ( ) const

Returns this thread OS id

◆ join()

virtual void sptk::Thread::join ( )
virtual

Waits until thread joins

◆ name()

const String & sptk::Thread::name ( ) const
inline

Returns the name of the thread

◆ onThreadExit()

virtual void sptk::Thread::onThreadExit ( )
inlinevirtual

This method is executed immediately after thread function exit

◆ run()

virtual void sptk::Thread::run ( )
virtual

Starts the already created thread

Referenced by sptk::TCPServerListener::listen().

◆ running()

bool sptk::Thread::running ( ) const

Check thread status

Returns
true if thread is running

Referenced by sptk::TCPServerListener::listen().

◆ sleep_for()

virtual bool sptk::Thread::sleep_for ( std::chrono::milliseconds  interval)
virtual

Sleep for interval of time The sleep is automatically interrupted when terminate() is called.

Parameters
intervalInterval of time

◆ sleep_until()

virtual bool sptk::Thread::sleep_until ( const DateTime timestamp)
virtual

Sleep until moment of time The pause is automatically interrupted when terminate() is called.

Parameters
timestampMoment of time

◆ terminate()

virtual void sptk::Thread::terminate ( )
virtual

Requests to terminate the thread

Reimplemented in sptk::SocketEvents, sptk::TCPServerListener, and sptk::WorkerThread.

◆ terminated()

virtual bool sptk::Thread::terminated ( )
virtual

Returns true if the thread is terminated

◆ threadFunction()

virtual void sptk::Thread::threadFunction ( )
pure virtual

The thread function. Should be overwritten by the derived class.

Implemented in sptk::LogEngine, sptk::SocketEvents, sptk::TCPServerListener, and sptk::WorkerThread.


The documentation for this class was generated from the following file:

Fri Oct 14 2022 09:58:46: SPTK 5.4.1