Parallel Programming - pthreads version
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
index 0b3208a..5950126 100644 (file)
 
 #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);
 #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.
 
@@ -26,13 +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;
+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

UCC git Repository :: git.ucc.asn.au