forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thread.hpp
113 lines (94 loc) · 2.17 KB
/
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Thread.cpp
*
*/
#ifndef GC_THREAD_HPP_
#define GC_THREAD_HPP_
#include "Thread.h"
#include "Program.h"
#include "Networking/CryptoPlayer.h"
#include "Processor/Processor.h"
#include "Processor.hpp"
namespace GC
{
template<class T>
void* Thread<T>::run_thread(void* thread)
{
((Thread<T>*)thread)->run();
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
OPENSSL_thread_stop();
#endif
return 0;
}
template<class T>
Thread<T>::Thread(int thread_num, ThreadMaster<T>& master) :
master(master), machine(master.machine), processor(machine),
N(master.N), P(0),
thread_num(thread_num)
{
pthread_create(&thread, 0, run_thread, this);
}
template<class T>
Thread<T>::~Thread()
{
if (P)
delete P;
}
template<class T>
void Thread<T>::run()
{
if (singleton)
throw runtime_error("there can only be one");
singleton = this;
BaseMachine::s().thread_num = thread_num;
secure_prng.ReSeed();
string id = "T" + to_string(thread_num);
if (machine.use_encryption)
P = new CryptoPlayer(N, id);
else
P = new PlainPlayer(N, id);
processor.open_input_file(N.my_num(), thread_num,
master.opts.cmd_private_input_file);
processor.setup_redirection(P->my_num(), thread_num, master.opts,
processor.out);
done.push(0);
pre_run();
ScheduleItem item;
while (tape_schedule.pop_dont_stop(item))
{
processor.reset(machine.progs.at(item.tape), item.arg);
run(machine.progs[item.tape]);
done.push(0);
}
post_run();
}
template<class T>
void Thread<T>::run(Program& program)
{
while (program.execute(processor, master.memory) != DONE_BREAK)
;
}
template<class T>
void Thread<T>::join_tape()
{
int _;
done.pop(_);
}
template<class T>
void Thread<T>::finish()
{
tape_schedule.stop();
pthread_join(thread, 0);
}
} /* namespace GC */
template<class T>
inline int InputArgListBase<T>::n_interactive_inputs_from_me(int my_num)
{
int res = 0;
if (ArithmeticProcessor().use_stdin())
res = n_inputs_from(my_num);
if (res > 0)
cout << "Please enter " << res << " numbers:" << endl;
return res;
}
#endif