-
Notifications
You must be signed in to change notification settings - Fork 0
/
atyp_Threading.h
57 lines (45 loc) · 1.15 KB
/
atyp_Threading.h
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
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include <thread>
template <class D = void>
class Thread{
void (*function)(D*);
D* data;
bool* doneflag;
std::thread thread;
static void RunThread(Thread<D>* thread, D* data){
printf("Running Thread\n");
thread->function(data);
printf("Finished Code\n");
thread->FinishThread();
printf("Finished Thread\n");
}
void StartThread(){
/*thread([](Thread* t, D* data){
t->function(data);
t->FinishThread();
}, this, data);*/
thread = std::thread(&Thread::RunThread, this, data);
//threadref = thread;
}
void FinishThread(){
if(doneflag != nullptr)
*doneflag = true;
}
public:
Thread(void (*threadLogic)(D*), bool& Finished, D* data){
this->data = data;
function = threadLogic;
doneflag = &(Finished = false);
StartThread();
}
Thread(void (*threadLogic)(D*), D* data){
this->data = data;
function = threadLogic;
doneflag = nullptr;
StartThread();
}
~Thread(){
//thread.join();
thread.~thread();
}
};