NEURON
nrnmutdec.h
Go to the documentation of this file.
1 #pragma once
2 #if NRN_ENABLE_THREADS
3 
4 #include <memory>
5 #include <mutex>
6 
7 #define MUTDEC std::unique_ptr<std::recursive_mutex> mut_;
8 #define MUTCONSTRUCTED static_cast<bool>(mut_)
9 #define MUTCONSTRUCT(mkmut) \
10  { \
11  if (mkmut) { \
12  mut_ = std::make_unique<std::recursive_mutex>(); \
13  } else { \
14  mut_.reset(); \
15  } \
16  }
17 #define MUTDESTRUCT mut_.reset();
18 #define MUTLOCK \
19  { \
20  if (mut_) { \
21  mut_->lock(); \
22  } \
23  }
24 #define MUTUNLOCK \
25  { \
26  if (mut_) { \
27  mut_->unlock(); \
28  } \
29  }
30 #else
31 #define MUTDEC /**/
32 #define MUTCONSTRUCTED false
33 #define MUTCONSTRUCT(mkmut) /**/
34 #define MUTDESTRUCT /**/
35 #define MUTLOCK /**/
36 #define MUTUNLOCK /**/
37 #endif