Ignore:
File:
1 edited

Legend:

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

    r4e00f87 r375e501  
    114114#include <stdlib.h>
    115115#include <macros.h>
    116 #include "private/libc.h"
    117 
     116
     117#define CLIENT_HASH_TABLE_BUCKETS  32
     118#define CONN_HASH_TABLE_BUCKETS    32
    118119
    119120/** Session data */
     
    203204/* Client connection data */
    204205typedef struct {
    205         ht_link_t link;
     206        link_t link;
    206207       
    207208        task_id_t in_task_id;
     
    215216       
    216217        /** Hash table link. */
    217         ht_link_t link;
     218        link_t link;
    218219       
    219220        /** Incoming client task ID. */
     
    391392static LIST_INITIALIZE(timeout_list);
    392393
    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 
     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}
    412415
    413416/** Operations for the client hash table. */
    414 static hash_table_ops_t client_hash_table_ops = {
     417static hash_table_operations_t client_hash_table_ops = {
    415418        .hash = client_hash,
    416         .key_hash = client_key_hash,
    417         .key_equal = client_key_equal,
    418         .equal = NULL,
    419         .remove_callback = NULL
     419        .compare = client_compare,
     420        .remove_callback = client_remove
    420421};
    421422
     
    427428 *
    428429 */
    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 
     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}
    448458
    449459/** Operations for the connection hash table. */
    450 static hash_table_ops_t conn_hash_table_ops = {
     460static hash_table_operations_t conn_hash_table_ops = {
    451461        .hash = conn_hash,
    452         .key_hash = conn_key_hash,
    453         .key_equal = conn_key_equal,
    454         .equal = NULL,
    455         .remove_callback = NULL
     462        .compare = conn_compare,
     463        .remove_callback = conn_remove
    456464};
    457465
     
    501509        futex_down(&async_futex);
    502510       
    503         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);
    504513       
    505514        if (!hlp) {
     
    508517        }
    509518       
    510         connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
     519        connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
    511520       
    512521        msg_t *msg = malloc(sizeof(*msg));
     
    628637       
    629638        if (usecs) {
    630                 getuptime(&conn->wdata.to_event.expires);
     639                gettimeofday(&conn->wdata.to_event.expires, NULL);
    631640                tv_add(&conn->wdata.to_event.expires, usecs);
    632641        } else
     
    688697static client_t *async_client_get(task_id_t client_id, bool create)
    689698{
     699        unsigned long key[2] = {
     700                LOWER32(client_id),
     701                UPPER32(client_id),
     702        };
    690703        client_t *client = NULL;
    691704
    692705        futex_down(&async_futex);
    693         ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
     706        link_t *lnk = hash_table_find(&client_hash_table, key);
    694707        if (lnk) {
    695                 client = hash_table_get_inst(lnk, client_t, link);
     708                client = hash_table_get_instance(lnk, client_t, link);
    696709                atomic_inc(&client->refcnt);
    697710        } else if (create) {
     
    702715               
    703716                        atomic_set(&client->refcnt, 1);
    704                         hash_table_insert(&client_hash_table, &client->link);
     717                        hash_table_insert(&client_hash_table, key, &client->link);
    705718                }
    706719        }
     
    713726{
    714727        bool destroy;
    715 
     728        unsigned long key[2] = {
     729                LOWER32(client->in_task_id),
     730                UPPER32(client->in_task_id)
     731        };
     732       
    716733        futex_down(&async_futex);
    717734       
    718735        if (atomic_predec(&client->refcnt) == 0) {
    719                 hash_table_remove(&client_hash_table, &client->in_task_id);
     736                hash_table_remove(&client_hash_table, key, 2);
    720737                destroy = true;
    721738        } else
     
    813830         */
    814831        futex_down(&async_futex);
    815         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);
    816834        futex_up(&async_futex);
    817835       
     
    897915       
    898916        /* Add connection to the connection hash table */
     917        unsigned long key = conn->in_phone_hash;
    899918       
    900919        futex_down(&async_futex);
    901         hash_table_insert(&conn_hash_table, &conn->link);
     920        hash_table_insert(&conn_hash_table, &key, &conn->link);
    902921        futex_up(&async_futex);
    903922       
     
    947966{
    948967        struct timeval tv;
    949         getuptime(&tv);
     968        gettimeofday(&tv, NULL);
    950969       
    951970        futex_down(&async_futex);
     
    10041023                       
    10051024                        struct timeval tv;
    1006                         getuptime(&tv);
     1025                        gettimeofday(&tv, NULL);
    10071026                       
    10081027                        if (tv_gteq(&tv, &waiter->to_event.expires)) {
     
    10911110void __async_init(void)
    10921111{
    1093         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))
    10941114                abort();
    10951115       
    1096         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))
    10971118                abort();
    10981119       
     
    13091330                timeout = 0;
    13101331
    1311         getuptime(&msg->wdata.to_event.expires);
     1332        gettimeofday(&msg->wdata.to_event.expires, NULL);
    13121333        tv_add(&msg->wdata.to_event.expires, timeout);
    13131334       
     
    13911412        msg->wdata.fid = fibril_get_id();
    13921413       
    1393         getuptime(&msg->wdata.to_event.expires);
     1414        gettimeofday(&msg->wdata.to_event.expires, NULL);
    13941415        tv_add(&msg->wdata.to_event.expires, timeout);
    13951416       
     
    21452166int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    21462167{
    2147         return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
    2148             (sysarg_t) __entry);
     2168        return ipc_share_in_finalize(callid, src, flags);
    21492169}
    21502170
     
    22132233int async_share_out_finalize(ipc_callid_t callid, void **dst)
    22142234{
    2215         return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
     2235        return ipc_share_out_finalize(callid, dst);
    22162236}
    22172237
     
    22972317int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
    22982318{
    2299         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
     2319        return ipc_data_read_finalize(callid, src, size);
    23002320}
    23012321
     
    24002420int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    24012421{
    2402         return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
     2422        return ipc_data_write_finalize(callid, dst, size);
    24032423}
    24042424
Note: See TracChangeset for help on using the changeset viewer.