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) {if (mkmut) {mut_ = new pthread_mutex_t; pthread_mutex_init(mut_, 0);}else{mut_ = 0;}}
18 #define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); delete mut_; mut_ = (pthread_mutex_t*)0;}}
19 #else
20 #define MUTCONSTRUCT(mkmut) {if (mkmut) {mut_ = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mut_, 0);}else{mut_ = 0;}}
21 #define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); free(mut_); mut_ = NULL;}}
22 #endif
23 #define MUTLOCK {if (mut_) {pthread_mutex_lock(mut_);}}
24 #define MUTUNLOCK {if (mut_) {pthread_mutex_unlock(mut_);}}
25 /*#define MUTLOCK {if (mut_) {printf("lock %lx\n", mut_); pthread_mutex_lock(mut_);}}*/
26 /*#define MUTUNLOCK {if (mut_) {printf("unlock %lx\n", mut_); pthread_mutex_unlock(mut_);}}*/
27 #else
28 #define MUTDEC /**/
29 #define MUTCONSTRUCTED (0)
30 #define MUTCONSTRUCT(mkmut) /**/
31 #define MUTDESTRUCT /**/
32 #define MUTLOCK /**/
33 #define MUTUNLOCK /**/
34 #endif
35 
36 #endif