Changes in uspace/srv/devman/devman.c [4820360:bc216a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r4820360 rbc216a0 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 = 0, 125 .remove_callback = 0 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 = 0, 133 .remove_callback = 0 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 = 0, 141 .remove_callback = 0 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; … … 1052 1076 } 1053 1077 1078 1054 1079 /** Find the device node structure of the device witch has the specified handle. 1055 1080 * … … 1060 1085 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1061 1086 { 1062 unsigned long key = handle;1063 link_t *link;1064 1065 1087 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1066 1088 1067 link = hash_table_find(&tree->devman_devices, &key);1089 ht_link_t *link = hash_table_find(&tree->devman_devices, &handle); 1068 1090 if (link == NULL) 1069 1091 return NULL; 1070 1092 1071 return hash_table_get_inst ance(link, dev_node_t, devman_dev);1093 return hash_table_get_inst(link, dev_node_t, devman_dev); 1072 1094 } 1073 1095 … … 1141 1163 fun->state = FUN_INIT; 1142 1164 atomic_set(&fun->refcnt, 0); 1143 fibril_mutex_initialize(&fun->busy_lock);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; … … 1186 1205 } 1187 1206 1188 /** Make function busy for reconfiguration operations. */1189 void fun_busy_lock(fun_node_t *fun)1190 {1191 fibril_mutex_lock(&fun->busy_lock);1192 }1193 1194 /** Mark end of reconfiguration operation. */1195 void fun_busy_unlock(fun_node_t *fun)1196 {1197 fibril_mutex_unlock(&fun->busy_lock);1198 }1199 1200 1207 /** Find the function node with the specified handle. 1201 1208 * … … 1206 1213 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1207 1214 { 1208 unsigned long key = handle;1209 link_t *link;1210 1215 fun_node_t *fun; 1211 1216 1212 1217 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1213 1218 1214 link = hash_table_find(&tree->devman_functions, &key);1219 ht_link_t *link = hash_table_find(&tree->devman_functions, &handle); 1215 1220 if (link == NULL) 1216 1221 return NULL; 1217 1222 1218 fun = hash_table_get_inst ance(link, fun_node_t, devman_fun);1223 fun = hash_table_get_inst(link, fun_node_t, devman_fun); 1219 1224 1220 1225 return fun; … … 1294 1299 /* Add the node to the handle-to-node map. */ 1295 1300 dev->handle = ++tree->current_handle; 1296 unsigned long key = dev->handle; 1297 hash_table_insert(&tree->devman_devices, &key, &dev->devman_dev); 1301 hash_table_insert(&tree->devman_devices, &dev->devman_dev); 1298 1302 1299 1303 /* Add the node to the list of its parent's children. */ … … 1316 1320 1317 1321 /* Remove node from the handle-to-node map. */ 1318 unsigned long key = dev->handle; 1319 hash_table_remove(&tree->devman_devices, &key, 1); 1322 hash_table_remove(&tree->devman_devices, &dev->handle); 1320 1323 1321 1324 /* Unlink from parent function. */ … … 1358 1361 /* Add the node to the handle-to-node map. */ 1359 1362 fun->handle = ++tree->current_handle; 1360 unsigned long key = fun->handle; 1361 hash_table_insert(&tree->devman_functions, &key, &fun->devman_fun); 1363 hash_table_insert(&tree->devman_functions, &fun->devman_fun); 1362 1364 1363 1365 /* Add the node to the list of its parent's children. */ … … 1379 1381 1380 1382 /* Remove the node from the handle-to-node map. */ 1381 unsigned long key = fun->handle; 1382 hash_table_remove(&tree->devman_functions, &key, 1); 1383 hash_table_remove(&tree->devman_functions, &fun->handle); 1383 1384 1384 1385 /* Remove the node from the list of its parent's children. */ … … 1493 1494 { 1494 1495 fun_node_t *fun = NULL; 1495 link_t *link;1496 unsigned long key = (unsigned long) service_id;1497 1496 1498 1497 fibril_rwlock_read_lock(&tree->rwlock); 1499 link = hash_table_find(&tree->loc_functions, &key);1498 ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id); 1500 1499 if (link != NULL) { 1501 fun = hash_table_get_inst ance(link, fun_node_t, loc_fun);1500 fun = hash_table_get_inst(link, fun_node_t, loc_fun); 1502 1501 fun_add_ref(fun); 1503 1502 } … … 1511 1510 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1512 1511 1513 unsigned long key = (unsigned long) fun->service_id; 1514 hash_table_insert(&tree->loc_functions, &key, &fun->loc_fun); 1512 hash_table_insert(&tree->loc_functions, &fun->loc_fun); 1515 1513 } 1516 1514
Note:
See TracChangeset
for help on using the changeset viewer.