1 #ifndef thread_group_header
2 #define thread_group_header
3
4 #include <windows.h>
5
6 struct thread_group;
7
8 //--------------------------------------
9 // Function ptr: Thread_Run
10 // Desc: the function a thread executes.
11 //--------------------------------------
12 typedef void (*Thread_Run)( int thread_index, struct thread_group* thread_group );
13
14 //--------------------------------------
15 // Function ptr: Init
16 // Desc: a initialization function
17 // called once when a thread is created.
18 //--------------------------------------
19 typedef void (*Init)( );
20
21 //--------------------------------------
22 // Struct: thread_group
23 // Desc: represents a group of threads
24 // that perform the same operation.
25 //--------------------------------------
26 typedef struct thread_group
27 {
28 int thread_no;
29
30 DWORD* dwThreadId;
31 HANDLE* hThread;
32 HANDLE* hStartEvents;
33 HANDLE* hStopEvents;
34
35 Thread_Run thread_run;
36 Init init;
37
38 bool end;
39
40 } Thread_Group;
41
42 //--------------------------------------
43 // Function: Thread_Group_Thread
44 // Desc: the main thread function that
45 // calls thread_run when appropriate
46 //--------------------------------------
47 DWORD WINAPI Thread_Group_Thread( LPVOID lpParam );
48
49 //--------------------------------------
50 // Function: Thread_Group_create
51 // Desc: creates a thread_group and the
52 // threads that will run.
53 //--------------------------------------
54 int Thread_Group_create( Thread_Group* thread_group, Thread_Run thread_run, int thread_no );
55
56 //--------------------------------------
57 // Function: Thread_Group_create_init
58 // Desc: creates a thread_group and the
59 // threads that will run and specifies
60 // an initialization function
61 //--------------------------------------
62 int Thread_Group_create_init( Thread_Group* thread_group, Thread_Run thread_run, int thread_no, Init init );
63
64 //--------------------------------------
65 // Function: Thread_Group_execute
66 // Desc: sends an event to all the
67 // threads in the group to execute once.
68 //--------------------------------------
69 void Thread_Group_execute( Thread_Group* thread_group );
70
71 //--------------------------------------
72 // Function: Thread_Group_wait
73 // Desc: waits for all threads in a
74 // group to finish executing.[blocking]
75 //--------------------------------------
76 void Thread_Group_wait( Thread_Group* thread_group );
77
78 //--------------------------------------
79 // Function: Thread_Group_done
80 // Desc: returns true if a threads are
81 // done.[non-blocking]
82 //--------------------------------------
83 bool Thread_Group_done( Thread_Group* thread_group );
84
85 //--------------------------------------
86 // Function: Thread_Group_release
87 // Desc: releases the thread group
88 //--------------------------------------
89 void Thread_Group_release( Thread_Group* thread_group );
90 #endif
syntax highlighted by Code2HTML,
v. 0.9.1