blob: a7f79a74fa2f716f000f284f774426524067a0f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#ifndef SYNCHRONIZED_INDEXED_LIST_H
#define SYNCHRONIZED_INDEXED_LIST_H
#include "indexed_list.h"
template<typename T> class synchronized_indexed_list :
public indexed_list<T> {
spin_lock _lock;
public:
/**
* Clients can use this global lock that is associated with the list to
* perform more coarse grained locking. Internally, the synchronized list
* doesn'tactually make any use of this lock.
*/
spin_lock global;
synchronized_indexed_list(memory_region *region) :
indexed_list<T>(region) {
// Nop.
}
int32_t append(T *value) {
int32_t index = 0;
_lock.lock();
index = indexed_list<T>::append(value);
_lock.unlock();
return index;
}
bool pop(T **value) {
_lock.lock();
bool result = indexed_list<T>::pop(value);
_lock.unlock();
return result;
}
size_t length() {
size_t length = 0;
_lock.lock();
length = indexed_list<T>::length();
_lock.unlock();
return length;
}
bool is_empty() {
bool empty = false;
_lock.lock();
empty = indexed_list<T>::is_empty();
_lock.unlock();
return empty;
}
int32_t remove(T* value) {
size_t index = 0;
_lock.lock();
index = indexed_list<T>::remove(value);
_lock.unlock();
return index;
}
T *operator[](size_t index) {
T *value = NULL;
_lock.lock();
value = indexed_list<T>::operator[](index);
_lock.unlock();
return value;
}
};
#endif /* SYNCHRONIZED_INDEXED_LIST_H */
|