Ignore:
File:
1 edited

Legend:

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

    r375e501 rbc216a0  
    115115#include <macros.h>
    116116
    117 #define CLIENT_HASH_TABLE_BUCKETS  32
    118 #define CONN_HASH_TABLE_BUCKETS    32
    119117
    120118/** Session data */
     
    204202/* Client connection data */
    205203typedef struct {
    206         link_t link;
     204        ht_link_t link;
    207205       
    208206        task_id_t in_task_id;
     
    216214       
    217215        /** Hash table link. */
    218         link_t link;
     216        ht_link_t link;
    219217       
    220218        /** Incoming client task ID. */
     
    392390static LIST_INITIALIZE(timeout_list);
    393391
    394 static hash_index_t client_hash(unsigned long key[])
    395 {
    396         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)
    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 
    412 static void client_remove(link_t *item)
    413 {
    414 }
     392static size_t client_key_hash(void *k)
     393{
     394        task_id_t key = *(task_id_t*)k;
     395        return key;
     396}
     397
     398static 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
     404static 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
    415411
    416412/** Operations for the client hash table. */
    417 static hash_table_operations_t client_hash_table_ops = {
     413static hash_table_ops_t client_hash_table_ops = {
    418414        .hash = client_hash,
    419         .compare = client_compare,
    420         .remove_callback = client_remove
     415        .key_hash = client_key_hash,
     416        .key_equal = client_key_equal,
     417        .equal = 0,
     418        .remove_callback = 0
    421419};
    422420
     
    428426 *
    429427 */
    430 static 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  */
    446 static 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 
    455 static void conn_remove(link_t *item)
    456 {
    457 }
     428static size_t conn_key_hash(void *key)
     429{
     430        sysarg_t in_phone_hash  = *(sysarg_t*)key;
     431        return in_phone_hash ;
     432}
     433
     434static 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
     440static 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
    458447
    459448/** Operations for the connection hash table. */
    460 static hash_table_operations_t conn_hash_table_ops = {
     449static hash_table_ops_t conn_hash_table_ops = {
    461450        .hash = conn_hash,
    462         .compare = conn_compare,
    463         .remove_callback = conn_remove
     451        .key_hash = conn_key_hash,
     452        .key_equal = conn_key_equal,
     453        .equal = 0,
     454        .remove_callback = 0
    464455};
    465456
     
    509500        futex_down(&async_futex);
    510501       
    511         unsigned long key = call->in_phone_hash;
    512         link_t *hlp = hash_table_find(&conn_hash_table, &key);
     502        ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash);
    513503       
    514504        if (!hlp) {
     
    517507        }
    518508       
    519         connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
     509        connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
    520510       
    521511        msg_t *msg = malloc(sizeof(*msg));
     
    697687static client_t *async_client_get(task_id_t client_id, bool create)
    698688{
    699         unsigned long key[2] = {
    700                 LOWER32(client_id),
    701                 UPPER32(client_id),
    702         };
    703689        client_t *client = NULL;
    704690
    705691        futex_down(&async_futex);
    706         link_t *lnk = hash_table_find(&client_hash_table, key);
     692        ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
    707693        if (lnk) {
    708                 client = hash_table_get_instance(lnk, client_t, link);
     694                client = hash_table_get_inst(lnk, client_t, link);
    709695                atomic_inc(&client->refcnt);
    710696        } else if (create) {
     
    715701               
    716702                        atomic_set(&client->refcnt, 1);
    717                         hash_table_insert(&client_hash_table, key, &client->link);
     703                        hash_table_insert(&client_hash_table, &client->link);
    718704                }
    719705        }
     
    726712{
    727713        bool destroy;
    728         unsigned long key[2] = {
    729                 LOWER32(client->in_task_id),
    730                 UPPER32(client->in_task_id)
    731         };
    732        
     714
    733715        futex_down(&async_futex);
    734716       
    735717        if (atomic_predec(&client->refcnt) == 0) {
    736                 hash_table_remove(&client_hash_table, key, 2);
     718                hash_table_remove(&client_hash_table, &client->in_task_id);
    737719                destroy = true;
    738720        } else
     
    830812         */
    831813        futex_down(&async_futex);
    832         unsigned long key = fibril_connection->in_phone_hash;
    833         hash_table_remove(&conn_hash_table, &key, 1);
     814        hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
    834815        futex_up(&async_futex);
    835816       
     
    915896       
    916897        /* Add connection to the connection hash table */
    917         unsigned long key = conn->in_phone_hash;
    918898       
    919899        futex_down(&async_futex);
    920         hash_table_insert(&conn_hash_table, &key, &conn->link);
     900        hash_table_insert(&conn_hash_table, &conn->link);
    921901        futex_up(&async_futex);
    922902       
     
    11101090void __async_init(void)
    11111091{
    1112         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    1113             2, &client_hash_table_ops))
     1092        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    11141093                abort();
    11151094       
    1116         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
    1117             1, &conn_hash_table_ops))
     1095        if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
    11181096                abort();
    11191097       
Note: See TracChangeset for help on using the changeset viewer.