EHS
ehs::Thread Class Reference

#include <Thread.h>

Public Member Functions

 ~Thread ()
 Frees any native handles. More...
 
 Thread (const UInt_64 stackSize=0)
 Default members initialization. More...
 
 Thread (const Thread &thread)
 
Threadoperator= (const Thread &thread)
 
void Start (UInt_32(*cb)(void *), void *args)
 
bool Join (const unsigned int timeout=EHS_INFINITE)
 
void Detach ()
 Detaches the referenced thread, removing ownership. More...
 
UInt_64 GetStackSize () const
 
THandle GetHandle () const
 
UInt_32 GetId () const
 
bool IsCurrent () const
 
bool IsValid () const
 

Static Public Member Functions

static UInt_32 GetMainId ()
 Gets the main thread id. More...
 
static UInt_64 GetCurrentId ()
 
static float HardSleepFor (const float seconds)
 
static void SleepFor (const UInt_32 miliseconds)
 

Constructor & Destructor Documentation

◆ ~Thread()

ehs::Thread::~Thread ( )

Frees any native handles.

◆ Thread() [1/2]

ehs::Thread::Thread ( const UInt_64  stackSize = 0)

Default members initialization.

◆ Thread() [2/2]

ehs::Thread::Thread ( const Thread thread)

Copies some members from the given thread object.

Parameters
[in]threadThe thread object to copy from.

Member Function Documentation

◆ Detach()

void ehs::Thread::Detach ( )

Detaches the referenced thread, removing ownership.

◆ GetCurrentId()

UInt_64 ehs::Thread::GetCurrentId ( )
static

Retrieves the calling thread's id.

Returns
The id.

◆ GetHandle()

THandle ehs::Thread::GetHandle ( ) const

Retrieves the native thread handle.

Returns
The native handle.

◆ GetId()

UInt_32 ehs::Thread::GetId ( ) const

Retrieves the thread's id.

Returns
The id.

◆ GetMainId()

UInt_32 ehs::Thread::GetMainId ( )
static

Gets the main thread id.

◆ GetStackSize()

UInt_64 ehs::Thread::GetStackSize ( ) const

Retrieves the given stack size available to the referenced thread.

Returns
The stack size.

◆ HardSleepFor()

float ehs::Thread::HardSleepFor ( const float  seconds)
static

Causes the calling thread to wait until the given time using a while loop and the CPU clock.

Parameters
secondsThe time in seconds to wait for.
Returns
The total elapsed time slept for due to this not being a 100% accurate.
Warning
Use "SleepFor" instead unless accuracy is required because this does not do other tasks while sleeping.

◆ IsCurrent()

bool ehs::Thread::IsCurrent ( ) const

Checks whether or not the calling thread is the referenced thread.

Returns
The result.

◆ IsValid()

bool ehs::Thread::IsValid ( ) const

◆ Join()

bool ehs::Thread::Join ( const unsigned int  timeout = EHS_INFINITE)

Blocks the calling thread until the referenced thread is finished.

Parameters
timeoutThe time to wait for before moving on.
Note
Pass "EHS_INFINITE" to wait until the thread is finished.

◆ operator=()

Thread & ehs::Thread::operator= ( const Thread thread)

Copies some members from the given thread object.

Parameters
[in]threadThe thread object to copy from.
Returns
The thread that has been assigned to.

◆ SleepFor()

void ehs::Thread::SleepFor ( const UInt_32  miliseconds)
static

Causes the calling thread to wait until the given time using native sleep calls.

Parameters
milisecondsThe time in miliseconds to wait for.
Warning
This is not at all accurate.

◆ Start()

void ehs::Thread::Start ( UInt_32(*)(void *)  cb,
void *  args 
)

Creates a thread handle and starts it with the given method.

Parameters
cbThe function to run on the thread.
argsRaw data to send over to the thread.

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