diff --git a/base/include/util/list.h b/base/include/util/list.h index 67321b7102..b044305e31 100644 --- a/base/include/util/list.h +++ b/base/include/util/list.h @@ -34,7 +34,7 @@ namespace Genode { friend class List; - LT *_next; + LT mutable *_next; public: @@ -53,34 +53,44 @@ namespace Genode { * * Start with an empty list. */ - List(): _first(0) { } + List() : _first(0) { } /** * Return first list element */ - LT *first() const { return _first; } + LT *first() { return _first; } + LT const *first() const { return _first; } /** - * Insert element into list + * Insert element after specified element into list + * + * \param le list element to insert + * \param at target position (preceding list element) */ - void insert(LT *le) + void insert(LT const *le, LT const *at = 0) { - le->Element::_next = _first; - _first = le; + /* insert at beginning of the list */ + if (at == 0) { + le->Element::_next = _first; + _first = const_cast(le); + } else { + le->Element::_next = at->Element::_next; + at->Element::_next = const_cast(le); + } } /** * Remove element from list */ - void remove(LT *le) + void remove(LT const *le) { if (!_first) return; /* if specified element is the first of the list */ - if (le == _first) + if (le == _first) { _first = le->Element::_next; - else { + } else { /* search specified element in the list */ Element *e = _first; @@ -119,7 +129,7 @@ namespace Genode { List_element(T *object) : _object(object) { } - T *object() { return _object; } + T *object() const { return _object; } }; } diff --git a/base/src/base/signal/signal.cc b/base/src/base/signal/signal.cc index d6a1ff19c0..0a67d27b8d 100644 --- a/base/src/base/signal/signal.cc +++ b/base/src/base/signal/signal.cc @@ -141,7 +141,7 @@ namespace Genode { Lock::Guard guard(_lock); /* search list for context */ - List_element *le = _list.first(); + List_element const *le = _list.first(); for ( ; le; le = le->next()) { if (context == le->object()) { diff --git a/base/src/test/lifetime/main.cc b/base/src/test/lifetime/main.cc index 31d3293cac..2e8c92e6f7 100644 --- a/base/src/test/lifetime/main.cc +++ b/base/src/test/lifetime/main.cc @@ -32,7 +32,7 @@ void Genode::Volatile_object_base::debug_info() const { /* count number of weak pointers pointing to the object */ weak_ptr_cnt = 0; - for (Weak_ptr_base *curr = _list.first(); curr; curr = curr->next()) + for (Weak_ptr_base const *curr = _list.first(); curr; curr = curr->next()) weak_ptr_cnt++; } diff --git a/gems/src/server/d3m/input_service.h b/gems/src/server/d3m/input_service.h index cd60bc1f21..771455f9ef 100644 --- a/gems/src/server/d3m/input_service.h +++ b/gems/src/server/d3m/input_service.h @@ -157,7 +157,7 @@ namespace Input { * * \return total number of available input events */ - Genode::size_t flush_sources(Event *dst, Genode::size_t dst_max) const + Genode::size_t flush_sources(Event *dst, Genode::size_t dst_max) { Genode::size_t dst_count = 0; diff --git a/libports/src/lib/libc/libc_mmap_registry.h b/libports/src/lib/libc/libc_mmap_registry.h index f7bbe6948d..44cf552000 100644 --- a/libports/src/lib/libc/libc_mmap_registry.h +++ b/libports/src/lib/libc/libc_mmap_registry.h @@ -48,10 +48,12 @@ class Libc::Mmap_registry Genode::Lock mutable _lock; - Entry *_lookup_by_addr_unsynchronized(void * const start) const + /* + * Common for both const and non-const lookup functions + */ + template + static ENTRY *_lookup_by_addr_unsynchronized(ENTRY *curr, void * const start) { - Entry *curr = _list.first(); - for (; curr; curr = curr->next()) if (curr->start == start) return curr; @@ -59,6 +61,16 @@ class Libc::Mmap_registry return 0; } + Entry const *_lookup_by_addr_unsynchronized(void * const start) const + { + return _lookup_by_addr_unsynchronized(_list.first(), start); + } + + Entry *_lookup_by_addr_unsynchronized(void * const start) + { + return _lookup_by_addr_unsynchronized(_list.first(), start); + } + public: void insert(void *start, Genode::size_t len, Plugin *plugin) @@ -77,7 +89,7 @@ class Libc::Mmap_registry { Genode::Lock::Guard guard(_lock); - Entry * const e = _lookup_by_addr_unsynchronized(start); + Entry const * const e = _lookup_by_addr_unsynchronized(start); return e ? e->plugin : 0; } diff --git a/os/src/init/main.cc b/os/src/init/main.cc index 24f1b123fb..1be73402b6 100644 --- a/os/src/init/main.cc +++ b/os/src/init/main.cc @@ -141,7 +141,7 @@ namespace Init { bool is_unique(const char *name) const { - Genode::List_element *curr = first(); + Genode::List_element const *curr = first(); for (; curr; curr = curr->next()) if (curr->object()->has_name(name)) return false; @@ -151,7 +151,7 @@ namespace Init { Genode::Server *lookup_server(const char *name) const { - Genode::List_element *curr = first(); + Genode::List_element const *curr = first(); for (; curr; curr = curr->next()) if (curr->object()->has_name(name)) return curr->object()->server(); diff --git a/os/src/server/ram_fs/directory.h b/os/src/server/ram_fs/directory.h index 5340e0c9d8..50d6d88a86 100644 --- a/os/src/server/ram_fs/directory.h +++ b/os/src/server/ram_fs/directory.h @@ -28,7 +28,7 @@ namespace File_system { bool has_sub_node_unsynchronized(char const *name) const { - Node *sub_node = _entries.first(); + Node const *sub_node = _entries.first(); for (; sub_node; sub_node = sub_node->next()) if (strcmp(sub_node->name(), name) == 0) return true;