/* * Thread.h * */ #ifndef GC_THREAD_H_ #define GC_THREAD_H_ #include "Networking/Player.h" #include "Tools/random.h" #include "Processor.h" namespace GC { struct ScheduleItem { int tape; int arg; ScheduleItem(int tape = 0, int arg = 0) : tape(tape), arg(arg) {} }; template class Thread { thread_local static Thread* singleton; static void* run_thread(void* thread); public: Machine& machine; Processor processor; typename T::MC MC; 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, Machine& machine, Names& N); virtual ~Thread(); void run(); virtual void pre_run() {} virtual void run(Program& program); virtual void post_run() {} void join_tape(); void finish(); }; 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_ */