ezEngine  Milestone 9
ThreadUtils_posix.h
1 #ifdef EZ_THREADUTILS_POSIX_INL_H_INCLUDED
2 #error "This file must not be included twice."
3 #endif
4 
5 #define EZ_THREADUTILS_POSIX_INL_H_INCLUDED
6 
7 
8 // Posix implementation of thread helper functions
9 
10 #include <pthread.h>
11 
12 static pthread_t g_MainThread = (pthread_t)0;
13 
14 void ezThreadUtils::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 
29 void ezThreadUtils::Sleep(const ezTime& duration)
30 {
31  timespec SleepTime;
32  SleepTime.tv_sec = duration.GetSeconds();
33  SleepTime.tv_nsec = ((ezInt64)duration.GetMilliseconds() * 1000000LL) % 1000000000LL;
34  nanosleep(&SleepTime, nullptr);
35 }
36 
37 // ezThreadHandle ezThreadUtils::GetCurrentThreadHandle()
38 //{
39 // return pthread_self();
40 //}
41 
43 {
44  return pthread_self();
45 }
46 
48 {
49  return pthread_self() == g_MainThread;
50 }
51 
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 Sleep(const ezTime &duration)
Suspends the execution of the current thread for the given amount of time. (Precision may vary accord...
Definition: ThreadUtils_posix.h:29
The time class encapsulates a double value storing the time in seconds.
Definition: Time.h:10
constexpr double GetSeconds() const
Returns the seconds value.
Definition: Time_inl.h:35
static ezThreadID GetCurrentThreadID()
Returns an identifier for the currently running thread.
Definition: ThreadUtils_posix.h:42
constexpr double GetMilliseconds() const
Returns the milliseconds value.
Definition: Time_inl.h:30
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 void YieldTimeSlice()
Suspends execution of the current thread.
Definition: ThreadUtils_posix.h:19