Cantera  2.1.2
ct_thread.h
Go to the documentation of this file.
1 /*!
2  * @file ct_thread.h
3  * Header file containing utilities used to ensure thread safety.
4  */
5 
6 #ifndef CT_THREAD_H
7 #define CT_THREAD_H
8 
9 #include "config.h"
10 
11 #ifdef THREAD_SAFE_CANTERA
12 #include <boost/shared_ptr.hpp>
13 #include <boost/thread/mutex.hpp>
14 
15 #endif
16 
17 namespace Cantera
18 {
19 
20 #ifdef THREAD_SAFE_CANTERA
21 
22 #if defined(BOOST_HAS_WINTHREADS)
23 typedef unsigned int cthreadId_t;
24 #elif defined(BOOST_HAS_PTHREADS)
25 typedef pthread_t cthreadId_t;
26 #endif
27 
28 class thread_equal
29 {
30 public:
31  bool operator()(cthreadId_t L, cthreadId_t R) {
32 #if defined(BOOST_HAS_WINTHREADS)
33  return L == R;
34 #elif defined(BOOST_HAS_PTHREADS)
35  return pthread_equal(L, R);
36 #endif
37  }
38 };
39 
40 typedef boost::mutex mutex_t;
41 typedef boost::mutex::scoped_lock ScopedLock;
42 
43 #else
44 typedef int mutex_t;
45 
46 class ScopedLock
47 {
48 public:
49  explicit ScopedLock(const int m) : m_(m) {}
50 private:
51  int m_;
52 };
53 
54 #endif // THREAD_SAFE_CANTERA
55 
56 }
57 
58 #endif