Changes in uspace/srv/fs/locfs/locfs_ops.c [9d58539:bc216a0] in mainline
- File:
-
- 1 edited
-
uspace/srv/fs/locfs/locfs_ops.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/locfs/locfs_ops.c
r9d58539 rbc216a0 61 61 async_sess_t *sess; /**< If NULL, the structure is incomplete. */ 62 62 size_t refcount; 63 link_t link;63 ht_link_t link; 64 64 fibril_condvar_t cv; /**< Broadcast when completed. */ 65 65 } service_t; … … 71 71 static FIBRIL_MUTEX_INITIALIZE(services_mutex); 72 72 73 #define SERVICES_KEYS 174 #define SERVICES_KEY_HANDLE 075 #define SERVICES_BUCKETS 25676 77 73 /* Implementation of hash table interface for the nodes hash table. */ 78 static hash_index_t services_hash(unsigned long key[]) 79 { 80 return key[SERVICES_KEY_HANDLE] % SERVICES_BUCKETS; 81 } 82 83 static int services_compare(unsigned long key[], hash_count_t keys, link_t *item) 84 { 85 service_t *dev = hash_table_get_instance(item, service_t, link); 86 return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]); 87 } 88 89 static void services_remove_callback(link_t *item) 90 { 91 free(hash_table_get_instance(item, service_t, link)); 92 } 93 94 static hash_table_operations_t services_ops = { 74 75 static size_t services_key_hash(void *key) 76 { 77 return *(service_id_t*)key; 78 } 79 80 static size_t services_hash(const ht_link_t *item) 81 { 82 service_t *dev = hash_table_get_inst(item, service_t, link); 83 return dev->service_id; 84 } 85 86 static bool services_key_equal(void *key, const ht_link_t *item) 87 { 88 service_t *dev = hash_table_get_inst(item, service_t, link); 89 return (dev->service_id == *(service_id_t*)key); 90 } 91 92 static void services_remove_callback(ht_link_t *item) 93 { 94 free(hash_table_get_inst(item, service_t, link)); 95 } 96 97 static hash_table_ops_t services_ops = { 95 98 .hash = services_hash, 96 .compare = services_compare, 99 .key_hash = services_key_hash, 100 .key_equal = services_key_equal, 101 .equal = 0, 97 102 .remove_callback = services_remove_callback 98 103 }; … … 229 234 /* Device node */ 230 235 231 unsigned long key[] = {232 [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id233 };234 link_t *lnk;235 236 236 fibril_mutex_lock(&services_mutex); 237 ht_link_t *lnk; 237 238 restart: 238 lnk = hash_table_find(&services, key);239 lnk = hash_table_find(&services, &node->service_id); 239 240 if (lnk == NULL) { 240 241 service_t *dev = (service_t *) malloc(sizeof(service_t)); … … 256 257 * below. 257 258 */ 258 hash_table_insert(&services, key,&dev->link);259 hash_table_insert(&services, &dev->link); 259 260 260 261 /* … … 279 280 * entry and free the device structure. 280 281 */ 281 hash_table_remove(&services, key, SERVICES_KEYS);282 hash_table_remove(&services, &node->service_id); 282 283 fibril_mutex_unlock(&services_mutex); 283 284 … … 288 289 dev->sess = sess; 289 290 } else { 290 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);291 service_t *dev = hash_table_get_inst(lnk, service_t, link); 291 292 292 293 if (!dev->sess) { … … 450 451 bool locfs_init(void) 451 452 { 452 if (!hash_table_create(&services, SERVICES_BUCKETS, 453 SERVICES_KEYS, &services_ops)) 453 if (!hash_table_create(&services, 0, 0, &services_ops)) 454 454 return false; 455 455 … … 555 555 /* Device node */ 556 556 557 unsigned long key[] = {558 [SERVICES_KEY_HANDLE] = (unsigned long) index559 };560 561 557 fibril_mutex_lock(&services_mutex); 562 link_t *lnk = hash_table_find(&services, key);558 ht_link_t *lnk = hash_table_find(&services, &index); 563 559 if (lnk == NULL) { 564 560 fibril_mutex_unlock(&services_mutex); … … 566 562 } 567 563 568 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);564 service_t *dev = hash_table_get_inst(lnk, service_t, link); 569 565 assert(dev->sess); 570 566 … … 621 617 if (type == LOC_OBJECT_SERVICE) { 622 618 /* Device node */ 623 unsigned long key[] = {624 [SERVICES_KEY_HANDLE] = (unsigned long) index625 };626 619 627 620 fibril_mutex_lock(&services_mutex); 628 link_t *lnk = hash_table_find(&services, key);621 ht_link_t *lnk = hash_table_find(&services, &index); 629 622 if (lnk == NULL) { 630 623 fibril_mutex_unlock(&services_mutex); … … 632 625 } 633 626 634 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);627 service_t *dev = hash_table_get_inst(lnk, service_t, link); 635 628 assert(dev->sess); 636 629 … … 691 684 692 685 if (type == LOC_OBJECT_SERVICE) { 693 unsigned long key[] = {694 [SERVICES_KEY_HANDLE] = (unsigned long) index695 };696 686 697 687 fibril_mutex_lock(&services_mutex); 698 link_t *lnk = hash_table_find(&services, key);688 ht_link_t *lnk = hash_table_find(&services, &index); 699 689 if (lnk == NULL) { 700 690 fibril_mutex_unlock(&services_mutex); … … 702 692 } 703 693 704 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);694 service_t *dev = hash_table_get_inst(lnk, service_t, link); 705 695 assert(dev->sess); 706 696 dev->refcount--; … … 708 698 if (dev->refcount == 0) { 709 699 async_hangup(dev->sess); 710 hash_table_remove(&services, key, SERVICES_KEYS);700 hash_table_remove(&services, &index); 711 701 } 712 702 … … 732 722 733 723 if (type == LOC_OBJECT_SERVICE) { 734 unsigned long key[] = { 735 [SERVICES_KEY_HANDLE] = (unsigned long) index 736 }; 737 724 738 725 fibril_mutex_lock(&services_mutex); 739 link_t *lnk = hash_table_find(&services, key);726 ht_link_t *lnk = hash_table_find(&services, &index); 740 727 if (lnk == NULL) { 741 728 fibril_mutex_unlock(&services_mutex); … … 743 730 } 744 731 745 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);732 service_t *dev = hash_table_get_inst(lnk, service_t, link); 746 733 assert(dev->sess); 747 734
Note:
See TracChangeset
for help on using the changeset viewer.
