tlds
Transactional Operations for Linked Data Structures
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
lock.hpp
Go to the documentation of this file.
1
/**
2
* Copyright (C) 2011
3
* University of Rochester Department of Computer Science
4
* and
5
* Lehigh University Department of Computer Science and Engineering
6
*
7
* License: Modified BSD
8
* Please see the file LICENSE.RSTM for licensing information
9
*/
10
11
/* lock.hpp
12
*
13
* Currently uses pthread mutex, with PTHREAD_MUTEX_RECURSIVE for
14
* re-entrancy.
15
*/
16
17
#ifndef LOCK_HPP__
18
#define LOCK_HPP__
19
20
#include <pthread.h>
// for pthread_mutex_t
21
22
#include "
macros.hpp
"
23
24
class
d_lock
{
25
pthread_mutex_t
mutex
;
26
public
:
27
void
acquire
() {
28
VERIFY
(pthread_mutex_lock(&
mutex
));
29
}
30
void
release
() {
31
VERIFY
(pthread_mutex_unlock(&
mutex
));
32
}
33
d_lock
() {
34
pthread_mutexattr_t attrs;
35
VERIFY
(pthread_mutexattr_init(&attrs));
36
VERIFY
(pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE));
37
VERIFY
(pthread_mutex_init(&
mutex
, &attrs));
38
}
39
~d_lock
() {
40
VERIFY
(pthread_mutex_destroy(&
mutex
));
41
}
42
};
43
44
// Declaring one of these makes a scope a critical section.
45
//
46
class
with_lock
{
47
d_lock
*
my_lock
;
48
public
:
49
with_lock
(
d_lock
&
l
) {
50
my_lock
= &
l
;
51
my_lock
->
acquire
();
52
}
53
~with_lock
() {
54
my_lock
->
release
();
55
}
56
};
57
58
#endif // LOCK_HPP__
macros.hpp
VERIFY
#define VERIFY(E)
Definition:
macros.hpp:25
l
Definition:
defs.h:133
d_lock::acquire
void acquire()
Definition:
lock.hpp:27
d_lock
Definition:
lock.hpp:24
with_lock::my_lock
d_lock * my_lock
Definition:
lock.hpp:47
with_lock
Definition:
lock.hpp:46
with_lock::~with_lock
~with_lock()
Definition:
lock.hpp:53
d_lock::release
void release()
Definition:
lock.hpp:30
d_lock::mutex
pthread_mutex_t mutex
Definition:
lock.hpp:25
d_lock::~d_lock
~d_lock()
Definition:
lock.hpp:39
with_lock::with_lock
with_lock(d_lock &l)
Definition:
lock.hpp:49
d_lock::d_lock
d_lock()
Definition:
lock.hpp:33
l
bool set_op int op_size set_t * l
Definition:
stmskip.cc:240
rstm
rstm-dev
mesh
lock.hpp
Generated on Thu Sep 8 2016 13:28:38 for tlds by
1.8.6