From c894b33088b9c64316b747f05abc5dd0f868f7bf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 24 Nov 2008 02:07:30 +0000 Subject: Use lists instead of ringbuffers for event queue - remove upper limit on event queue size and related warnings on big patch load. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@1776 a436a847-0d15-0410-975c-d299462d15a1 --- raul/List.hpp | 22 ++++++++++++++++++---- raul/ListImpl.hpp | 36 ++++++++++++++++++++++++++++++++++-- wscript | 2 +- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/raul/List.hpp b/raul/List.hpp index 05fdb1e..a3f63a2 100644 --- a/raul/List.hpp +++ b/raul/List.hpp @@ -69,11 +69,17 @@ public: }; - List() : _size(0), _end_iter(this), _const_end_iter(this) { + List(size_t size=0, Node* head=NULL, Node* tail=NULL) + : _size(size) + , _end_iter(this) + , _const_end_iter(this) + { + _head = head; + _tail = tail; _end_iter._listnode = NULL; _const_end_iter._listnode = NULL; } - + ~List(); void push_back(Node* elem); ///< Realtime Safe @@ -106,6 +112,9 @@ public: inline bool operator==(const const_iterator& iter) const; inline bool operator==(const iterator& iter) const; + inline typename List::Node* node() { return _listnode; } + inline const typename List::Node* node() const { return _listnode; } + friend class List; private: @@ -126,7 +135,7 @@ public: inline bool operator!=(const const_iterator& iter) const; inline bool operator==(const iterator& iter) const; inline bool operator==(const const_iterator& iter) const; - + friend class List; friend class List::const_iterator; @@ -135,6 +144,7 @@ public: typename List::Node* _listnode; }; + void chop_front(List& front, size_t front_size, Node* new_head); Node* erase(const iterator iter); @@ -147,6 +157,9 @@ public: T& front() { return *begin(); } const T& front() const { return *begin(); } + Node* head() { return _head.get(); } + const Node* head() const { return _head.get(); } + private: AtomicPtr _head; AtomicPtr _tail; ///< writer only @@ -158,6 +171,7 @@ private: } // namespace Raul +#endif // RAUL_LIST_HPP + #include "ListImpl.hpp" -#endif // RAUL_LIST_HPP diff --git a/raul/ListImpl.hpp b/raul/ListImpl.hpp index ec1fde4..815afcb 100644 --- a/raul/ListImpl.hpp +++ b/raul/ListImpl.hpp @@ -109,7 +109,6 @@ List::push_back(T& elem) * * This operation is fast ( O(1) ). * The appended list is not safe to use concurrently with this call. - * * The appended list will be empty after this call. * * Thread safe (may be called while another thread is reading the list). @@ -123,6 +122,9 @@ List::append(List& list) Node* const my_tail = _tail.get(); Node* const other_head = list._head.get(); Node* const other_tail = list._tail.get(); + + assert((my_head && my_tail) || (!my_head && !my_tail)); + assert((other_head && other_tail) || (!other_head && !other_tail)); // Appending to an empty list if (my_head == NULL && my_tail == NULL) { @@ -178,7 +180,6 @@ List::erase(const iterator iter) Node* const n = iter._listnode; if (n) { - Node* const prev = n->prev(); Node* const next = n->next(); @@ -199,10 +200,41 @@ List::erase(const iterator iter) --_size; } + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); return n; } +template +void +List::chop_front(List& front, size_t front_size, Node* new_head) +{ + assert(new_head != _head.get()); + assert((front._head.get() && front._tail.get()) || (!front._head.get() && !front._tail.get())); + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); + if (!new_head) { + assert(front_size == static_cast(_size.get())); + front._size = _size; + front._head = _head; + front._tail = _tail; + _size = 0; + _head = NULL; + _tail = NULL; + } else { + front._size = front_size; + front._head = _head; + front._tail = new_head->_prev; + if (new_head->prev()) + new_head->prev()->_next = NULL; + _head = new_head; + new_head->_prev = NULL; + _size -= front_size; + } + assert((front._head.get() && front._tail.get()) || (!front._head.get() && !front._tail.get())); + assert((_head.get() && _tail.get()) || (!_head.get() && !_tail.get())); +} + + //// Iterator stuff //// template diff --git a/wscript b/wscript index 1eafdc4..b4cf73a 100644 --- a/wscript +++ b/wscript @@ -51,7 +51,7 @@ def build(bld): src/Symbol.cpp src/Thread.cpp ''' - obj.includes = '.' + obj.includes = ['.','./raul'] obj.name = 'libraul' obj.target = 'raul' obj.uselib = 'GLIBMM GTHREAD' -- cgit v1.2.1