VAPoR  0.1
EasyThreads.h
Go to the documentation of this file.
1 
2 #ifndef _EasyThreads_h_
3 #define _EasyThreads_h_
4 
5 #include <vector>
6 
7 #ifndef WIN32
8 #include <pthread.h>
9 #else
10 #include <windows.h>
11 #include <process.h>
12 #endif
13 #include "MyBase.h"
14 
15 namespace VetsUtil {
16 
17 class COMMON_API EasyThreads : public MyBase {
18 
19 public:
20 
21 
22  EasyThreads(int nthreads);
23  ~EasyThreads();
24  int ParRun(void *(*start)(void *), std::vector <void *> arg);
25  int ParRun(void *(*start)(void *), void **arg);
26  int Barrier();
27  int MutexLock();
28  int MutexUnlock();
29  static void Decompose(int n, int size, int rank, int *offset, int *length);
30  static int NProc();
31  int GetNumThreads() const {return(nthreads_c); }
32 
33 private:
34 
35 #ifndef WIN32
36 
37  int nthreads_c;
38  pthread_t *threads_c;
39  pthread_attr_t attr_c;
40  pthread_cond_t cond_c;
41  pthread_mutex_t barrier_lock_c;
42  pthread_mutex_t mutex_lock_c;
43  int block_c;
44  int count_c; // counters for barrier
45 
46 #else
47 
48  bool initialized_c;
49  int nblocked_c;
50  int nthreads_c;
51  HANDLE* threads_c;
52  HANDLE* mutices_c;
53  HANDLE* bMutices_c;
54  HANDLE mutex_c;
55  HANDLE bMutex_c;
56 
57 #endif
58 };
59 
60 };
61 
62 #endif
Definition: Base64.h:6
int GetNumThreads() const
Definition: EasyThreads.h:31
#define COMMON_API
Definition: common.h:60
VetsUtil base class.
Definition: MyBase.h:68