Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    ra1a101d r4e00f87  
    6666/* hash table operations */
    6767
    68 static hash_index_t devices_hash(unsigned long key[])
    69 {
    70         return key[0] % DEVICE_BUCKETS;
    71 }
    72 
    73 static int devman_devices_compare(unsigned long key[], hash_count_t keys,
    74     link_t *item)
    75 {
    76         dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev);
    77         return (dev->handle == (devman_handle_t) key[0]);
    78 }
    79 
    80 static int devman_functions_compare(unsigned long key[], hash_count_t keys,
    81     link_t *item)
    82 {
    83         fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun);
    84         return (fun->handle == (devman_handle_t) key[0]);
    85 }
    86 
    87 static int loc_functions_compare(unsigned long key[], hash_count_t keys,
    88     link_t *item)
    89 {
    90         fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun);
    91         return (fun->service_id == (service_id_t) key[0]);
    92 }
    93 
    94 static void devices_remove_callback(link_t *item)
    95 {
    96 }
    97 
    98 static hash_table_operations_t devman_devices_ops = {
    99         .hash = devices_hash,
    100         .compare = devman_devices_compare,
    101         .remove_callback = devices_remove_callback
     68static inline size_t handle_key_hash(void *key)
     69{
     70        devman_handle_t handle = *(devman_handle_t*)key;
     71        return handle;
     72}
     73
     74static size_t devman_devices_hash(const ht_link_t *item)
     75{
     76        dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev);
     77        return handle_key_hash(&dev->handle);
     78}
     79
     80static size_t devman_functions_hash(const ht_link_t *item)
     81{
     82        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun);
     83        return handle_key_hash(&fun->handle);
     84}
     85
     86static bool devman_devices_key_equal(void *key, const ht_link_t *item)
     87{
     88        devman_handle_t handle = *(devman_handle_t*)key;
     89        dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev);
     90        return dev->handle == handle;
     91}
     92
     93static bool devman_functions_key_equal(void *key, const ht_link_t *item)
     94{
     95        devman_handle_t handle = *(devman_handle_t*)key;
     96        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun);
     97        return fun->handle == handle;
     98}
     99
     100static inline size_t service_id_key_hash(void *key)
     101{
     102        service_id_t service_id = *(service_id_t*)key;
     103        return service_id;
     104}
     105
     106static size_t loc_functions_hash(const ht_link_t *item)
     107{
     108        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun);
     109        return service_id_key_hash(&fun->service_id);
     110}
     111
     112static bool loc_functions_key_equal(void *key, const ht_link_t *item)
     113{
     114        service_id_t service_id = *(service_id_t*)key;
     115        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun);
     116        return fun->service_id == service_id;
     117}
     118
     119
     120static hash_table_ops_t devman_devices_ops = {
     121        .hash = devman_devices_hash,
     122        .key_hash = handle_key_hash,
     123        .key_equal = devman_devices_key_equal,
     124        .equal = NULL,
     125        .remove_callback = NULL
    102126};
    103127
    104 static hash_table_operations_t devman_functions_ops = {
    105         .hash = devices_hash,
    106         .compare = devman_functions_compare,
    107         .remove_callback = devices_remove_callback
     128static hash_table_ops_t devman_functions_ops = {
     129        .hash = devman_functions_hash,
     130        .key_hash = handle_key_hash,
     131        .key_equal = devman_functions_key_equal,
     132        .equal = NULL,
     133        .remove_callback = NULL
    108134};
    109135
    110 static hash_table_operations_t loc_devices_ops = {
    111         .hash = devices_hash,
    112         .compare = loc_functions_compare,
    113         .remove_callback = devices_remove_callback
     136static hash_table_ops_t loc_devices_ops = {
     137        .hash = loc_functions_hash,
     138        .key_hash = service_id_key_hash,
     139        .key_equal = loc_functions_key_equal,
     140        .equal = NULL,
     141        .remove_callback = NULL
    114142};
    115143
     
    9741002        tree->current_handle = 0;
    9751003       
    976         hash_table_create(&tree->devman_devices, DEVICE_BUCKETS, 1,
    977             &devman_devices_ops);
    978         hash_table_create(&tree->devman_functions, DEVICE_BUCKETS, 1,
    979             &devman_functions_ops);
    980         hash_table_create(&tree->loc_functions, DEVICE_BUCKETS, 1,
    981             &loc_devices_ops);
     1004        hash_table_create(&tree->devman_devices, 0, 0, &devman_devices_ops);
     1005        hash_table_create(&tree->devman_functions, 0, 0, &devman_functions_ops);
     1006        hash_table_create(&tree->loc_functions, 0, 0, &loc_devices_ops);
    9821007       
    9831008        fibril_rwlock_initialize(&tree->rwlock);
     
    10131038        list_initialize(&dev->functions);
    10141039        link_initialize(&dev->driver_devices);
    1015         link_initialize(&dev->devman_dev);
    10161040       
    10171041        return dev;
     
    10601084dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    10611085{
    1062         unsigned long key = handle;
    1063         link_t *link;
    1064        
    10651086        assert(fibril_rwlock_is_locked(&tree->rwlock));
    10661087       
    1067         link = hash_table_find(&tree->devman_devices, &key);
     1088        ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);
    10681089        if (link == NULL)
    10691090                return NULL;
    10701091       
    1071         return hash_table_get_instance(link, dev_node_t, devman_dev);
     1092        return hash_table_get_inst(link, dev_node_t, devman_dev);
    10721093}
    10731094
     
    11441165        link_initialize(&fun->dev_functions);
    11451166        list_initialize(&fun->match_ids.ids);
    1146         link_initialize(&fun->devman_fun);
    1147         link_initialize(&fun->loc_fun);
    11481167       
    11491168        return fun;
     
    12061225fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle)
    12071226{
    1208         unsigned long key = handle;
    1209         link_t *link;
    12101227        fun_node_t *fun;
    12111228       
    12121229        assert(fibril_rwlock_is_locked(&tree->rwlock));
    12131230       
    1214         link = hash_table_find(&tree->devman_functions, &key);
     1231        ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);
    12151232        if (link == NULL)
    12161233                return NULL;
    12171234       
    1218         fun = hash_table_get_instance(link, fun_node_t, devman_fun);
     1235        fun = hash_table_get_inst(link, fun_node_t, devman_fun);
    12191236       
    12201237        return fun;
     
    12941311        /* Add the node to the handle-to-node map. */
    12951312        dev->handle = ++tree->current_handle;
    1296         unsigned long key = dev->handle;
    1297         hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev);
     1313        hash_table_insert(&tree->devman_devices, &dev->devman_dev);
    12981314
    12991315        /* Add the node to the list of its parent's children. */
     
    13161332       
    13171333        /* Remove node from the handle-to-node map. */
    1318         unsigned long key = dev->handle;
    1319         hash_table_remove(&tree->devman_devices, &key, 1);
     1334        hash_table_remove(&tree->devman_devices, &dev->handle);
    13201335       
    13211336        /* Unlink from parent function. */
     
    13581373        /* Add the node to the handle-to-node map. */
    13591374        fun->handle = ++tree->current_handle;
    1360         unsigned long key = fun->handle;
    1361         hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun);
     1375        hash_table_insert(&tree->devman_functions, &fun->devman_fun);
    13621376
    13631377        /* Add the node to the list of its parent's children. */
     
    13791393       
    13801394        /* Remove the node from the handle-to-node map. */
    1381         unsigned long key = fun->handle;
    1382         hash_table_remove(&tree->devman_functions, &key, 1);
     1395        hash_table_remove(&tree->devman_functions, &fun->handle);
    13831396       
    13841397        /* Remove the node from the list of its parent's children. */
     
    14931506{
    14941507        fun_node_t *fun = NULL;
    1495         link_t *link;
    1496         unsigned long key = (unsigned long) service_id;
    14971508       
    14981509        fibril_rwlock_read_lock(&tree->rwlock);
    1499         link = hash_table_find(&tree->loc_functions, &key);
     1510        ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
    15001511        if (link != NULL) {
    1501                 fun = hash_table_get_instance(link, fun_node_t, loc_fun);
     1512                fun = hash_table_get_inst(link, fun_node_t, loc_fun);
    15021513                fun_add_ref(fun);
    15031514        }
     
    15111522        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    15121523       
    1513         unsigned long key = (unsigned long) fun->service_id;
    1514         hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun);
     1524        hash_table_insert(&tree->loc_functions, &fun->loc_fun);
    15151525}
    15161526
Note: See TracChangeset for help on using the changeset viewer.