/* * 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 void* Thread::run_thread(void* thread) { ((Thread*)thread)->run(); #if OPENSSL_VERSION_NUMBER >= 0x10100000L OPENSSL_thread_stop(); #endif return 0; } template Thread::Thread(int thread_num, ThreadMaster& master) : master(master), machine(master.machine), processor(machine), N(master.N), P(0), thread_num(thread_num), thread(0) { } template void Thread::start() { pthread_create(&thread, 0, run_thread, this); } template Thread::~Thread() { if (P) delete P; } template void Thread::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 void Thread::run(Program& program) { while (program.execute(processor, master.memory) != DONE_BREAK) ; } template void Thread::join_tape() { int _; done.pop(_); } template void Thread::finish() { tape_schedule.stop(); pthread_join(thread, 0); } } /* namespace GC */ template inline int InputArgListBase::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