Ignore:
File:
1 edited

Legend:

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

    rd7978525 rbc216a0  
    114114#include <stdlib.h>
    115115#include <macros.h>
    116 #include "private/libc.h"
    117 
    118 #define CLIENT_HASH_TABLE_BUCKETS  32
    119 #define CONN_HASH_TABLE_BUCKETS    32
     116
    120117
    121118/** Session data */
     
    205202/* Client connection data */
    206203typedef struct {
    207         link_t link;
     204        ht_link_t link;
    208205       
    209206        task_id_t in_task_id;
     
    217214       
    218215        /** Hash table link. */
    219         link_t link;
     216        ht_link_t link;
    220217       
    221218        /** Incoming client task ID. */
     
    393390static LIST_INITIALIZE(timeout_list);
    394391
    395 static hash_index_t client_hash(unsigned long key[])
    396 {
    397         assert(key);
    398        
    399         return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    400 }
    401 
    402 static 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 
    413 static void client_remove(link_t *item)
    414 {
    415 }
     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
    416411
    417412/** Operations for the client hash table. */
    418 static hash_table_operations_t client_hash_table_ops = {
     413static hash_table_ops_t client_hash_table_ops = {
    419414        .hash = client_hash,
    420         .compare = client_compare,
    421         .remove_callback = client_remove
     415        .key_hash = client_key_hash,
     416        .key_equal = client_key_equal,
     417        .equal = 0,
     418        .remove_callback = 0
    422419};
    423420
     
    429426 *
    430427 */
    431 static 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  */
    447 static 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 
    456 static void conn_remove(link_t *item)
    457 {
    458 }
     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
    459447
    460448/** Operations for the connection hash table. */
    461 static hash_table_operations_t conn_hash_table_ops = {
     449static hash_table_ops_t conn_hash_table_ops = {
    462450        .hash = conn_hash,
    463         .compare = conn_compare,
    464         .remove_callback = conn_remove
     451        .key_hash = conn_key_hash,
     452        .key_equal = conn_key_equal,
     453        .equal = 0,
     454        .remove_callback = 0
    465455};
    466456
     
    510500        futex_down(&async_futex);
    511501       
    512         unsigned long key = call->in_phone_hash;
    513         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);
    514503       
    515504        if (!hlp) {
     
    518507        }
    519508       
    520         connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
     509        connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
    521510       
    522511        msg_t *msg = malloc(sizeof(*msg));
     
    698687static client_t *async_client_get(task_id_t client_id, bool create)
    699688{
    700         unsigned long key[2] = {
    701                 LOWER32(client_id),
    702                 UPPER32(client_id),
    703         };
    704689        client_t *client = NULL;
    705690
    706691        futex_down(&async_futex);
    707         link_t *lnk = hash_table_find(&client_hash_table, key);
     692        ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
    708693        if (lnk) {
    709                 client = hash_table_get_instance(lnk, client_t, link);
     694                client = hash_table_get_inst(lnk, client_t, link);
    710695                atomic_inc(&client->refcnt);
    711696        } else if (create) {
     
    716701               
    717702                        atomic_set(&client->refcnt, 1);
    718                         hash_table_insert(&client_hash_table, key, &client->link);
     703                        hash_table_insert(&client_hash_table, &client->link);
    719704                }
    720705        }
     
    727712{
    728713        bool destroy;
    729         unsigned long key[2] = {
    730                 LOWER32(client->in_task_id),
    731                 UPPER32(client->in_task_id)
    732         };
    733        
     714
    734715        futex_down(&async_futex);
    735716       
    736717        if (atomic_predec(&client->refcnt) == 0) {
    737                 hash_table_remove(&client_hash_table, key, 2);
     718                hash_table_remove(&client_hash_table, &client->in_task_id);
    738719                destroy = true;
    739720        } else
     
    831812         */
    832813        futex_down(&async_futex);
    833         unsigned long key = fibril_connection->in_phone_hash;
    834         hash_table_remove(&conn_hash_table, &key, 1);
     814        hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
    835815        futex_up(&async_futex);
    836816       
     
    916896       
    917897        /* Add connection to the connection hash table */
    918         unsigned long key = conn->in_phone_hash;
    919898       
    920899        futex_down(&async_futex);
    921         hash_table_insert(&conn_hash_table, &key, &conn->link);
     900        hash_table_insert(&conn_hash_table, &conn->link);
    922901        futex_up(&async_futex);
    923902       
     
    11111090void __async_init(void)
    11121091{
    1113         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    1114             2, &client_hash_table_ops))
     1092        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    11151093                abort();
    11161094       
    1117         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
    1118             1, &conn_hash_table_ops))
     1095        if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
    11191096                abort();
    11201097       
     
    21672144int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    21682145{
    2169         return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
    2170             (sysarg_t) __entry);
     2146        return ipc_share_in_finalize(callid, src, flags);
    21712147}
    21722148
     
    22352211int async_share_out_finalize(ipc_callid_t callid, void **dst)
    22362212{
    2237         return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
     2213        return ipc_share_out_finalize(callid, dst);
    22382214}
    22392215
     
    23192295int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
    23202296{
    2321         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
     2297        return ipc_data_read_finalize(callid, src, size);
    23222298}
    23232299
     
    24222398int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    24232399{
    2424         return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
     2400        return ipc_data_write_finalize(callid, dst, size);
    24252401}
    24262402
Note: See TracChangeset for help on using the changeset viewer.