Skip to content

Commit

Permalink
Small updates to util classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbebenita committed Sep 8, 2010
1 parent b03812a commit 5375b39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/rt/util/indexed_list.h
Expand Up @@ -10,6 +10,15 @@ class indexed_list_object {
int32_t list_index;
};

template<typename T>
class indexed_list_element : public indexed_list_object {
public:
T value;
indexed_list_element(T value) : value(value) {
// Nop;
}
};

/**
* An array list of objects that are aware of their position in the list.
* Normally, objects in this list should derive from the base class
Expand Down
16 changes: 15 additions & 1 deletion src/rt/util/synchronized_indexed_list.h
Expand Up @@ -7,7 +7,14 @@ template<typename T> class synchronized_indexed_list :
public indexed_list<T> {
spin_lock _lock;
public:
synchronized_indexed_list(memory_region &region) :
/**
* 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.
}
Expand All @@ -20,6 +27,13 @@ template<typename T> class synchronized_indexed_list :
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();
Expand Down

0 comments on commit 5375b39

Please sign in to comment.