From 00d1465d13980fc3acf650f182ee0723fbda0e06 Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Mon, 19 Jul 2010 14:05:18 -0700 Subject: Added a message passing system based on lock free queues for inter-thread communication. Channels now buffer on the sending side, and no longer require blocking when sending. Lots of other refactoring and bug fixes. --- src/rt/util/array_list.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/rt/util/array_list.h') diff --git a/src/rt/util/array_list.h b/src/rt/util/array_list.h index 0d112575..04fd833f 100644 --- a/src/rt/util/array_list.h +++ b/src/rt/util/array_list.h @@ -13,38 +13,44 @@ public: array_list(); ~array_list(); size_t size(); - void append(T value); + int32_t append(T value); T replace(T old_value, T new_value); - size_t index_of(T value); + int32_t index_of(T value); T & operator[](size_t index); }; -template array_list::array_list() { +template +array_list::array_list() { _capacity = INITIAL_CAPACITY; _data = (T *) malloc(sizeof(T) * _capacity); } -template array_list::~array_list() { +template +array_list::~array_list() { delete _data; } -template size_t array_list::size() { +template size_t +array_list::size() { return _size; } -template void array_list::append(T value) { +template int32_t +array_list::append(T value) { if (_size == _capacity) { _capacity = _capacity * 2; _data = (T *) realloc(_data, _capacity * sizeof(T)); } - _data[_size++] = value; + _data[_size ++] = value; + return _size - 1; } /** * Replaces the old_value in the list with the new_value. * Returns the old_value if the replacement succeeded, or NULL otherwise. */ -template T array_list::replace(T old_value, T new_value) { +template T +array_list::replace(T old_value, T new_value) { int index = index_of(old_value); if (index < 0) { return NULL; @@ -53,7 +59,8 @@ template T array_list::replace(T old_value, T new_value) { return old_value; } -template size_t array_list::index_of(T value) { +template int32_t +array_list::index_of(T value) { for (size_t i = 0; i < _size; i++) { if (_data[i] == value) { return i; @@ -62,7 +69,8 @@ template size_t array_list::index_of(T value) { return -1; } -template T & array_list::operator[](size_t index) { +template T & +array_list::operator[](size_t index) { return _data[index]; } -- cgit v1.2.3