-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathThread.hpp
46 lines (35 loc) · 891 Bytes
/
Thread.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <nstd/Base.hpp>
#include <nstd/Call.hpp>
class Thread
{
public:
Thread();
~Thread();
bool start(uint (*proc)(void*), void* param);
template <class X> bool start(X& obj, uint (X::*ptr)())
{
typename Call<uint>::Member<X>::Func0 func(obj, ptr);
this->func = *(Call<uint>::Member<Thread>::Func0*)&func;
return start((uint (*)(void*))&proc< typename Call<uint>::Member<X>::Func0 >, &this->func);
}
uint join();
static void yield();
static void sleep(int64 milliseconds);
/**
* Get the id of the calling thread.
*
* @return The thread id.
*/
static uint32 getCurrentThreadId();
private:
template <class T> static uint proc(T* t);
void* thread;
Call<uint>::Member<Thread>::Func0 func;
Thread(const Thread&);
Thread& operator=(const Thread&);
};
template <class T> uint Thread::proc(T* t)
{
return t->call();
}