SPIDAR API Library  0x16033101
Space Interface Device for Artificial Reality
Thread.cpp
Go to the documentation of this file.
1 
5 #include "Thread.hpp"
6 
7 #define NOMINMAX
8 #include <windows.h>
9 #include <process.h>
10 #include <cstdint>
11 
12 namespace Spidar
13 {
14 namespace Win32
15 {
23 Thread::Thread(FuncType func, ParamType param) : handle_(nullptr), timeOut_(5000), workerFunc_(func), workerParam_(param)
24 {
25  handle_ = reinterpret_cast<HANDLE>(::_beginthreadex(nullptr, 0, threadFunc, this, 0, nullptr));
26 }
27 
33 {
34  join();
35 }
36 
41 void Thread::join(void)
42 {
43  if (!handle_) return;
44 
45  if (::WaitForSingleObject(handle_, timeOut_)!=WAIT_OBJECT_0) return;
46 
47  ::CloseHandle(handle_);
48  handle_ = nullptr;
49 }
50 
56 unsigned __stdcall Thread::threadFunc(void* param)
57 {
58  Thread* thread = static_cast<Thread*>(param);
59 
60  if (thread->workerFunc_) thread->workerFunc_(thread->workerParam_);
61 
62  ::_endthreadex(0);
63  return 0;
64 }
65 
66 } // end of namespace Win32.
67 } // end of namespace Spidar.
68 
69 // end of file.
void join(void)
スレッドの終了を待ちます.
Definition: Thread.cpp:41
Win32APIを用いたスレッドクラスです.
Definition: Thread.hpp:16
SPIDARライブラリのルート名前空間です.
void * ParamType
ワーカー関数のパラメータのポインタの型
Definition: Thread.hpp:20
~Thread(void)
デストラクタです.
Definition: Thread.cpp:32