X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fmthread%2Fnbody.h;h=9948e5240900449c4b14a0a08dc7961cd95a3007;hb=20979b1c07eda73b7f86b2fe8cb66eb58d959e04;hp=f2de0229ee9c1fbfda57542c8af6aaf3c7d0c493;hpb=47b0dba32b8e0e0deedfbfc6db49b65b930e2889;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/mthread/nbody.h b/course/semester2/pprog/assignment1/mthread/nbody.h index f2de0229..9948e524 100644 --- a/course/semester2/pprog/assignment1/mthread/nbody.h +++ b/course/semester2/pprog/assignment1/mthread/nbody.h @@ -4,13 +4,14 @@ #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 @@ -29,6 +30,8 @@ void AfterDraw(); void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads. + + System * Split_System(System * s, unsigned n); // Splits one system into a number of other systems, returns an array of size n pthread_t * Allocate_Threads(unsigned n); // Allocates space for threads - handles errors @@ -40,33 +43,8 @@ void * Position_Thread(void * system); //Thread - Compute positions for all obje void Thread_Cleanup(void); //Called at program exit to safely join computation thread -/** - * Structure to represent a barrier for multiple threads - * @param mutex - Mutex around the counter - * @param busy - Counter of threads within the barrier - * @param threads_done_cv - Condition to wake up threads waiting on barrier once all working threads have left it - */ -typedef struct -{ - pthread_mutex_t mutex; - unsigned threads_busy; // Counter of threads which are busy - pthread_cond_t threads_done_cv; -} Barrier; - -/** - * Structure to represent a pair of Systems; passed to Force_Thread - * @param A - System to calculate forces for - * @param B - System causing forces on System A - */ -typedef struct -{ - System * A; - System * B; -} System_ForcePair; - -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