OpenTTD Source 20241224-master-gf74b0cf984
thread.h File Reference

Base of all threads. More...

#include "debug.h"
#include "crashlog.h"
#include "error_func.h"
#include <system_error>
#include <thread>
#include <mutex>

Go to the source code of this file.

Functions

void CSleep (int milliseconds)
 Sleep on the current thread for a defined time.
 
void SetCurrentThreadName (const char *name)
 Name the thread this function is called on for the debugger.
 
template<class TFn , class... TArgs>
bool StartNewThread (std::thread *thr, const char *name, TFn &&_Fx, TArgs &&... _Ax)
 Start a new thread.
 

Detailed Description

Base of all threads.

Definition in file thread.h.

Function Documentation

◆ CSleep()

void CSleep ( int  milliseconds)
inline

Sleep on the current thread for a defined time.

Parameters
millisecondsTime to sleep for in milliseconds.

Definition at line 24 of file thread.h.

Referenced by ClientNetworkGameSocketHandler::CloseConnection(), KillWait(), and SetAsyncSaveFinish().

◆ SetCurrentThreadName()

void SetCurrentThreadName ( const char *  name)

Name the thread this function is called on for the debugger.

Parameters
nameName to set for the thread..

Definition at line 245 of file unix.cpp.

Referenced by StartNewThread().

◆ StartNewThread()

template<class TFn , class... TArgs>
bool StartNewThread ( std::thread *  thr,
const char *  name,
TFn &&  _Fx,
TArgs &&...  _Ax 
)
inline

Start a new thread.

Template Parameters
TFnType of the function to call on the thread.
TArgsType of the parameters of the thread function.
Parameters
thrPointer to a thread object; may be nullptr if a detached thread is wanted.
nameName of the thread.
_FxFunction to call on the thread.
_AxArguments for the thread function.
Returns
True if the thread was successfully started, false otherwise.

Definition at line 47 of file thread.h.

References Debug, CrashLog::InitThread(), lock, and SetCurrentThreadName().

Referenced by TCPConnecter::CheckActivity(), DoSave(), NetworkHTTPInitialize(), LinkGraphJob::SpawnThread(), MusicDriver_DMusic::Start(), and VideoDriver::StartGameThread().