Changeset 9f4067b6 in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2012-10-09T21:16:13Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6659037, 7d248e3
Parents:
d1ef4a1 (diff), 97b199b1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/gsoc2012-uspace-hash-table-from-adam.

Location:
uspace/lib/c/generic
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/hash_table.c

    rd1ef4a1 r9f4067b6  
    11/*
    22 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2012 Adam Hraska
     4 *
    35 * All rights reserved.
    46 *
     
    3436
    3537/*
    36  * This is an implementation of generic chained hash table.
     38 * This is an implementation of a generic resizable chained hash table.
     39 *
     40 * The table grows to 2*n+1 buckets each time, starting at n == 89,
     41 * per Thomas Wang's recommendation:
     42 * http://www.concentric.net/~Ttwang/tech/hashsize.htm
     43 *
     44 * This policy produces prime table sizes for the first five resizes
     45 * and generally produces table sizes which are either prime or
     46 * have fairly large (prime/odd) divisors. Having a prime table size
     47 * mitigates the use of suboptimal hash functions and distributes
     48 * items over the whole table.
    3749 */
    3850
     
    4456#include <str.h>
    4557
     58/* Optimal initial bucket count. See comment above. */
     59#define HT_MIN_BUCKETS  89
     60/* The table is resized when the average load per bucket exceeds this number. */
     61#define HT_MAX_LOAD     2
     62
     63
     64static size_t round_up_size(size_t);
     65static bool alloc_table(size_t, list_t **);
     66static void clear_items(hash_table_t *);
     67static void resize(hash_table_t *, size_t);
     68static void grow_if_needed(hash_table_t *);
     69static void shrink_if_needed(hash_table_t *);
     70
     71/* Dummy do nothing callback to invoke in place of remove_callback == NULL. */
     72static void nop_remove_callback(ht_link_t *item)
     73{
     74        /* no-op */
     75}
     76
     77
    4678/** Create chained hash table.
    4779 *
    4880 * @param h        Hash table structure. Will be initialized by this call.
    49  * @param m        Number of hash table buckets.
     81 * @param init_size Initial desired number of hash table buckets. Pass zero
     82 *                 if you want the default initial size.
    5083 * @param max_keys Maximal number of keys needed to identify an item.
    51  * @param op       Hash table operations structure.
     84 * @param op       Hash table operations structure. remove_callback()
     85 *                 is optional and can be NULL if no action is to be taken
     86 *                 upon removal. equal() is optional if and only if
     87 *                 hash_table_insert_unique() will never be invoked.
     88 *                 All other operations are mandatory.
    5289 *
    5390 * @return True on success
    5491 *
    5592 */
    56 bool hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
    57     hash_table_operations_t *op)
     93bool hash_table_create(hash_table_t *h, size_t init_size, size_t max_load,
     94    hash_table_ops_t *op)
    5895{
    5996        assert(h);
    60         assert(op && op->hash && op->compare);
    61         assert(max_keys > 0);
    62        
    63         h->entry = malloc(m * sizeof(list_t));
    64         if (!h->entry)
     97        assert(op && op->hash && op->key_hash && op->key_equal);
     98       
     99        /* Check for compulsory ops. */
     100        if (!op || !op->hash || !op->key_hash || !op->key_equal)
    65101                return false;
    66102       
    67         memset((void *) h->entry, 0,  m * sizeof(list_t));
    68        
    69         hash_count_t i;
    70         for (i = 0; i < m; i++)
    71                 list_initialize(&h->entry[i]);
    72        
    73         h->entries = m;
    74         h->max_keys = max_keys;
     103        h->bucket_cnt = round_up_size(init_size);
     104       
     105        if (!alloc_table(h->bucket_cnt, &h->bucket))
     106                return false;
     107       
     108        h->max_load = (max_load == 0) ? HT_MAX_LOAD : max_load;
     109        h->item_cnt = 0;
    75110        h->op = op;
     111        h->full_item_cnt = h->max_load * h->bucket_cnt;
     112        h->apply_ongoing = false;
     113
     114        if (h->op->remove_callback == NULL) {
     115                h->op->remove_callback = nop_remove_callback;
     116        }
    76117       
    77118        return true;
    78119}
    79120
     121/** Destroy a hash table instance.
     122 *
     123 * @param h Hash table to be destroyed.
     124 *
     125 */
     126void hash_table_destroy(hash_table_t *h)
     127{
     128        assert(h && h->bucket);
     129        assert(!h->apply_ongoing);
     130       
     131        clear_items(h);
     132       
     133        free(h->bucket);
     134
     135        h->bucket = 0;
     136        h->bucket_cnt = 0;
     137}
     138
     139/** Returns true if there are no items in the table. */
     140bool hash_table_empty(hash_table_t *h)
     141{
     142        assert(h && h->bucket);
     143        return h->item_cnt == 0;
     144}
     145
     146/** Returns the number of items in the table. */
     147size_t hash_table_size(hash_table_t *h)
     148{
     149        assert(h && h->bucket);
     150        return h->item_cnt;
     151}
     152
    80153/** Remove all elements from the hash table
    81154 *
     
    84157void hash_table_clear(hash_table_t *h)
    85158{
    86         for (hash_count_t chain = 0; chain < h->entries; ++chain) {
    87                 link_t *cur;
    88                 link_t *next;
    89                
    90                 for (cur = h->entry[chain].head.next;
    91                     cur != &h->entry[chain].head;
    92                     cur = next) {
    93                         next = cur->next;
     159        assert(h && h->bucket);
     160        assert(!h->apply_ongoing);
     161       
     162        clear_items(h);
     163       
     164        /* Shrink the table to its minimum size if possible. */
     165        if (HT_MIN_BUCKETS < h->bucket_cnt) {
     166                resize(h, HT_MIN_BUCKETS);
     167        }
     168}
     169
     170/** Unlinks and removes all items but does not resize. */
     171static void clear_items(hash_table_t *h)
     172{
     173        if (h->item_cnt == 0)
     174                return;
     175       
     176        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
     177                list_foreach_safe(h->bucket[idx], cur, next) {
     178                        assert(cur);
     179                        ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     180                       
    94181                        list_remove(cur);
    95                         h->op->remove_callback(cur);
    96                 }
    97         }
    98 }
    99 
    100 /** Destroy a hash table instance.
    101  *
    102  * @param h Hash table to be destroyed.
    103  *
    104  */
    105 void hash_table_destroy(hash_table_t *h)
    106 {
    107         assert(h);
    108         assert(h->entry);
    109        
    110         free(h->entry);
     182                        h->op->remove_callback(cur_link);
     183                }
     184        }
     185       
     186        h->item_cnt = 0;
    111187}
    112188
     
    117193 * @param item Item to be inserted into the hash table.
    118194 */
    119 void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item)
     195void hash_table_insert(hash_table_t *h, ht_link_t *item)
    120196{
    121197        assert(item);
    122         assert(h && h->op && h->op->hash && h->op->compare);
    123        
    124         hash_index_t chain = h->op->hash(key);
    125         assert(chain < h->entries);
    126        
    127         list_append(item, &h->entry[chain]);
     198        assert(h && h->bucket);
     199        assert(!h->apply_ongoing);
     200       
     201        size_t idx = h->op->hash(item) % h->bucket_cnt;
     202       
     203        list_append(&item->link, &h->bucket[idx]);
     204        ++h->item_cnt;
     205        grow_if_needed(h);
     206}
     207
     208
     209/** Insert item into a hash table if not already present.
     210 *
     211 * @param h    Hash table.
     212 * @param key  Array of all keys necessary to compute hash index.
     213 * @param item Item to be inserted into the hash table.
     214 *
     215 * @return False if such an item had already been inserted.
     216 * @return True if the inserted item was the only item with such a lookup key.
     217 */
     218bool hash_table_insert_unique(hash_table_t *h, ht_link_t *item)
     219{
     220        assert(item);
     221        assert(h && h->bucket && h->bucket_cnt);
     222        assert(h->op && h->op->hash && h->op->equal);
     223        assert(!h->apply_ongoing);
     224       
     225        size_t idx = h->op->hash(item) % h->bucket_cnt;
     226       
     227        /* Check for duplicates. */
     228        list_foreach(h->bucket[idx], cur) {
     229                /*
     230                 * We could filter out items using their hashes first, but
     231                 * calling equal() might very well be just as fast.
     232                 */
     233                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     234                if (h->op->equal(cur_link, item))
     235                        return false;
     236        }
     237       
     238        list_append(&item->link, &h->bucket[idx]);
     239        ++h->item_cnt;
     240        grow_if_needed(h);
     241       
     242        return true;
    128243}
    129244
     
    136251 *
    137252 */
    138 link_t *hash_table_find(hash_table_t *h, unsigned long key[])
    139 {
    140         assert(h && h->op && h->op->hash && h->op->compare);
    141        
    142         hash_index_t chain = h->op->hash(key);
    143         assert(chain < h->entries);
    144        
    145         list_foreach(h->entry[chain], cur) {
    146                 if (h->op->compare(key, h->max_keys, cur)) {
    147                         /*
    148                          * The entry is there.
    149                          */
    150                         return cur;
    151                 }
    152         }
    153        
     253ht_link_t *hash_table_find(const hash_table_t *h, void *key)
     254{
     255        assert(h && h->bucket);
     256       
     257        size_t idx = h->op->key_hash(key) % h->bucket_cnt;
     258
     259        list_foreach(h->bucket[idx], cur) {
     260                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     261                /*
     262                 * Is this is the item we are looking for? We could have first
     263                 * checked if the hashes match but op->key_equal() may very well be
     264                 * just as fast as op->hash().
     265                 */
     266                if (h->op->key_equal(key, cur_link)) {
     267                        return cur_link;
     268                }
     269        }
     270       
     271        return NULL;
     272}
     273
     274/** Find the next item equal to item. */
     275ht_link_t *hash_table_find_next(const hash_table_t *h, ht_link_t *item)
     276{
     277        assert(item);
     278        assert(h && h->bucket);
     279
     280        /* Traverse the circular list until we reach the starting item again. */
     281        for (link_t *cur = item->link.next; cur != &item->link; cur = cur->next) {
     282                assert(cur);
     283                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     284                /*
     285                 * Is this is the item we are looking for? We could have first
     286                 * checked if the hashes match but op->equal() may very well be
     287                 * just as fast as op->hash().
     288                 */
     289                if (h->op->equal(cur_link, item)) {
     290                        return cur_link;
     291                }
     292        }
     293
    154294        return NULL;
    155295}
     
    163303 *             the hash table.
    164304 * @param keys Number of keys in the 'key' array.
    165  *
    166  */
    167 void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys)
    168 {
    169         assert(h && h->op && h->op->hash && h->op->compare &&
    170             h->op->remove_callback);
    171         assert(keys <= h->max_keys);
    172        
    173         if (keys == h->max_keys) {
    174                 /*
    175                  * All keys are known, hash_table_find() can be used to find the
    176                  * entry.
     305 *
     306 * @return Returns the number of removed items.
     307 */
     308size_t hash_table_remove(hash_table_t *h, void *key)
     309{
     310        assert(h && h->bucket);
     311        assert(!h->apply_ongoing);
     312       
     313        size_t idx = h->op->key_hash(key) % h->bucket_cnt;
     314
     315        size_t removed = 0;
     316       
     317        list_foreach_safe(h->bucket[idx], cur, next) {
     318                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     319               
     320                if (h->op->key_equal(key, cur_link)) {
     321                        ++removed;
     322                        list_remove(cur);
     323                        h->op->remove_callback(cur_link);
     324                }
     325        }
     326
     327        h->item_cnt -= removed;
     328        shrink_if_needed(h);
     329       
     330        return removed;
     331}
     332
     333/** Removes an item already present in the table. The item must be in the table.*/
     334void hash_table_remove_item(hash_table_t *h, ht_link_t *item)
     335{
     336        assert(item);
     337        assert(h && h->bucket);
     338        assert(link_in_use(&item->link));
     339
     340        list_remove(&item->link);
     341        --h->item_cnt;
     342        h->op->remove_callback(item);
     343        shrink_if_needed(h);
     344}
     345
     346/** Apply function to all items in hash table.
     347 *
     348 * @param h   Hash table.
     349 * @param f   Function to be applied. Return false if no more items
     350 *            should be visited. The functor may only delete the supplied
     351 *            item. It must not delete the successor of the item passed
     352 *            in the first argument.
     353 * @param arg Argument to be passed to the function.
     354 */
     355void hash_table_apply(hash_table_t *h, bool (*f)(ht_link_t *, void *), void *arg)
     356{       
     357        assert(f);
     358        assert(h && h->bucket);
     359       
     360        if (h->item_cnt == 0)
     361                return;
     362       
     363        h->apply_ongoing = true;
     364       
     365        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
     366                list_foreach_safe(h->bucket[idx], cur, next) {
     367                        ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     368                        /*
     369                         * The next pointer had already been saved. f() may safely
     370                         * delete cur (but not next!).
     371                         */
     372                        if (!f(cur_link, arg))
     373                                return;
     374                }
     375        }
     376       
     377        h->apply_ongoing = false;
     378       
     379        shrink_if_needed(h);
     380        grow_if_needed(h);
     381}
     382
     383/** Rounds up size to the nearest suitable table size. */
     384static size_t round_up_size(size_t size)
     385{
     386        size_t rounded_size = HT_MIN_BUCKETS;
     387       
     388        while (rounded_size < size) {
     389                rounded_size = 2 * rounded_size + 1;
     390        }
     391       
     392        return rounded_size;
     393}
     394
     395/** Allocates and initializes the desired number of buckets. True if successful.*/
     396static bool alloc_table(size_t bucket_cnt, list_t **pbuckets)
     397{
     398        assert(pbuckets && HT_MIN_BUCKETS <= bucket_cnt);
     399               
     400        list_t *buckets = malloc(bucket_cnt * sizeof(list_t));
     401        if (!buckets)
     402                return false;
     403       
     404        for (size_t i = 0; i < bucket_cnt; i++)
     405                list_initialize(&buckets[i]);
     406
     407        *pbuckets = buckets;
     408        return true;
     409}
     410
     411
     412/** Shrinks the table if the table is only sparely populated. */
     413static inline void shrink_if_needed(hash_table_t *h)
     414{
     415        if (h->item_cnt <= h->full_item_cnt / 4 && HT_MIN_BUCKETS < h->bucket_cnt) {
     416                /*
     417                 * Keep the bucket_cnt odd (possibly also prime).
     418                 * Shrink from 2n + 1 to n. Integer division discards the +1.
    177419                 */
    178                
    179                 link_t *cur = hash_table_find(h, key);
    180                 if (cur) {
    181                         list_remove(cur);
    182                         h->op->remove_callback(cur);
    183                 }
    184                
     420                size_t new_bucket_cnt = h->bucket_cnt / 2;
     421                resize(h, new_bucket_cnt);
     422        }
     423}
     424
     425/** Grows the table if table load exceeds the maximum allowed. */
     426static inline void grow_if_needed(hash_table_t *h)
     427{
     428        /* Grow the table if the average bucket load exceeds the maximum. */
     429        if (h->full_item_cnt < h->item_cnt) {
     430                /* Keep the bucket_cnt odd (possibly also prime). */
     431                size_t new_bucket_cnt = 2 * h->bucket_cnt + 1;
     432                resize(h, new_bucket_cnt);
     433        }
     434}
     435
     436/** Allocates and rehashes items to a new table. Frees the old table. */
     437static void resize(hash_table_t *h, size_t new_bucket_cnt)
     438{
     439        assert(h && h->bucket);
     440        assert(HT_MIN_BUCKETS <= new_bucket_cnt);
     441       
     442        /* We are traversing the table and resizing would mess up the buckets. */
     443        if (h->apply_ongoing)
    185444                return;
    186         }
    187        
    188         /*
    189          * Fewer keys were passed.
    190          * Any partially matching entries are to be removed.
    191          */
    192         hash_index_t chain;
    193         for (chain = 0; chain < h->entries; chain++) {
    194                 for (link_t *cur = h->entry[chain].head.next;
    195                     cur != &h->entry[chain].head;
    196                     cur = cur->next) {
    197                         if (h->op->compare(key, keys, cur)) {
    198                                 link_t *hlp;
    199                                
    200                                 hlp = cur;
    201                                 cur = cur->prev;
    202                                
    203                                 list_remove(hlp);
    204                                 h->op->remove_callback(hlp);
    205                                
    206                                 continue;
     445       
     446        list_t *new_buckets;
     447
     448        /* Leave the table as is if we cannot resize. */
     449        if (!alloc_table(new_bucket_cnt, &new_buckets))
     450                return;
     451       
     452        if (0 < h->item_cnt) {
     453                /* Rehash all the items to the new table. */
     454                for (size_t old_idx = 0; old_idx < h->bucket_cnt; ++old_idx) {
     455                        list_foreach_safe(h->bucket[old_idx], cur, next) {
     456                                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     457
     458                                size_t new_idx = h->op->hash(cur_link) % new_bucket_cnt;
     459                                list_remove(cur);
     460                                list_append(cur, &new_buckets[new_idx]);
    207461                        }
    208462                }
    209463        }
    210 }
    211 
    212 /** Apply function to all items in hash table.
    213  *
    214  * @param h   Hash table.
    215  * @param f   Function to be applied.
    216  * @param arg Argument to be passed to the function.
    217  *
    218  */
    219 void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
    220 {       
    221         for (hash_index_t bucket = 0; bucket < h->entries; bucket++) {
    222                 link_t *cur;
    223                 link_t *next;
    224 
    225                 for (cur = h->entry[bucket].head.next; cur != &h->entry[bucket].head;
    226                     cur = next) {
    227                         /*
    228                          * The next pointer must be stored prior to the functor
    229                          * call to allow using destructor as the functor (the
    230                          * free function could overwrite the cur->next pointer).
    231                          */
    232                         next = cur->next;
    233                         f(cur, arg);
    234                 }
    235         }
    236 }
     464       
     465        free(h->bucket);
     466        h->bucket = new_buckets;
     467        h->bucket_cnt = new_bucket_cnt;
     468        h->full_item_cnt = h->max_load * h->bucket_cnt;
     469}
     470
    237471
    238472/** @}
  • uspace/lib/c/generic/async.c

    rd1ef4a1 r9f4067b6  
    116116#include "private/libc.h"
    117117
    118 #define CLIENT_HASH_TABLE_BUCKETS  32
    119 #define CONN_HASH_TABLE_BUCKETS    32
    120118
    121119/** Session data */
     
    205203/* Client connection data */
    206204typedef struct {
    207         link_t link;
     205        ht_link_t link;
    208206       
    209207        task_id_t in_task_id;
     
    217215       
    218216        /** Hash table link. */
    219         link_t link;
     217        ht_link_t link;
    220218       
    221219        /** Incoming client task ID. */
     
    393391static LIST_INITIALIZE(timeout_list);
    394392
    395 static hash_index_t client_hash(unsigned long key[])
    396 {
    397         assert(key);
    398        
    399         return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    400 }
    401 
    402 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    403 {
    404         assert(key);
    405         assert(keys == 2);
    406         assert(item);
    407        
    408         client_t *client = hash_table_get_instance(item, client_t, link);
    409         return (key[0] == LOWER32(client->in_task_id) &&
    410             (key[1] == UPPER32(client->in_task_id)));
    411 }
    412 
    413 static void client_remove(link_t *item)
    414 {
    415 }
     393static size_t client_key_hash(void *k)
     394{
     395        task_id_t key = *(task_id_t*)k;
     396        return key;
     397}
     398
     399static size_t client_hash(const ht_link_t *item)
     400{
     401        client_t *client = hash_table_get_inst(item, client_t, link);
     402        return client_key_hash(&client->in_task_id);
     403}
     404
     405static bool client_key_equal(void *k, const ht_link_t *item)
     406{
     407        task_id_t key = *(task_id_t*)k;
     408        client_t *client = hash_table_get_inst(item, client_t, link);
     409        return key == client->in_task_id;
     410}
     411
    416412
    417413/** Operations for the client hash table. */
    418 static hash_table_operations_t client_hash_table_ops = {
     414static hash_table_ops_t client_hash_table_ops = {
    419415        .hash = client_hash,
    420         .compare = client_compare,
    421         .remove_callback = client_remove
     416        .key_hash = client_key_hash,
     417        .key_equal = client_key_equal,
     418        .equal = NULL,
     419        .remove_callback = NULL
    422420};
    423421
     
    429427 *
    430428 */
    431 static hash_index_t conn_hash(unsigned long key[])
    432 {
    433         assert(key);
    434        
    435         return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
    436 }
    437 
    438 /** Compare hash table item with a key.
    439  *
    440  * @param key  Array containing the source phone hash as the only item.
    441  * @param keys Expected 1 but ignored.
    442  * @param item Connection hash table item.
    443  *
    444  * @return True on match, false otherwise.
    445  *
    446  */
    447 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    448 {
    449         assert(key);
    450         assert(item);
    451        
    452         connection_t *conn = hash_table_get_instance(item, connection_t, link);
    453         return (key[0] == conn->in_phone_hash);
    454 }
    455 
    456 static void conn_remove(link_t *item)
    457 {
    458 }
     429static size_t conn_key_hash(void *key)
     430{
     431        sysarg_t in_phone_hash  = *(sysarg_t*)key;
     432        return in_phone_hash ;
     433}
     434
     435static size_t conn_hash(const ht_link_t *item)
     436{
     437        connection_t *conn = hash_table_get_inst(item, connection_t, link);
     438        return conn_key_hash(&conn->in_phone_hash);
     439}
     440
     441static bool conn_key_equal(void *key, const ht_link_t *item)
     442{
     443        sysarg_t in_phone_hash = *(sysarg_t*)key;
     444        connection_t *conn = hash_table_get_inst(item, connection_t, link);
     445        return (in_phone_hash == conn->in_phone_hash);
     446}
     447
    459448
    460449/** Operations for the connection hash table. */
    461 static hash_table_operations_t conn_hash_table_ops = {
     450static hash_table_ops_t conn_hash_table_ops = {
    462451        .hash = conn_hash,
    463         .compare = conn_compare,
    464         .remove_callback = conn_remove
     452        .key_hash = conn_key_hash,
     453        .key_equal = conn_key_equal,
     454        .equal = NULL,
     455        .remove_callback = NULL
    465456};
    466457
     
    510501        futex_down(&async_futex);
    511502       
    512         unsigned long key = call->in_phone_hash;
    513         link_t *hlp = hash_table_find(&conn_hash_table, &key);
     503        ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash);
    514504       
    515505        if (!hlp) {
     
    518508        }
    519509       
    520         connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
     510        connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
    521511       
    522512        msg_t *msg = malloc(sizeof(*msg));
     
    698688static client_t *async_client_get(task_id_t client_id, bool create)
    699689{
    700         unsigned long key[2] = {
    701                 LOWER32(client_id),
    702                 UPPER32(client_id),
    703         };
    704690        client_t *client = NULL;
    705691
    706692        futex_down(&async_futex);
    707         link_t *lnk = hash_table_find(&client_hash_table, key);
     693        ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
    708694        if (lnk) {
    709                 client = hash_table_get_instance(lnk, client_t, link);
     695                client = hash_table_get_inst(lnk, client_t, link);
    710696                atomic_inc(&client->refcnt);
    711697        } else if (create) {
     
    716702               
    717703                        atomic_set(&client->refcnt, 1);
    718                         hash_table_insert(&client_hash_table, key, &client->link);
     704                        hash_table_insert(&client_hash_table, &client->link);
    719705                }
    720706        }
     
    727713{
    728714        bool destroy;
    729         unsigned long key[2] = {
    730                 LOWER32(client->in_task_id),
    731                 UPPER32(client->in_task_id)
    732         };
    733        
     715
    734716        futex_down(&async_futex);
    735717       
    736718        if (atomic_predec(&client->refcnt) == 0) {
    737                 hash_table_remove(&client_hash_table, key, 2);
     719                hash_table_remove(&client_hash_table, &client->in_task_id);
    738720                destroy = true;
    739721        } else
     
    831813         */
    832814        futex_down(&async_futex);
    833         unsigned long key = fibril_connection->in_phone_hash;
    834         hash_table_remove(&conn_hash_table, &key, 1);
     815        hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
    835816        futex_up(&async_futex);
    836817       
     
    916897       
    917898        /* Add connection to the connection hash table */
    918         unsigned long key = conn->in_phone_hash;
    919899       
    920900        futex_down(&async_futex);
    921         hash_table_insert(&conn_hash_table, &key, &conn->link);
     901        hash_table_insert(&conn_hash_table, &conn->link);
    922902        futex_up(&async_futex);
    923903       
     
    11111091void __async_init(void)
    11121092{
    1113         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    1114             2, &client_hash_table_ops))
     1093        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    11151094                abort();
    11161095       
    1117         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
    1118             1, &conn_hash_table_ops))
     1096        if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
    11191097                abort();
    11201098       
Note: See TracChangeset for help on using the changeset viewer.