OpenTTD Source: src/thread.h File Reference

OpenTTD Source 12.2

Functions
thread.h File Reference
`#include "debug.h"`
`#include "crashlog.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. More...
void | SetCurrentThreadName (const char *name)
| Name the thread this function is called on for the debugger. More...
template<class TFn , class... TArgs>
bool | StartNewThread (std::thread *thr, const char *name, TFn &&_Fx, TArgs &&... _Ax)
| Start a new thread. More...

## 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

  milliseconds | Time to sleep for in milliseconds.

Definition at line 23 of file thread.h.

Referenced by ClientNetworkGameSocketHandler::CloseConnection().

## ◆ SetCurrentThreadName()

void SetCurrentThreadName | ( | const char * | name | ) |

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

Parameters

  name | Name to set for the thread..

Definition at line 212 of file os2.cpp.

## ◆ 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

  TFn | Type of the function to call on the thread.
  TArgs | Type of the parameters of the thread function.

Parameters

  thr | Pointer to a thread object; may be `nullptr` if a detached thread is wanted.
  name | Name of the thread.
  _Fx | Function to call on the thread.
  _Ax | Arguments for the thread function.

Returns
  True if the thread was successfully started, false otherwise.

Definition at line 46 of file thread.h.

References lock.

Referenced by TCPConnecter::CheckActivity(), LinkGraphJob::SpawnThread(), and VideoDriver::StartGameThread().