f2eec0dba9985ec5e65b4db30f3d548f296790a7
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
1 #ifndef _NBODY_MTHREAD_H
2 #define _NBODY_MTHREAD_H
3
4
5 #include "../single-thread/nbody.h" //Use original simulation code
6 #include <pthread.h>
7
8 #undef SINGLE_THREADED
9 #define PTHREADED
10
11 #define DEFAULT_WORKING_THREADS 2 
12
13 //Undefine default macros, replace with functions
14 #undef Simulation_Run
15 void Simulation_Run(int argc, char ** argv);
16 #undef QuitProgram
17 void QuitProgram(bool error);
18
19 #undef BeforeDraw
20 void BeforeDraw();
21 #undef AfterDraw
22 void AfterDraw();
23
24
25 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
26
27 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
28 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
29
30
31
32 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
33
34 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread. 
35 extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
36
37 extern pthread_t * worker_thread; //Array of worker threads responsible for Force and Position updates
38 extern System * sub_system; //Array of Systems used to divide up the main "universe" System for worker threads
39 extern pthread_mutex_t mutex_workers;
40 extern pthread_cond_t workers_done_cv;
41 extern unsigned workers_busy;
42
43 extern pthread_mutex_t mutex_graphics; // Mutex for graphics
44 extern pthread_cond_t graphics_cv; //Condition used to start graphics or computation thread from the other
45 extern bool graphics_busy;
46
47 #endif //_NBODY_MTHREAD_H

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