X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fmthread%2Fnbody.h;h=375c2c94871f5a715149010a932dbbaceaeab01c;hb=0217abbb1034188ecbfdf034678cf6867381e561;hp=595012637908739db12a6932b15d94ec56cd7bed;hpb=19d5190c55a836926f2bd646e043fcd6c61ab919;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/mthread/nbody.h b/course/semester2/pprog/assignment1/mthread/nbody.h index 59501263..375c2c94 100644 --- a/course/semester2/pprog/assignment1/mthread/nbody.h +++ b/course/semester2/pprog/assignment1/mthread/nbody.h @@ -4,13 +4,16 @@ #include "../single-thread/nbody.h" //Use original simulation code #include +#include "barrier.h" // Barriers #undef SINGLE_THREADED #define PTHREADED #define DEFAULT_WORKING_THREADS 2 -#define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned +//#define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned + + //Undefine default macros, replace with functions #undef Simulation_Run @@ -26,23 +29,22 @@ void AfterDraw(); void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads. + + + + +pthread_t * Allocate_Threads(unsigned n); // Allocates space for threads - handles errors + +#ifdef PERSISTENT_THREADS +void * Worker_Thread(void * arg); +#endif //PERSISTENT_THREADS void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system +void Thread_Cleanup(void); //Called at program exit to safely join computation thread -void Thread_Cleanup(void); //Called at program exit to safely join computation thread -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); +void * StepFunction(void * s); //Function called at the end of every step #endif //_NBODY_MTHREAD_H