X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fmthread%2Fnbody.h;h=595012637908739db12a6932b15d94ec56cd7bed;hb=19d5190c55a836926f2bd646e043fcd6c61ab919;hp=f2eec0dba9985ec5e65b4db30f3d548f296790a7;hpb=83cf58f62ddc5ce9fe44de27327fde27f767ebb6;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/mthread/nbody.h b/course/semester2/pprog/assignment1/mthread/nbody.h index f2eec0db..59501263 100644 --- a/course/semester2/pprog/assignment1/mthread/nbody.h +++ b/course/semester2/pprog/assignment1/mthread/nbody.h @@ -10,6 +10,8 @@ #define DEFAULT_WORKING_THREADS 2 +#define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned + //Undefine default macros, replace with functions #undef Simulation_Run void Simulation_Run(int argc, char ** argv); @@ -31,17 +33,16 @@ void * Position_Thread(void * system); //Thread - Compute positions for all obje void Thread_Cleanup(void); //Called at program exit to safely join computation thread -extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread. -extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable - -extern pthread_t * worker_thread; //Array of worker threads responsible for Force and Position updates -extern System * sub_system; //Array of Systems used to divide up the main "universe" System for worker threads -extern pthread_mutex_t mutex_workers; -extern pthread_cond_t workers_done_cv; -extern unsigned workers_busy; - -extern pthread_mutex_t mutex_graphics; // Mutex for graphics -extern pthread_cond_t graphics_cv; //Condition used to start graphics or computation thread from the other -extern bool graphics_busy; +typedef struct +{ + pthread_mutex_t mutex; + unsigned threads_busy; // Counter of threads which are busy + pthread_cond_t threads_done_cv; +} Barrier; + +void Barrier_Init(Barrier * b); +void Barrier_Enter(Barrier * b); +void Barrier_Leave(Barrier * b); +void Barrier_Wait(Barrier * b); #endif //_NBODY_MTHREAD_H