X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fmthread%2Fnbody.h;h=375c2c94871f5a715149010a932dbbaceaeab01c;hb=HEAD;hp=9b76bc75132c92ed04914da958083f7427ee23cc;hpb=c2c6a38870351a5702913ce8a97c25c51662a59c;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/mthread/nbody.h b/course/semester2/pprog/assignment1/mthread/nbody.h index 9b76bc75..375c2c94 100644 --- a/course/semester2/pprog/assignment1/mthread/nbody.h +++ b/course/semester2/pprog/assignment1/mthread/nbody.h @@ -4,35 +4,47 @@ #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 + + + //Undefine default macros, replace with functions #undef Simulation_Run -void Simulation_Run(void); +void Simulation_Run(int argc, char ** argv); #undef QuitProgram void QuitProgram(bool error); +#undef BeforeDraw +void BeforeDraw(); +#undef AfterDraw +void AfterDraw(); + void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker 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 + +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 -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; + +void * StepFunction(void * s); //Function called at the end of every step #endif //_NBODY_MTHREAD_H