forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.h
75 lines (58 loc) · 1.28 KB
/
Thread.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Thread.h
*
*/
#ifndef GC_THREAD_H_
#define GC_THREAD_H_
#include "Networking/Player.h"
#include "Tools/random.h"
#include "Processor.h"
#include "ArgTuples.h"
namespace GC
{
struct ScheduleItem
{
int tape;
int arg;
ScheduleItem(int tape = 0, int arg = 0) : tape(tape), arg(arg) {}
};
template<class T> class ThreadMaster;
template<class T>
class Thread
{
thread_local static Thread* singleton;
static void* run_thread(void* thread);
public:
ThreadMaster<T>& master;
Machine<T>& machine;
Processor<T> processor;
Names& N;
Player* P;
PRNG secure_prng;
int thread_num;
WaitQueue<ScheduleItem> tape_schedule;
WaitQueue<int> done;
pthread_t thread;
static Thread<T>& s();
Thread(int thread_num, ThreadMaster<T>& master);
virtual ~Thread();
void run();
virtual void pre_run() {}
virtual void run(Program& program);
virtual void post_run() {}
void join_tape();
void finish();
};
template<class T>
thread_local Thread<T>* Thread<T>::singleton = 0;
template<class T>
Thread<T>& Thread<T>::s()
{
if (singleton)
return *singleton;
else
throw runtime_error(
"no singleton / not implemented with arithmetic VMs");
}
} /* namespace GC */
#endif /* GC_THREAD_H_ */