Changeset 30f1a25 in mainline


Ignore:
Timestamp:
2018-03-14T18:54:08Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67f11a0
Parents:
963037b0
Message:

Make hash_table_find_next immune to livelocks

By giving hash_table_find_next the item returned from hash_table_find,
we provide it with a fixed reference with which the outer loop which
calls hash_table_find_next can terminate even if the respective bucket
contains more matching elements.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/hash_table.h

    r963037b0 r30f1a25  
    9595extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *);
    9696extern ht_link_t *hash_table_find(const hash_table_t *, void *);
    97 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *);
     97extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *,
     98    ht_link_t *);
    9899extern size_t hash_table_remove(hash_table_t *, void *);
    99100extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
  • kernel/generic/src/adt/hash_table.c

    r963037b0 r30f1a25  
    269269
    270270/** Find the next item equal to item. */
    271 ht_link_t *hash_table_find_next(const hash_table_t *h, ht_link_t *item)
     271ht_link_t *
     272hash_table_find_next(const hash_table_t *h, ht_link_t *first, ht_link_t *item)
    272273{
    273274        assert(item);
     
    277278
    278279        /* Traverse the circular list until we reach the starting item again. */
    279         for (link_t *cur = item->link.next; cur != &item->link; cur = cur->next) {
     280        for (link_t *cur = item->link.next; cur != &first->link;
     281            cur = cur->next) {
    280282                assert(cur);
    281283
  • kernel/generic/src/ddi/irq.c

    r963037b0 r30f1a25  
    141141{
    142142        irq_spinlock_lock(l, false);
    143         for (ht_link_t *lnk = hash_table_find(h, &inr); lnk;
    144             lnk = hash_table_find_next(h, lnk)) {
     143        ht_link_t *first = hash_table_find(h, &inr);
     144        for (ht_link_t *lnk = first; lnk;
     145            lnk = hash_table_find_next(h, first, lnk)) {
    145146                irq_t *irq = hash_table_get_inst(lnk, irq_t, link);
    146147                irq_spinlock_lock(&irq->lock, false);
  • uspace/lib/c/generic/adt/hash_table.c

    r963037b0 r30f1a25  
    269269
    270270/** Find the next item equal to item. */
    271 ht_link_t *hash_table_find_next(const hash_table_t *h, ht_link_t *item)
     271ht_link_t *
     272hash_table_find_next(const hash_table_t *h, ht_link_t *first, ht_link_t *item)
    272273{
    273274        assert(item);
     
    277278
    278279        /* Traverse the circular list until we reach the starting item again. */
    279         for (link_t *cur = item->link.next; cur != &item->link; cur = cur->next) {
     280        for (link_t *cur = item->link.next; cur != &first->link;
     281            cur = cur->next) {
    280282                assert(cur);
    281283
  • uspace/lib/c/include/adt/hash_table.h

    r963037b0 r30f1a25  
    9595extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *);
    9696extern ht_link_t *hash_table_find(const hash_table_t *, void *);
    97 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *);
     97extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *,
     98    ht_link_t *);
    9899extern size_t hash_table_remove(hash_table_t *, void *);
    99100extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
Note: See TracChangeset for help on using the changeset viewer.