Changeset efdfebc in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2012-11-06T21:03:44Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
338810f
Parents:
de73242 (diff), 94795812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rde73242 refdfebc  
    114114#include <stdlib.h>
    115115#include <macros.h>
    116 
    117 #define CLIENT_HASH_TABLE_BUCKETS  32
    118 #define CONN_HASH_TABLE_BUCKETS    32
     116#include "private/libc.h"
     117
    119118
    120119/** Session data */
     
    204203/* Client connection data */
    205204typedef struct {
    206         link_t link;
     205        ht_link_t link;
    207206       
    208207        task_id_t in_task_id;
     
    216215       
    217216        /** Hash table link. */
    218         link_t link;
     217        ht_link_t link;
    219218       
    220219        /** Incoming client task ID. */
     
    392391static LIST_INITIALIZE(timeout_list);
    393392
    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 }
     393static size_t client_key_hash(void *k)
     394{
     395        task_id_t key = *(task_id_t*)k;
     396        return key;
     397}
     398
     399static 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
     405static 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
    415412
    416413/** Operations for the client hash table. */
    417 static hash_table_operations_t client_hash_table_ops = {
     414static hash_table_ops_t client_hash_table_ops = {
    418415        .hash = client_hash,
    419         .compare = client_compare,
    420         .remove_callback = client_remove
     416        .key_hash = client_key_hash,
     417        .key_equal = client_key_equal,
     418        .equal = NULL,
     419        .remove_callback = NULL
    421420};
    422421
     
    428427 *
    429428 */
    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 }
     429static size_t conn_key_hash(void *key)
     430{
     431        sysarg_t in_phone_hash  = *(sysarg_t*)key;
     432        return in_phone_hash ;
     433}
     434
     435static 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
     441static 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
    458448
    459449/** Operations for the connection hash table. */
    460 static hash_table_operations_t conn_hash_table_ops = {
     450static hash_table_ops_t conn_hash_table_ops = {
    461451        .hash = conn_hash,
    462         .compare = conn_compare,
    463         .remove_callback = conn_remove
     452        .key_hash = conn_key_hash,
     453        .key_equal = conn_key_equal,
     454        .equal = NULL,
     455        .remove_callback = NULL
    464456};
    465457
     
    509501        futex_down(&async_futex);
    510502       
    511         unsigned long key = call->in_phone_hash;
    512         link_t *hlp = hash_table_find(&conn_hash_table, &key);
     503        ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash);
    513504       
    514505        if (!hlp) {
     
    517508        }
    518509       
    519         connection_t *conn = hash_table_get_instance(hlp, connection_t, link);
     510        connection_t *conn = hash_table_get_inst(hlp, connection_t, link);
    520511       
    521512        msg_t *msg = malloc(sizeof(*msg));
     
    637628       
    638629        if (usecs) {
    639                 gettimeofday(&conn->wdata.to_event.expires, NULL);
     630                getuptime(&conn->wdata.to_event.expires);
    640631                tv_add(&conn->wdata.to_event.expires, usecs);
    641632        } else
     
    697688static client_t *async_client_get(task_id_t client_id, bool create)
    698689{
    699         unsigned long key[2] = {
    700                 LOWER32(client_id),
    701                 UPPER32(client_id),
    702         };
    703690        client_t *client = NULL;
    704691
    705692        futex_down(&async_futex);
    706         link_t *lnk = hash_table_find(&client_hash_table, key);
     693        ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);
    707694        if (lnk) {
    708                 client = hash_table_get_instance(lnk, client_t, link);
     695                client = hash_table_get_inst(lnk, client_t, link);
    709696                atomic_inc(&client->refcnt);
    710697        } else if (create) {
     
    715702               
    716703                        atomic_set(&client->refcnt, 1);
    717                         hash_table_insert(&client_hash_table, key, &client->link);
     704                        hash_table_insert(&client_hash_table, &client->link);
    718705                }
    719706        }
     
    726713{
    727714        bool destroy;
    728         unsigned long key[2] = {
    729                 LOWER32(client->in_task_id),
    730                 UPPER32(client->in_task_id)
    731         };
    732        
     715
    733716        futex_down(&async_futex);
    734717       
    735718        if (atomic_predec(&client->refcnt) == 0) {
    736                 hash_table_remove(&client_hash_table, key, 2);
     719                hash_table_remove(&client_hash_table, &client->in_task_id);
    737720                destroy = true;
    738721        } else
     
    830813         */
    831814        futex_down(&async_futex);
    832         unsigned long key = fibril_connection->in_phone_hash;
    833         hash_table_remove(&conn_hash_table, &key, 1);
     815        hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash);
    834816        futex_up(&async_futex);
    835817       
     
    915897       
    916898        /* Add connection to the connection hash table */
    917         unsigned long key = conn->in_phone_hash;
    918899       
    919900        futex_down(&async_futex);
    920         hash_table_insert(&conn_hash_table, &key, &conn->link);
     901        hash_table_insert(&conn_hash_table, &conn->link);
    921902        futex_up(&async_futex);
    922903       
     
    966947{
    967948        struct timeval tv;
    968         gettimeofday(&tv, NULL);
     949        getuptime(&tv);
    969950       
    970951        futex_down(&async_futex);
     
    10231004                       
    10241005                        struct timeval tv;
    1025                         gettimeofday(&tv, NULL);
     1006                        getuptime(&tv);
    10261007                       
    10271008                        if (tv_gteq(&tv, &waiter->to_event.expires)) {
     
    11101091void __async_init(void)
    11111092{
    1112         if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    1113             2, &client_hash_table_ops))
     1093        if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops))
    11141094                abort();
    11151095       
    1116         if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS,
    1117             1, &conn_hash_table_ops))
     1096        if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops))
    11181097                abort();
    11191098       
     
    13301309                timeout = 0;
    13311310
    1332         gettimeofday(&msg->wdata.to_event.expires, NULL);
     1311        getuptime(&msg->wdata.to_event.expires);
    13331312        tv_add(&msg->wdata.to_event.expires, timeout);
    13341313       
     
    14121391        msg->wdata.fid = fibril_get_id();
    14131392       
    1414         gettimeofday(&msg->wdata.to_event.expires, NULL);
     1393        getuptime(&msg->wdata.to_event.expires);
    14151394        tv_add(&msg->wdata.to_event.expires, timeout);
    14161395       
     
    21662145int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    21672146{
    2168         return ipc_share_in_finalize(callid, src, flags);
     2147        return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
     2148            (sysarg_t) __entry);
    21692149}
    21702150
     
    22332213int async_share_out_finalize(ipc_callid_t callid, void **dst)
    22342214{
    2235         return ipc_share_out_finalize(callid, dst);
     2215        return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
    22362216}
    22372217
     
    23172297int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
    23182298{
    2319         return ipc_data_read_finalize(callid, src, size);
     2299        return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
    23202300}
    23212301
     
    24202400int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    24212401{
    2422         return ipc_data_write_finalize(callid, dst, size);
     2402        return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
    24232403}
    24242404
Note: See TracChangeset for help on using the changeset viewer.