Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
cIsThread Class Referenceabstract

#include <IsThread.h>

Inheritance diagram for cIsThread:
Inheritance graph
[legend]
Collaboration diagram for cIsThread:
Collaboration graph
[legend]

Public Member Functions

 cIsThread (AString &&a_ThreadName)
 
bool IsCurrentThread (void) const
 Returns true if the thread calling this function is the thread contained within this object. More...
 
void Start (void)
 Starts the thread; returns without waiting for the actual start. More...
 
void Stop (void)
 Signals the thread to terminate and waits until it's finished. More...
 
virtual ~cIsThread ()
 

Protected Member Functions

virtual void Execute (void)=0
 This function, overloaded by the descendants, is called in the new thread. More...
 

Protected Attributes

std::atomic< bool > m_ShouldTerminate
 The overriden Execute() method should check this value periodically and terminate if this is true. More...
 

Private Member Functions

void Entrypoint (void)
 This is the main thread entrypoint. More...
 
void SetThreadName () const
 Sets the name of the current thread to be the name provided in m_ThreadName. More...
 

Private Attributes

cEvent m_Initialisation
 The event that is used to wait with the thread's execution until the thread object is fully initialized. More...
 
std::thread m_Thread
 The thread object which holds the created thread for later manipulation. More...
 
AString m_ThreadName
 The name of the thread, used to aid debugging in IDEs which support named threads. More...
 

Detailed Description

Definition at line 23 of file IsThread.h.

Constructor & Destructor Documentation

◆ cIsThread()

cIsThread::cIsThread ( AString &&  a_ThreadName)

Definition at line 16 of file IsThread.cpp.

◆ ~cIsThread()

cIsThread::~cIsThread ( )
virtual

Definition at line 26 of file IsThread.cpp.

Member Function Documentation

◆ Entrypoint()

void cIsThread::Entrypoint ( void  )
private

This is the main thread entrypoint.

Wrapper for Execute() that waits for the initialization event, to prevent race conditions in thread initialization.

Definition at line 66 of file IsThread.cpp.

◆ Execute()

virtual void cIsThread::Execute ( void  )
protectedpure virtual

This function, overloaded by the descendants, is called in the new thread.

Implemented in cWorldStorage, cWorld::cTickThread, cServer::cTickThread, cMojangAPI::cUpdateThread, cAuthenticator, cLightingThread, cDeadlockDetect, cChunkSender, cChunkGeneratorThread, and cNetworkLookup.

◆ IsCurrentThread()

bool cIsThread::IsCurrentThread ( void  ) const
inline

Returns true if the thread calling this function is the thread contained within this object.

Definition at line 37 of file IsThread.h.

◆ SetThreadName()

void cIsThread::SetThreadName ( ) const
private

Sets the name of the current thread to be the name provided in m_ThreadName.

Definition at line 94 of file IsThread.cpp.

◆ Start()

void cIsThread::Start ( void  )

Starts the thread; returns without waiting for the actual start.

Definition at line 35 of file IsThread.cpp.

◆ Stop()

void cIsThread::Stop ( void  )

Signals the thread to terminate and waits until it's finished.

Definition at line 48 of file IsThread.cpp.

Member Data Documentation

◆ m_Initialisation

cEvent cIsThread::m_Initialisation
private

The event that is used to wait with the thread's execution until the thread object is fully initialized.

This prevents the IsCurrentThread() call to fail because of a race-condition where the thread starts before m_Thread has been fully assigned.

Definition at line 57 of file IsThread.h.

◆ m_ShouldTerminate

std::atomic<bool> cIsThread::m_ShouldTerminate
protected

The overriden Execute() method should check this value periodically and terminate if this is true.

Definition at line 45 of file IsThread.h.

◆ m_Thread

std::thread cIsThread::m_Thread
private

The thread object which holds the created thread for later manipulation.

Definition at line 50 of file IsThread.h.

◆ m_ThreadName

AString cIsThread::m_ThreadName
private

The name of the thread, used to aid debugging in IDEs which support named threads.

Definition at line 53 of file IsThread.h.


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