Changes in uspace/srv/devman/devman.c [a1a101d:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
ra1a101d r4e00f87 66 66 /* hash table operations */ 67 67 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 68 static inline size_t handle_key_hash(void *key) 69 { 70 devman_handle_t handle = *(devman_handle_t*)key; 71 return handle; 72 } 73 74 static 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 80 static 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 86 static 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 93 static 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 100 static 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 106 static 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 112 static 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 120 static 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 102 126 }; 103 127 104 static hash_table_operations_t devman_functions_ops = { 105 .hash = devices_hash, 106 .compare = devman_functions_compare, 107 .remove_callback = devices_remove_callback 128 static 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 108 134 }; 109 135 110 static hash_table_operations_t loc_devices_ops = { 111 .hash = devices_hash, 112 .compare = loc_functions_compare, 113 .remove_callback = devices_remove_callback 136 static 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 114 142 }; 115 143 … … 974 1002 tree->current_handle = 0; 975 1003 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); 982 1007 983 1008 fibril_rwlock_initialize(&tree->rwlock); … … 1013 1038 list_initialize(&dev->functions); 1014 1039 link_initialize(&dev->driver_devices); 1015 link_initialize(&dev->devman_dev);1016 1040 1017 1041 return dev; … … 1060 1084 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1061 1085 { 1062 unsigned long key = handle;1063 link_t *link;1064 1065 1086 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1066 1087 1067 link = hash_table_find(&tree->devman_devices, &key);1088 ht_link_t *link = hash_table_find(&tree->devman_devices, &handle); 1068 1089 if (link == NULL) 1069 1090 return NULL; 1070 1091 1071 return hash_table_get_inst ance(link, dev_node_t, devman_dev);1092 return hash_table_get_inst(link, dev_node_t, devman_dev); 1072 1093 } 1073 1094 … … 1144 1165 link_initialize(&fun->dev_functions); 1145 1166 list_initialize(&fun->match_ids.ids); 1146 link_initialize(&fun->devman_fun);1147 link_initialize(&fun->loc_fun);1148 1167 1149 1168 return fun; … … 1206 1225 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1207 1226 { 1208 unsigned long key = handle;1209 link_t *link;1210 1227 fun_node_t *fun; 1211 1228 1212 1229 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1213 1230 1214 link = hash_table_find(&tree->devman_functions, &key);1231 ht_link_t *link = hash_table_find(&tree->devman_functions, &handle); 1215 1232 if (link == NULL) 1216 1233 return NULL; 1217 1234 1218 fun = hash_table_get_inst ance(link, fun_node_t, devman_fun);1235 fun = hash_table_get_inst(link, fun_node_t, devman_fun); 1219 1236 1220 1237 return fun; … … 1294 1311 /* Add the node to the handle-to-node map. */ 1295 1312 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); 1298 1314 1299 1315 /* Add the node to the list of its parent's children. */ … … 1316 1332 1317 1333 /* 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); 1320 1335 1321 1336 /* Unlink from parent function. */ … … 1358 1373 /* Add the node to the handle-to-node map. */ 1359 1374 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); 1362 1376 1363 1377 /* Add the node to the list of its parent's children. */ … … 1379 1393 1380 1394 /* 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); 1383 1396 1384 1397 /* Remove the node from the list of its parent's children. */ … … 1493 1506 { 1494 1507 fun_node_t *fun = NULL; 1495 link_t *link;1496 unsigned long key = (unsigned long) service_id;1497 1508 1498 1509 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); 1500 1511 if (link != NULL) { 1501 fun = hash_table_get_inst ance(link, fun_node_t, loc_fun);1512 fun = hash_table_get_inst(link, fun_node_t, loc_fun); 1502 1513 fun_add_ref(fun); 1503 1514 } … … 1511 1522 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1512 1523 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); 1515 1525 } 1516 1526
Note:
See TracChangeset
for help on using the changeset viewer.