SST/macro
thread_lock.h
Go to the documentation of this file.
1 #ifndef THREAD_LOCK_H
2 #define THREAD_LOCK_H
3 
5 #include <pthread.h>
6 
7 #ifdef SSTMAC_PTHREAD_MACRO_H
8 #error sstmacro thread_lock.h should never be used with pthread.h replacement headers
9 #endif
10 
11 namespace sstmac {
12 
14 {
15 
16  public:
18 
20 
21  void lock();
22 
23  void unlock();
24 
25  bool trylock();
26 
27  bool locked() const {
28  return locked_;
29  }
30 
31  private:
33 
34  bool locked_;
35 
36 };
37 
38 #if SSTMAC_USE_SPINLOCK
39 class spin_thread_lock
40 {
41  public:
42  spin_thread_lock();
43 
44  ~spin_thread_lock();
45 
46  void lock();
47 
48  void unlock();
49 
50  bool trylock();
51 
52  bool locked() const {
53  return locked_;
54  }
55 
56  private:
57  pthread_spinlock_t lock_;
58 
59  bool locked_;
60 };
61 #endif
62 
63 #if SSTMAC_USE_SPINLOCK
64 typedef spin_thread_lock thread_lock;
65 #else
67 #endif
68 
69 class lockable {
70  public:
71  void lock(){
72 #if SSTMAC_USE_MULTITHREAD
73  lock_.lock();
74 #endif
75  }
76 
77  void unlock(){
78 #if SSTMAC_USE_MULTITHREAD
79  lock_.unlock();
80 #endif
81  }
82 
83  private:
84 #if SSTMAC_USE_MULTITHREAD
85  thread_lock lock_;
86 #endif
87 };
88 
89 }
90 
91 #endif // THREAD_LOCK_H
mutex_thread_lock thread_lock
Definition: thread_lock.h:66
pthread_mutex_t mutex_
Definition: thread_lock.h:32
#define pthread_mutex_t
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
#define pthread_spinlock_t