Changeset bc216a0 in mainline for uspace/app/trace/ipcp.c


Ignore:
Timestamp:
2012-08-07T22:13:44Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
da68871a
Parents:
b17518e
Message:

Refactored any users of hash_table to use opaque void* keys instead of the cumbersome unsigned long[] keys. Switched from the ad hoc computations of hashes of multiple values to hash_combine().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/trace/ipcp.c

    rb17518e rbc216a0  
    5353        ipc_callid_t call_hash;
    5454
    55         link_t link;
     55        ht_link_t link;
    5656} pending_call_t;
    5757
     
    7373proto_t *proto_unknown;         /**< Protocol with no known methods. */
    7474
    75 static size_t pending_call_key_hash(unsigned long key[]);
    76 static size_t pending_call_hash(const link_t *item);
    77 static bool pending_call_match(unsigned long key[], size_t keys,
    78     const link_t *item);
     75
     76static size_t pending_call_key_hash(void *key)
     77{
     78        ipc_callid_t *call_id = (ipc_callid_t *)key;
     79        return *call_id;
     80}
     81
     82static size_t pending_call_hash(const ht_link_t *item)
     83{
     84        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     85        return hs->call_hash;
     86}
     87
     88static bool pending_call_key_equal(void *key, const ht_link_t *item)
     89{
     90        ipc_callid_t *call_id = (ipc_callid_t *)key;
     91        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     92
     93        return *call_id == hs->call_hash;
     94}
    7995
    8096static hash_table_ops_t pending_call_ops = {
    8197        .hash = pending_call_hash,
    8298        .key_hash = pending_call_key_hash,
    83         .match = pending_call_match,
     99        .key_equal = pending_call_key_equal,
    84100        .equal = 0,
    85101        .remove_callback = 0
    86102};
    87 
    88 
    89 static size_t pending_call_key_hash(unsigned long key[])
    90 {
    91         size_t hash = 17;
    92         hash = 31 * hash + key[1];
    93         hash = 31 * hash + key[0];
    94         return hash;
    95 }
    96 
    97 static size_t pending_call_hash(const link_t *item)
    98 {
    99         pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
    100         unsigned long key[] = {
    101                 LOWER32(hs->call_hash),
    102                 UPPER32(hs->call_hash)
    103         };
    104         return pending_call_key_hash(key);
    105 }
    106 
    107 static bool pending_call_match(unsigned long key[], size_t keys,
    108         const link_t *item)
    109 {
    110         assert(keys == 2);
    111         pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
    112 
    113         return MERGE_LOUP32(key[0], key[1]) == hs->call_hash;
    114 }
    115 
    116103
    117104
     
    184171        }
    185172
    186         hash_table_create(&pending_calls, 0, 2, &pending_call_ops);
     173        bool ok = hash_table_create(&pending_calls, 0, 0, &pending_call_ops);
     174        assert(ok);
    187175}
    188176
     
    338326void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash)
    339327{
    340         link_t *item;
     328        ht_link_t *item;
    341329        pending_call_t *pcall;
    342330       
     
    350338       
    351339        hash = hash & ~IPC_CALLID_ANSWERED;
    352         unsigned long key[] = {
    353                 LOWER32(hash),
    354                 UPPER32(hash)
    355         };
    356        
    357         item = hash_table_find(&pending_calls, key);
     340       
     341        item = hash_table_find(&pending_calls, &hash);
    358342        if (item == NULL)
    359343                return; /* No matching question found */
     
    363347         */
    364348       
    365         pcall = hash_table_get_instance(item, pending_call_t, link);
    366         hash_table_remove(&pending_calls, key, 2);
     349        pcall = hash_table_get_inst(item, pending_call_t, link);
     350        hash_table_remove(&pending_calls, &hash);
    367351       
    368352        parse_answer(hash, pcall, call);
Note: See TracChangeset for help on using the changeset viewer.