Changeset 0ca7286 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2732c94
Parents:
1c1da4b
Message:

Added resizing to user space (single-threaded) hash_table. Resizes in a way to mitigate effects of bad hash functions. Change of interface affected many files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r1c1da4b r0ca7286  
    115115#include <macros.h>
    116116
    117 #define CLIENT_HASH_TABLE_BUCKETS  32
    118 #define CONN_HASH_TABLE_BUCKETS    32
    119117
    120118/** Session data */
     
    392390static LIST_INITIALIZE(timeout_list);
    393391
    394 static hash_index_t client_hash(unsigned long key[])
     392static size_t client_key_hash(unsigned long key[])
    395393{
    396394        assert(key);
    397        
    398         return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    399 }
    400 
    401 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
     395        /* LOWER32(in_task_id) */
     396        return key[0] >> 4;
     397}
     398
     399static size_t client_hash(const link_t *item)
     400{
     401        client_t *client = hash_table_get_instance(item, client_t, link);
     402       
     403        unsigned long key[2] = {
     404                LOWER32(client->in_task_id),
     405                UPPER32(client->in_task_id),
     406        };
     407
     408        return client_key_hash(key);
     409}
     410
     411static bool client_match(unsigned long key[], size_t keys, const link_t *item)
    402412{
    403413        assert(key);
     
    410420}
    411421
    412 static void client_remove(link_t *item)
    413 {
    414 }
    415422
    416423/** Operations for the client hash table. */
    417 static hash_table_operations_t client_hash_table_ops = {
     424static hash_table_ops_t client_hash_table_ops = {
    418425        .hash = client_hash,
    419         .compare = client_compare,
    420         .remove_callback = client_remove
     426        .key_hash = client_key_hash,
     427        .match = client_match,
     428        .equal = 0,
     429        .remove_callback = 0
    421430};
    422431
     
    428437 *
    429438 */
    430 static hash_index_t conn_hash(unsigned long key[])
     439static size_t conn_key_hash(unsigned long key[])
    431440{
    432441        assert(key);
    433        
    434         return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
     442        return key[0] >> 4;
     443}
     444
     445static size_t conn_hash(const link_t *item)
     446{
     447        connection_t *conn = hash_table_get_instance(item, connection_t, link);
     448        unsigned long key = conn->in_phone_hash;
     449        return conn_key_hash(&key);
    435450}
    436451
     
    444459 *
    445460 */
    446 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
     461static bool conn_match(unsigned long key[], size_t keys, const link_t *item)
    447462{
    448463        assert(key);
     
    453468}
    454469
     470static bool conn_equal(const link_t *item1, const link_t *item2)
     471{
     472        connection_t *c1 = hash_table_get_instance(item1, connection_t, link);
     473        connection_t *c2 = hash_table_get_instance(item2, connection_t, link);
     474       
     475        return c1->in_phone_hash == c2->in_phone_hash;
     476}
     477
    455478static void conn_remove(link_t *item)
    456479{
     
    458481
    459482/** Operations for the connection hash table. */
    460 static hash_table_operations_t conn_hash_table_ops = {
     483static hash_table_ops_t conn_hash_table_ops = {
    461484        .hash = conn_hash,
    462         .compare = conn_compare,
     485        .key_hash = conn_key_hash,
     486        .match = conn_match,
     487        .equal = conn_equal,
    463488        .remove_callback = conn_remove
    464489};
     
    715740               
    716741                        atomic_set(&client->refcnt, 1);
    717                         hash_table_insert(&client_hash_table, key, &client->link);
     742                        hash_table_insert(&client_hash_table, &client->link);
    718743                }
    719744        }
     
    915940       
    916941        /* Add connection to the connection hash table */
    917         unsigned long key = conn->in_phone_hash;
    918942       
    919943        futex_down(&async_futex);
    920         hash_table_insert(&conn_hash_table, &key, &conn->link);
     944        hash_table_insert(&conn_hash_table, &conn->link);
    921945        futex_up(&async_futex);
    922946       
     
    11101134void __async_init(void)
    11111135{
    1112         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    1113             2, &client_hash_table_ops))
     1136        if (!hash_table_create(&client_hash_table, 0, 2, &client_hash_table_ops))
    11141137                abort();
    11151138       
    1116         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
    1117             1, &conn_hash_table_ops))
     1139        if (!hash_table_create(&conn_hash_table, 0, 1, &conn_hash_table_ops))
    11181140                abort();
    11191141       
Note: See TracChangeset for help on using the changeset viewer.