MPQC  3.0.0-alpha
mutex.hpp
1 #ifndef MPQC_UTILITY_MUTEX_HPP
2 #define MPQC_UTILITY_MUTEX_HPP
3 
4 #include <boost/thread/mutex.hpp>
5 #include <util/misc/exenv.h>
6 
7 namespace mpqc {
8 
11 
13  template<typename T>
14  struct static_mutex {
15  static const bool debug = false; // change to true
16  static void lock() {
17  if (debug) {
18  std::ostringstream oss;
19  oss << "entered mpqc::static_mutex<>::lock(): count = " << lock_count << std::endl;
20  sc::ExEnv::out0() << oss.str();
21  }
22  get().lock();
23  if (debug) {
24  ++lock_count;
25  std::ostringstream oss;
26  oss << "completed mpqc::static_mutex<>::lock(): count = " << lock_count << std::endl;
27  sc::ExEnv::out0() << oss.str();
28  }
29  }
30  static void unlock() {
31  if (debug) {
32  std::ostringstream oss;
33  oss << "entered mpqc::static_mutex<>::unlock(): count = " << lock_count << std::endl;
34  sc::ExEnv::out0() << oss.str();
35  }
36  get().unlock();
37  if (debug) {
38  std::ostringstream oss;
39  oss << "completed mpqc::static_mutex<>::unlock(): count = " << lock_count << std::endl;
40  sc::ExEnv::out0() << oss.str();
41  }
42  }
43  static boost::mutex& get() {
44  return mutex;
45  }
46 
47  static boost::mutex mutex;
48  static int64_t lock_count;
49  };
50 
51  template<typename T>
52  boost::mutex static_mutex<T>::mutex;
53  template<typename T>
54  int64_t static_mutex<T>::lock_count = int64_t(0);
55 
63  struct mutex {
64  struct global_mutex_tag {};
66  };
67 
69 
70 }
71 
72 #endif // MPQC_UTILITY_MUTEX_HPP
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::mutex
Static mutex instances.
Definition: mutex.hpp:63
mpqc::static_mutex
Static mutex factory.
Definition: mutex.hpp:14
mpqc::mutex::global_mutex_tag
Definition: mutex.hpp:64
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.