ezEngine  Milestone 9
ThreadUtils_win.h
1 #ifdef EZ_THREADUTILS_WIN_INL_H_INCLUDED
2 #error "This file must not be included twice."
3 #endif
4 
5 #define EZ_THREADUTILS_WIN_INL_H_INCLUDED
6 
7 // Windows implementation of thread helper functions
8 
9 static DWORD g_uiMainThreadID = 0xFFFFFFFF;
10 
11 void ezThreadUtils::Initialize()
12 {
13  g_uiMainThreadID = GetCurrentThreadId();
14 }
15 
17 {
18  ::Sleep(0);
19 }
20 
22 {
23  YieldProcessor();
24 }
25 
26 void ezThreadUtils::Sleep(const ezTime& duration)
27 {
28  ::Sleep((DWORD)duration.GetMilliseconds());
29 }
30 
32 {
33  return ::GetCurrentThreadId();
34 }
35 
37 {
38  return GetCurrentThreadID() == g_uiMainThreadID;
39 }
40 
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
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