Ignore:
File:
1 edited

Legend:

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

    rbc216a0 r375e501  
    115115#include <macros.h>
    116116
     117#define CLIENT_HASH_TABLE_BUCKETS  32
     118#define CONN_HASH_TABLE_BUCKETS    32
    117119
    118120/** Session data */
     
    202204/* Client connection data */
    203205typedef struct {
    204         ht_link_t link;
     206        link_t link;
    205207       
    206208        task_id_t in_task_id;
     
    214216       
    215217        /** Hash table link. */
    216         ht_link_t link;
     218        link_t link;
    217219       
    218220        /** Incoming client task ID. */
     
    390392static LIST_INITIALIZE(timeout_list);
    391393
    392 static size_t client_key_hash(void *k)
    393 {
    394         task_id_t key = *(task_id_t*)k;
    395         return key;
    396 }
    397 
    398 static size_t client_hash(const ht_link_t *item)
    399 {
    400         client_t *client = hash_table_get_inst(item, client_t, link);
    401         return client_key_hash(&client->in_task_id);
    402 }
    403 
    404 static bool client_key_equal(void *k, const ht_link_t *item)
    405 {
    406         task_id_t key = *(task_id_t*)k;
    407         client_t *client = hash_table_get_inst(item, client_t, link);
    408         return key == client->in_task_id;
    409 }
    410 
     394static hash_index_t client_hash(unsigned long key[])
     395{
     396        assert(key);
     397       
     398        return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     399}
     400
     401static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
     402{
     403        assert(key);
     404        assert(keys == 2);
     405        assert(item);
     406       
     407        client_t *client = hash_table_get_instance(item, client_t, link);
     408        return (key[0] == LOWER32(client->in_task_id) &&
     409            (key[1] == UPPER32(client->in_task_id)));
     410}
     411
     412static void client_remove(link_t *item)
     413{
     414}
    411415
    412416/** Operations for the client hash table. */
    413 static hash_table_ops_t client_hash_table_ops = {
     417static hash_table_operations_t client_hash_table_ops = {
    414418        .hash = client_hash,
    415         .key_hash = client_key_hash,
    416         .key_equal = client_key_equal,
    417         .equal = 0,
    418         .remove_callback = 0
     419        .compare = client_compare,
     420        .remove_callback = client_remove
    419421};
    420422
     
    426428 *
    427429 */
    428 static size_t conn_key_hash(void *key)
    429 {
    430         sysarg_t in_phone_hash  = *(sysarg_t*)key;
    431         return in_phone_hash ;
    432 }
    433 
    434 static size_t conn_hash(const ht_link_t *item)
    435 {
    436         connection_t *conn = hash_table_get_inst(item, connection_t, link);
    437         return conn_key_hash(&conn->in_phone_hash);
    438 }
    439 
    440 static bool conn_key_equal(void *key, const ht_link_t *item)
    441 {
    442         sysarg_t in_phone_hash = *(sysarg_t*)key;
    443         connection_t *conn = hash_table_get_inst(item, connection_t, link);
    444         return (in_phone_hash == conn->in_phone_hash);
    445 }
    446 
     430static hash_index_t conn_hash(unsigned long key[])
     431{
     432        assert(key);
     433       
     434        return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
     435}
     436
     437/** Compare hash table item with a key.
     438 *
     439 * @param key  Array containing the source phone hash as the only item.
     440 * @param keys Expected 1 but ignored.
     441 * @param item Connection hash table item.
     442 *
     443 * @return True on match, false otherwise.
     444 *
     445 */
     446static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
     447{
     448        assert(key);
     449        assert(item);
     450       
     451        connection_t *conn = hash_table_get_instance(item, connection_t, link);
     452        return (key[0] == conn->in_phone_hash);
     453}
     454
     455static void conn_remove(link_t *item)
     456{
     457}
    447458
    448459/** Operations for the connection hash table. */
    449 static hash_table_ops_t conn_hash_table_ops = {
     460static hash_table_operations_t conn_hash_table_ops = {
    450461        .hash = conn_hash,
    451         .key_hash = conn_key_hash,
    452         .key_equal = conn_key_equal,
    453         .equal = 0,
    454         .remove_callback = 0
     462        .compare = conn_compare,
     463        .remove_callback = conn_remove
    455464};
    456465
     
    500509        futex_down(&async_futex);
    501510       
    502         ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash);
     511        unsigned long key = call->in_phone_hash;
     512        link_t *hlp = hash_table_find(&conn_hash_table, &key);
    503513       
    504514        if (!hlp) {
     
    507517        }
    508518       
    509         connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
     519        connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
    510520       
    511521        msg_t *msg = malloc(sizeof(*msg));
     
    687697static client_t *async_client_get(task_id_t client_id, bool create)
    688698{
     699        unsigned long key[2] = {
     700                LOWER32(client_id),
     701                UPPER32(client_id),
     702        };
    689703        client_t *client = NULL;
    690704
    691705        futex_down(&async_futex);
    692         ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
     706        link_t *lnk = hash_table_find(&client_hash_table, key);
    693707        if (lnk) {
    694                 client = hash_table_get_inst(lnk, client_t, link);
     708                client = hash_table_get_instance(lnk, client_t, link);
    695709                atomic_inc(&client->refcnt);
    696710        } else if (create) {
     
    701715               
    702716                        atomic_set(&client->refcnt, 1);
    703                         hash_table_insert(&client_hash_table, &client->link);
     717                        hash_table_insert(&client_hash_table, key, &client->link);
    704718                }
    705719        }
     
    712726{
    713727        bool destroy;
    714 
     728        unsigned long key[2] = {
     729                LOWER32(client->in_task_id),
     730                UPPER32(client->in_task_id)
     731        };
     732       
    715733        futex_down(&async_futex);
    716734       
    717735        if (atomic_predec(&client->refcnt) == 0) {
    718                 hash_table_remove(&client_hash_table, &client->in_task_id);
     736                hash_table_remove(&client_hash_table, key, 2);
    719737                destroy = true;
    720738        } else
     
    812830         */
    813831        futex_down(&async_futex);
    814         hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     832        unsigned long key = fibril_connection->in_phone_hash;
     833        hash_table_remove(&conn_hash_table, &key, 1);
    815834        futex_up(&async_futex);
    816835       
     
    896915       
    897916        /* Add connection to the connection hash table */
     917        unsigned long key = conn->in_phone_hash;
    898918       
    899919        futex_down(&async_futex);
    900         hash_table_insert(&conn_hash_table, &conn->link);
     920        hash_table_insert(&conn_hash_table, &key, &conn->link);
    901921        futex_up(&async_futex);
    902922       
     
    10901110void __async_init(void)
    10911111{
    1092         if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
     1112        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
     1113            2, &client_hash_table_ops))
    10931114                abort();
    10941115       
    1095         if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
     1116        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
     1117            1, &conn_hash_table_ops))
    10961118                abort();
    10971119       
Note: See TracChangeset for help on using the changeset viewer.