20 #include <mach/mach.h> 26 enum class ThreadPriority
47 explicit CThread(
const char* ThreadName);
52 void Create(
bool bAutoDelete =
false);
54 template<
typename Rep,
typename Period>
55 void Sleep(std::chrono::duration<Rep, Period> duration)
57 if (duration > std::chrono::milliseconds(10) && IsCurrentThread())
58 m_StopEvent.Wait(duration);
60 std::this_thread::sleep_for(duration);
63 bool IsAutoDelete()
const;
64 virtual void StopThread(
bool bWait =
true);
65 bool IsRunning()
const;
67 bool IsCurrentThread()
const;
68 bool Join(std::chrono::milliseconds duration);
70 inline static const std::thread::id GetCurrentThreadId()
72 return std::this_thread::get_id();
80 bool SetPriority(
const ThreadPriority& priority);
82 static CThread* GetCurrentThread();
84 virtual void OnException(){}
87 virtual void OnStartup() {}
88 virtual void OnExit() {}
89 virtual void Process();
91 std::atomic<bool> m_bStop;
93 enum WaitResponse { WAIT_INTERRUPTED = -1, WAIT_SIGNALED = 0, WAIT_TIMEDOUT = 1 };
101 std::chrono::milliseconds duration =
102 std::chrono::milliseconds(-1) )
106 duration < std::chrono::milliseconds::zero() ?
group.wait() :
group.wait(duration);
107 return result == &
event ? WAIT_SIGNALED :
108 (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED);
114 bool m_bAutoDelete =
false;
117 CCriticalSection m_CriticalSection;
120 std::string m_ThreadName;
121 std::thread* m_thread =
nullptr;
122 std::future<bool> m_future;
124 std::unique_ptr<IThreadImpl> m_impl;
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
WaitResponse AbortableWait(CEvent &event, std::chrono::milliseconds duration=std::chrono::milliseconds(-1))
This call will wait on a CEvent in an interruptible way such that if stop is called on the thread the...
Definition: Thread.h:100
CEventGroup is a means of grouping CEvents to wait on them together.
Definition: Event.h:138
Definition: IThreadImpl.h:17
Definition: IRunnable.h:11
Definition: SmartPlayList.cpp:137