Plasma Engine  2.0
Loading...
Searching...
No Matches
ThreadUtils_Posix.h
1#include <Foundation/FoundationInternal.h>
2PL_FOUNDATION_INTERNAL_HEADER
3
4#include <Foundation/Threading/ConditionVariable.h>
5#include <Foundation/Threading/ThreadUtils.h>
6#include <Foundation/Time/Time.h>
7
8// Posix implementation of thread helper functions
9
10#include <pthread.h>
11
12static pthread_t g_MainThread = (pthread_t)0;
13
14void plThreadUtils::Initialize()
15{
16 g_MainThread = pthread_self();
17}
18
20{
21 sched_yield();
22}
23
25{
26 // No equivalent to mm_pause on linux
27}
28
29void plThreadUtils::Sleep(const plTime& duration)
30{
31 timespec SleepTime;
32 SleepTime.tv_sec = duration.GetSeconds();
33 SleepTime.tv_nsec = ((plInt64)duration.GetMilliseconds() * 1000000LL) % 1000000000LL;
34 nanosleep(&SleepTime, nullptr);
35}
36
37// plThreadHandle plThreadUtils::GetCurrentThreadHandle()
38//{
39// return pthread_self();
40//}
41
43{
44 return pthread_self();
45}
46
48{
49 return pthread_self() == g_MainThread;
50}
static void Sleep(const plTime &duration)
Suspends the execution of the current thread for the given amount of time. (Precision may vary accord...
Definition ThreadUtils_Posix.h:29
static void YieldTimeSlice()
Suspends execution of the current thread.
Definition ThreadUtils_Posix.h:19
static bool IsMainThread()
Helper function to check if the current thread is the main thread (e.g. the thread which initialized ...
Definition ThreadUtils_Posix.h:47
static void YieldHardwareThread()
Give resources to other hardware threads on the same processor. Does nothing if the processor has no ...
Definition ThreadUtils_Posix.h:24
static plThreadID GetCurrentThreadID()
Returns an identifier for the currently running thread.
Definition ThreadUtils_Posix.h:42
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
constexpr double GetSeconds() const
Returns the seconds value.
Definition Time_inl.h:30
constexpr double GetMilliseconds() const
Returns the milliseconds value.
Definition Time_inl.h:25