/* * 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 ThreadMaster; template class Thread { thread_local static Thread* singleton; static void* run_thread(void* thread); public: ThreadMaster& master; Machine& machine; Processor processor; typename T::MC* MC; typename T::Protocol* protocol; Names& N; Player* P; PRNG secure_prng; vector os; int thread_num; WaitQueue tape_schedule; WaitQueue done; pthread_t thread; static Thread& s(); Thread(int thread_num, ThreadMaster& master); virtual ~Thread(); virtual typename T::MC* new_mc() { return T::new_mc(machine); } void run(); virtual void pre_run() {} virtual void run(Program& program); virtual void post_run() {} void join_tape(); void finish(); int n_interactive_inputs_from_me(InputArgList& args); }; template thread_local Thread* Thread::singleton = 0; template Thread& Thread::s() { if (singleton) return *singleton; else throw runtime_error("no singleton"); } } /* namespace GC */ #endif /* GC_THREAD_H_ */