/* * 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; Names& N; Player* P; PRNG secure_prng; int thread_num; WaitQueue tape_schedule; WaitQueue done; pthread_t thread; static Thread& s(); Thread(int thread_num, ThreadMaster& master); virtual ~Thread(); void start(); void run(); virtual void pre_run() {} virtual void run(Program& program); virtual void post_run() {} void join_tape(); void finish(); virtual NamedCommStats extra_comm() { return {}; } }; template thread_local Thread* Thread::singleton = 0; template Thread& Thread::s() { if (singleton) return *singleton; else throw runtime_error( "no singleton / not implemented with arithmetic VMs"); } } /* namespace GC */ #endif /* GC_THREAD_H_ */