Minetest  5.4.0
Thread Class Referenceabstract

#include <thread.h>

+ Inheritance diagram for Thread:
+ Collaboration diagram for Thread:

Public Member Functions

 Thread (const std::string &name="")
 
virtual ~Thread ()
 
bool start ()
 
bool stop ()
 
bool wait ()
 
bool isCurrentThread ()
 
bool isRunning ()
 
bool stopRequested ()
 
std::thread::id getThreadId ()
 
bool getReturnValue (void **ret)
 
bool bindToProcessor (unsigned int proc_number)
 
bool setPriority (int prio)
 

Static Public Member Functions

static void setName (const std::string &name)
 
static unsigned int getNumberOfProcessors ()
 

Protected Member Functions

virtual void * run ()=0
 

Protected Attributes

std::string m_name
 

Private Member Functions

std::thread::native_handle_type getThreadHandle ()
 

Static Private Member Functions

static void threadProc (Thread *thr)
 

Private Attributes

void * m_retval = nullptr
 
bool m_joinable = false
 
std::atomic< bool > m_request_stop
 
std::atomic< bool > m_running
 
std::mutex m_mutex
 
std::mutex m_start_finished_mutex
 
std::thread * m_thread_obj = nullptr
 

Constructor & Destructor Documentation

◆ Thread()

Thread::Thread ( const std::string &  name = "")

◆ ~Thread()

Thread::~Thread ( )
virtual

References getThreadHandle(), m_running, m_start_finished_mutex, m_thread_obj, and wait().

+ Here is the call graph for this function:

Member Function Documentation

◆ bindToProcessor()

bool Thread::bindToProcessor ( unsigned int  proc_number)

References getThreadHandle().

+ Here is the call graph for this function:

◆ getNumberOfProcessors()

unsigned int Thread::getNumberOfProcessors ( )
static

Referenced by EmergeManager::EmergeManager().

+ Here is the caller graph for this function:

◆ getReturnValue()

bool Thread::getReturnValue ( void **  ret)

References m_retval, and m_running.

Referenced by TestThreading::testStartStopWait().

+ Here is the caller graph for this function:

◆ getThreadHandle()

std::thread::native_handle_type Thread::getThreadHandle ( )
inlineprivate

References m_thread_obj.

Referenced by ~Thread(), bindToProcessor(), and setPriority().

+ Here is the caller graph for this function:

◆ getThreadId()

std::thread::id Thread::getThreadId ( )
inline

References m_thread_obj.

Referenced by isCurrentThread().

+ Here is the caller graph for this function:

◆ isCurrentThread()

bool Thread::isCurrentThread ( )
inline

References getThreadId().

Referenced by EmergeManager::getCurrentMapgen(), SimpleTestThread::run(), and TestThreading::testStartStopWait().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRunning()

bool Thread::isRunning ( )
inline

◆ run()

virtual void* Thread::run ( )
protectedpure virtual

Implemented in UpdateThread, AtomicTestThread, SimpleTestThread, TerminalChatConsole, ServerThread, AsyncWorkerThread, con::ConnectionReceiveThread, con::ConnectionSendThread, CurlFetchThread, and EmergeThread.

Referenced by threadProc().

+ Here is the caller graph for this function:

◆ setName()

void Thread::setName ( const std::string &  name)
static

Referenced by android_main(), and threadProc().

+ Here is the caller graph for this function:

◆ setPriority()

bool Thread::setPriority ( int  prio)

References getThreadHandle(), and THREAD_PRIORITY_HIGHEST.

+ Here is the call graph for this function:

◆ start()

bool Thread::start ( )

References m_joinable, m_mutex, m_request_stop, m_running, m_start_finished_mutex, m_thread_obj, sleep_ms, and threadProc().

Referenced by Minimap::Minimap(), Client::afterContentReceived(), httpfetch_async(), AsyncEngine::initialize(), run_dedicated_server(), Server::start(), and TestThreading::testStartStopWait().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stop()

bool Thread::stop ( )

References m_request_stop.

Referenced by EmergeManager::~EmergeManager(), httpfetch_cleanup(), run_dedicated_server(), Server::start(), Server::stop(), UpdateThread::stop(), and TestThreading::testStartStopWait().

+ Here is the caller graph for this function:

◆ stopRequested()

bool Thread::stopRequested ( )
inline

References m_request_stop.

Referenced by EmergeThread::run(), CurlFetchThread::run(), con::ConnectionSendThread::run(), con::ConnectionReceiveThread::run(), AsyncWorkerThread::run(), ServerThread::run(), SimpleTestThread::run(), UpdateThread::run(), and con::ConnectionSendThread::sendPackets().

+ Here is the caller graph for this function:

◆ threadProc()

void Thread::threadProc ( Thread thr)
staticprivate

References Logger::deregisterThread(), g_logger, m_name, m_retval, m_running, m_start_finished_mutex, Logger::registerThread(), run(), and setName().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wait()

bool Thread::wait ( )

References m_joinable, m_mutex, m_running, and m_thread_obj.

Referenced by Client::~Client(), EmergeManager::~EmergeManager(), Minimap::~Minimap(), ~Thread(), httpfetch_cleanup(), run_dedicated_server(), Server::stop(), and TestThreading::testStartStopWait().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_joinable

bool Thread::m_joinable = false
private

Referenced by start(), and wait().

◆ m_mutex

std::mutex Thread::m_mutex
private

Referenced by start(), and wait().

◆ m_name

std::string Thread::m_name
protected

◆ m_request_stop

std::atomic<bool> Thread::m_request_stop
private

Referenced by start(), stop(), and stopRequested().

◆ m_retval

void* Thread::m_retval = nullptr
private

Referenced by getReturnValue(), and threadProc().

◆ m_running

std::atomic<bool> Thread::m_running
private

◆ m_start_finished_mutex

std::mutex Thread::m_start_finished_mutex
private

Referenced by ~Thread(), start(), and threadProc().

◆ m_thread_obj

std::thread* Thread::m_thread_obj = nullptr
private

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