SST/macro
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
sstmac
common
thread_lock.h
Go to the documentation of this file.
1
#ifndef THREAD_LOCK_H
2
#define THREAD_LOCK_H
3
4
#include <
sstmac/common/sstmac_config.h
>
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
13
class
mutex_thread_lock
14
{
15
16
public
:
17
mutex_thread_lock
();
18
19
~mutex_thread_lock
();
20
21
void
lock
();
22
23
void
unlock
();
24
25
bool
trylock
();
26
27
bool
locked
()
const
{
28
return
locked_
;
29
}
30
31
private
:
32
pthread_mutex_t
mutex_
;
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
66
typedef
mutex_thread_lock
thread_lock
;
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
sstmac::thread_lock
mutex_thread_lock thread_lock
Definition:
thread_lock.h:66
sstmac::mutex_thread_lock::lock
void lock()
sstmac::mutex_thread_lock
Definition:
thread_lock.h:13
sstmac::mutex_thread_lock::trylock
bool trylock()
pthread.h
sstmac::lockable::lock
void lock()
Definition:
thread_lock.h:71
sstmac::mutex_thread_lock::mutex_
pthread_mutex_t mutex_
Definition:
thread_lock.h:32
sstmac::lockable
Definition:
thread_lock.h:69
sstmac::mutex_thread_lock::unlock
void unlock()
sstmac::mutex_thread_lock::mutex_thread_lock
mutex_thread_lock()
pthread_mutex_t
#define pthread_mutex_t
Definition:
sstmac_pthread_macro.h:136
sstmac
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
Definition:
parallel_runtime.h:18
sstmac::mutex_thread_lock::~mutex_thread_lock
~mutex_thread_lock()
sstmac::mutex_thread_lock::locked
bool locked() const
Definition:
thread_lock.h:27
sstmac::mutex_thread_lock::locked_
bool locked_
Definition:
thread_lock.h:34
sstmac::lockable::unlock
void unlock()
Definition:
thread_lock.h:77
pthread_spinlock_t
#define pthread_spinlock_t
Definition:
sstmac_pthread_macro.h:137
sstmac_config.h
Generated by
1.8.11