Changes in uspace/srv/fs/locfs/locfs_ops.c [3e6a98c5:086290d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/locfs/locfs_ops.c
r3e6a98c5 r086290d 37 37 38 38 #include <macros.h> 39 #include < stdbool.h>39 #include <bool.h> 40 40 #include <errno.h> 41 41 #include <malloc.h> … … 61 61 async_sess_t *sess; /**< If NULL, the structure is incomplete. */ 62 62 size_t refcount; 63 ht_link_t link;63 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 1 74 #define SERVICES_KEY_HANDLE 0 75 #define SERVICES_BUCKETS 256 76 73 77 /* Implementation of hash table interface for the nodes hash table. */ 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 = { 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 = { 98 95 .hash = services_hash, 99 .key_hash = services_key_hash, 100 .key_equal = services_key_equal, 101 .equal = NULL, 96 .compare = services_compare, 102 97 .remove_callback = services_remove_callback 103 98 }; … … 234 229 /* Device node */ 235 230 231 unsigned long key[] = { 232 [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id 233 }; 234 link_t *lnk; 235 236 236 fibril_mutex_lock(&services_mutex); 237 ht_link_t *lnk;238 237 restart: 239 lnk = hash_table_find(&services, &node->service_id);238 lnk = hash_table_find(&services, key); 240 239 if (lnk == NULL) { 241 240 service_t *dev = (service_t *) malloc(sizeof(service_t)); … … 257 256 * below. 258 257 */ 259 hash_table_insert(&services, &dev->link);258 hash_table_insert(&services, key, &dev->link); 260 259 261 260 /* … … 280 279 * entry and free the device structure. 281 280 */ 282 hash_table_remove(&services, &node->service_id);281 hash_table_remove(&services, key, SERVICES_KEYS); 283 282 fibril_mutex_unlock(&services_mutex); 284 283 … … 289 288 dev->sess = sess; 290 289 } else { 291 service_t *dev = hash_table_get_inst (lnk, service_t, link);290 service_t *dev = hash_table_get_instance(lnk, service_t, link); 292 291 293 292 if (!dev->sess) { … … 451 450 bool locfs_init(void) 452 451 { 453 if (!hash_table_create(&services, 0, 0, &services_ops)) 452 if (!hash_table_create(&services, SERVICES_BUCKETS, 453 SERVICES_KEYS, &services_ops)) 454 454 return false; 455 455 … … 555 555 /* Device node */ 556 556 557 unsigned long key[] = { 558 [SERVICES_KEY_HANDLE] = (unsigned long) index 559 }; 560 557 561 fibril_mutex_lock(&services_mutex); 558 service_id_t service_index = index; 559 ht_link_t *lnk = hash_table_find(&services, &service_index); 562 link_t *lnk = hash_table_find(&services, key); 560 563 if (lnk == NULL) { 561 564 fibril_mutex_unlock(&services_mutex); … … 563 566 } 564 567 565 service_t *dev = hash_table_get_inst (lnk, service_t, link);568 service_t *dev = hash_table_get_instance(lnk, service_t, link); 566 569 assert(dev->sess); 567 570 … … 618 621 if (type == LOC_OBJECT_SERVICE) { 619 622 /* Device node */ 623 unsigned long key[] = { 624 [SERVICES_KEY_HANDLE] = (unsigned long) index 625 }; 620 626 621 627 fibril_mutex_lock(&services_mutex); 622 service_id_t service_index = index; 623 ht_link_t *lnk = hash_table_find(&services, &service_index); 628 link_t *lnk = hash_table_find(&services, key); 624 629 if (lnk == NULL) { 625 630 fibril_mutex_unlock(&services_mutex); … … 627 632 } 628 633 629 service_t *dev = hash_table_get_inst (lnk, service_t, link);634 service_t *dev = hash_table_get_instance(lnk, service_t, link); 630 635 assert(dev->sess); 631 636 … … 686 691 687 692 if (type == LOC_OBJECT_SERVICE) { 693 unsigned long key[] = { 694 [SERVICES_KEY_HANDLE] = (unsigned long) index 695 }; 688 696 689 697 fibril_mutex_lock(&services_mutex); 690 service_id_t service_index = index; 691 ht_link_t *lnk = hash_table_find(&services, &service_index); 698 link_t *lnk = hash_table_find(&services, key); 692 699 if (lnk == NULL) { 693 700 fibril_mutex_unlock(&services_mutex); … … 695 702 } 696 703 697 service_t *dev = hash_table_get_inst (lnk, service_t, link);704 service_t *dev = hash_table_get_instance(lnk, service_t, link); 698 705 assert(dev->sess); 699 706 dev->refcount--; … … 701 708 if (dev->refcount == 0) { 702 709 async_hangup(dev->sess); 703 service_id_t service_index = index; 704 hash_table_remove(&services, &service_index); 710 hash_table_remove(&services, key, SERVICES_KEYS); 705 711 } 706 712 … … 726 732 727 733 if (type == LOC_OBJECT_SERVICE) { 728 734 unsigned long key[] = { 735 [SERVICES_KEY_HANDLE] = (unsigned long) index 736 }; 737 729 738 fibril_mutex_lock(&services_mutex); 730 service_id_t service_index = index; 731 ht_link_t *lnk = hash_table_find(&services, &service_index); 739 link_t *lnk = hash_table_find(&services, key); 732 740 if (lnk == NULL) { 733 741 fibril_mutex_unlock(&services_mutex); … … 735 743 } 736 744 737 service_t *dev = hash_table_get_inst (lnk, service_t, link);745 service_t *dev = hash_table_get_instance(lnk, service_t, link); 738 746 assert(dev->sess); 739 747
Note:
See TracChangeset
for help on using the changeset viewer.