Ignore:
File:
1 edited

Legend:

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

    r4e00f87 rd7978525  
    116116#include "private/libc.h"
    117117
     118#define CLIENT_HASH_TABLE_BUCKETS  32
     119#define CONN_HASH_TABLE_BUCKETS    32
    118120
    119121/** Session data */
     
    203205/* Client connection data */
    204206typedef struct {
    205         ht_link_t link;
     207        link_t link;
    206208       
    207209        task_id_t in_task_id;
     
    215217       
    216218        /** Hash table link. */
    217         ht_link_t link;
     219        link_t link;
    218220       
    219221        /** Incoming client task ID. */
     
    391393static LIST_INITIALIZE(timeout_list);
    392394
    393 static size_t client_key_hash(void *k)
    394 {
    395         task_id_t key = *(task_id_t*)k;
    396         return key;
    397 }
    398 
    399 static 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 
    405 static 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 
     395static hash_index_t client_hash(unsigned long key[])
     396{
     397        assert(key);
     398       
     399        return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     400}
     401
     402static 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
     413static void client_remove(link_t *item)
     414{
     415}
    412416
    413417/** Operations for the client hash table. */
    414 static hash_table_ops_t client_hash_table_ops = {
     418static hash_table_operations_t client_hash_table_ops = {
    415419        .hash = client_hash,
    416         .key_hash = client_key_hash,
    417         .key_equal = client_key_equal,
    418         .equal = NULL,
    419         .remove_callback = NULL
     420        .compare = client_compare,
     421        .remove_callback = client_remove
    420422};
    421423
     
    427429 *
    428430 */
    429 static size_t conn_key_hash(void *key)
    430 {
    431         sysarg_t in_phone_hash  = *(sysarg_t*)key;
    432         return in_phone_hash ;
    433 }
    434 
    435 static 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 
    441 static 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 
     431static 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 */
     447static 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
     456static void conn_remove(link_t *item)
     457{
     458}
    448459
    449460/** Operations for the connection hash table. */
    450 static hash_table_ops_t conn_hash_table_ops = {
     461static hash_table_operations_t conn_hash_table_ops = {
    451462        .hash = conn_hash,
    452         .key_hash = conn_key_hash,
    453         .key_equal = conn_key_equal,
    454         .equal = NULL,
    455         .remove_callback = NULL
     463        .compare = conn_compare,
     464        .remove_callback = conn_remove
    456465};
    457466
     
    501510        futex_down(&async_futex);
    502511       
    503         ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash);
     512        unsigned long key = call->in_phone_hash;
     513        link_t *hlp = hash_table_find(&conn_hash_table, &key);
    504514       
    505515        if (!hlp) {
     
    508518        }
    509519       
    510         connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
     520        connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
    511521       
    512522        msg_t *msg = malloc(sizeof(*msg));
     
    628638       
    629639        if (usecs) {
    630                 getuptime(&conn->wdata.to_event.expires);
     640                gettimeofday(&conn->wdata.to_event.expires, NULL);
    631641                tv_add(&conn->wdata.to_event.expires, usecs);
    632642        } else
     
    688698static client_t *async_client_get(task_id_t client_id, bool create)
    689699{
     700        unsigned long key[2] = {
     701                LOWER32(client_id),
     702                UPPER32(client_id),
     703        };
    690704        client_t *client = NULL;
    691705
    692706        futex_down(&async_futex);
    693         ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
     707        link_t *lnk = hash_table_find(&client_hash_table, key);
    694708        if (lnk) {
    695                 client = hash_table_get_inst(lnk, client_t, link);
     709                client = hash_table_get_instance(lnk, client_t, link);
    696710                atomic_inc(&client->refcnt);
    697711        } else if (create) {
     
    702716               
    703717                        atomic_set(&client->refcnt, 1);
    704                         hash_table_insert(&client_hash_table, &client->link);
     718                        hash_table_insert(&client_hash_table, key, &client->link);
    705719                }
    706720        }
     
    713727{
    714728        bool destroy;
    715 
     729        unsigned long key[2] = {
     730                LOWER32(client->in_task_id),
     731                UPPER32(client->in_task_id)
     732        };
     733       
    716734        futex_down(&async_futex);
    717735       
    718736        if (atomic_predec(&client->refcnt) == 0) {
    719                 hash_table_remove(&client_hash_table, &client->in_task_id);
     737                hash_table_remove(&client_hash_table, key, 2);
    720738                destroy = true;
    721739        } else
     
    813831         */
    814832        futex_down(&async_futex);
    815         hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
     833        unsigned long key = fibril_connection->in_phone_hash;
     834        hash_table_remove(&conn_hash_table, &key, 1);
    816835        futex_up(&async_futex);
    817836       
     
    897916       
    898917        /* Add connection to the connection hash table */
     918        unsigned long key = conn->in_phone_hash;
    899919       
    900920        futex_down(&async_futex);
    901         hash_table_insert(&conn_hash_table, &conn->link);
     921        hash_table_insert(&conn_hash_table, &key, &conn->link);
    902922        futex_up(&async_futex);
    903923       
     
    947967{
    948968        struct timeval tv;
    949         getuptime(&tv);
     969        gettimeofday(&tv, NULL);
    950970       
    951971        futex_down(&async_futex);
     
    10041024                       
    10051025                        struct timeval tv;
    1006                         getuptime(&tv);
     1026                        gettimeofday(&tv, NULL);
    10071027                       
    10081028                        if (tv_gteq(&tv, &waiter->to_event.expires)) {
     
    10911111void __async_init(void)
    10921112{
    1093         if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
     1113        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
     1114            2, &client_hash_table_ops))
    10941115                abort();
    10951116       
    1096         if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
     1117        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
     1118            1, &conn_hash_table_ops))
    10971119                abort();
    10981120       
     
    13091331                timeout = 0;
    13101332
    1311         getuptime(&msg->wdata.to_event.expires);
     1333        gettimeofday(&msg->wdata.to_event.expires, NULL);
    13121334        tv_add(&msg->wdata.to_event.expires, timeout);
    13131335       
     
    13911413        msg->wdata.fid = fibril_get_id();
    13921414       
    1393         getuptime(&msg->wdata.to_event.expires);
     1415        gettimeofday(&msg->wdata.to_event.expires, NULL);
    13941416        tv_add(&msg->wdata.to_event.expires, timeout);
    13951417       
Note: See TracChangeset for help on using the changeset viewer.