NEURON
nrnmutdec.h
Go to the documentation of this file.
1 #ifndef nrnmutdec_h
2 #define nrnmutdec_h
3 
4 #include <nrnpthread.h>
5 #if USE_PTHREAD
6 
7 #include <pthread.h>
8 
9 #ifdef MINGW
10 #undef DELETE
11 #undef near
12 #endif
13 
14 #define MUTDEC pthread_mutex_t* mut_;
15 #define MUTCONSTRUCTED (mut_ != (pthread_mutex_t*) 0)
16 #if defined(__cplusplus)
17 #define MUTCONSTRUCT(mkmut) \
18  { \
19  if (mkmut) { \
20  mut_ = new pthread_mutex_t; \
21  pthread_mutex_init(mut_, 0); \
22  } else { \
23  mut_ = 0; \
24  } \
25  }
26 #define MUTDESTRUCT \
27  { \
28  if (mut_) { \
29  pthread_mutex_destroy(mut_); \
30  delete mut_; \
31  mut_ = (pthread_mutex_t*) 0; \
32  } \
33  }
34 #else
35 #define MUTCONSTRUCT(mkmut) \
36  { \
37  if (mkmut) { \
38  mut_ = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); \
39  pthread_mutex_init(mut_, 0); \
40  } else { \
41  mut_ = 0; \
42  } \
43  }
44 #define MUTDESTRUCT \
45  { \
46  if (mut_) { \
47  pthread_mutex_destroy(mut_); \
48  free(mut_); \
49  mut_ = NULL; \
50  } \
51  }
52 #endif
53 #define MUTLOCK \
54  { \
55  if (mut_) { \
56  pthread_mutex_lock(mut_); \
57  } \
58  }
59 #define MUTUNLOCK \
60  { \
61  if (mut_) { \
62  pthread_mutex_unlock(mut_); \
63  } \
64  }
65 /*#define MUTLOCK {if (mut_) {printf("lock %lx\n", mut_); pthread_mutex_lock(mut_);}}*/
66 /*#define MUTUNLOCK {if (mut_) {printf("unlock %lx\n", mut_); pthread_mutex_unlock(mut_);}}*/
67 #else
68 #define MUTDEC /**/
69 #define MUTCONSTRUCTED (0)
70 #define MUTCONSTRUCT(mkmut) /**/
71 #define MUTDESTRUCT /**/
72 #define MUTLOCK /**/
73 #define MUTUNLOCK /**/
74 #endif
75 
76 #endif