Changeset bc216a0 in mainline for uspace/srv/fs/locfs/locfs_ops.c
- Timestamp:
- 2012-08-07T22:13:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/locfs/locfs_ops.c
rb17518e 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 76 73 /* Implementation of hash table interface for the nodes hash table. */ 77 74 78 static size_t services_key_hash(unsigned long key[]) 79 { 80 return key[SERVICES_KEY_HANDLE]; 81 } 82 83 static size_t services_hash(const link_t *item) 84 { 85 service_t *dev = hash_table_get_instance(item, service_t, link); 86 unsigned long key[] = { 87 [SERVICES_KEY_HANDLE] = dev->service_id 88 }; 89 90 return services_key_hash(key); 91 } 92 93 static bool services_match(unsigned long key[], size_t keys, const link_t *item) 94 { 95 assert(keys == 1); 96 service_t *dev = hash_table_get_instance(item, service_t, link); 97 return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]); 98 } 99 100 static void services_remove_callback(link_t *item) 101 { 102 free(hash_table_get_instance(item, service_t, link)); 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)); 103 95 } 104 96 … … 106 98 .hash = services_hash, 107 99 .key_hash = services_key_hash, 108 . match = services_match,100 .key_equal = services_key_equal, 109 101 .equal = 0, 110 102 .remove_callback = services_remove_callback … … 242 234 /* Device node */ 243 235 244 unsigned long key[] = {245 [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id246 };247 link_t *lnk;248 249 236 fibril_mutex_lock(&services_mutex); 237 ht_link_t *lnk; 250 238 restart: 251 lnk = hash_table_find(&services, key);239 lnk = hash_table_find(&services, &node->service_id); 252 240 if (lnk == NULL) { 253 241 service_t *dev = (service_t *) malloc(sizeof(service_t)); … … 292 280 * entry and free the device structure. 293 281 */ 294 hash_table_remove(&services, key, SERVICES_KEYS);282 hash_table_remove(&services, &node->service_id); 295 283 fibril_mutex_unlock(&services_mutex); 296 284 … … 301 289 dev->sess = sess; 302 290 } else { 303 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);291 service_t *dev = hash_table_get_inst(lnk, service_t, link); 304 292 305 293 if (!dev->sess) { … … 463 451 bool locfs_init(void) 464 452 { 465 if (!hash_table_create(&services, 0, SERVICES_KEYS, &services_ops))453 if (!hash_table_create(&services, 0, 0, &services_ops)) 466 454 return false; 467 455 … … 567 555 /* Device node */ 568 556 569 unsigned long key[] = {570 [SERVICES_KEY_HANDLE] = (unsigned long) index571 };572 573 557 fibril_mutex_lock(&services_mutex); 574 link_t *lnk = hash_table_find(&services, key);558 ht_link_t *lnk = hash_table_find(&services, &index); 575 559 if (lnk == NULL) { 576 560 fibril_mutex_unlock(&services_mutex); … … 578 562 } 579 563 580 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);564 service_t *dev = hash_table_get_inst(lnk, service_t, link); 581 565 assert(dev->sess); 582 566 … … 633 617 if (type == LOC_OBJECT_SERVICE) { 634 618 /* Device node */ 635 unsigned long key[] = {636 [SERVICES_KEY_HANDLE] = (unsigned long) index637 };638 619 639 620 fibril_mutex_lock(&services_mutex); 640 link_t *lnk = hash_table_find(&services, key);621 ht_link_t *lnk = hash_table_find(&services, &index); 641 622 if (lnk == NULL) { 642 623 fibril_mutex_unlock(&services_mutex); … … 644 625 } 645 626 646 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);627 service_t *dev = hash_table_get_inst(lnk, service_t, link); 647 628 assert(dev->sess); 648 629 … … 703 684 704 685 if (type == LOC_OBJECT_SERVICE) { 705 unsigned long key[] = {706 [SERVICES_KEY_HANDLE] = (unsigned long) index707 };708 686 709 687 fibril_mutex_lock(&services_mutex); 710 link_t *lnk = hash_table_find(&services, key);688 ht_link_t *lnk = hash_table_find(&services, &index); 711 689 if (lnk == NULL) { 712 690 fibril_mutex_unlock(&services_mutex); … … 714 692 } 715 693 716 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);694 service_t *dev = hash_table_get_inst(lnk, service_t, link); 717 695 assert(dev->sess); 718 696 dev->refcount--; … … 720 698 if (dev->refcount == 0) { 721 699 async_hangup(dev->sess); 722 hash_table_remove(&services, key, SERVICES_KEYS);700 hash_table_remove(&services, &index); 723 701 } 724 702 … … 744 722 745 723 if (type == LOC_OBJECT_SERVICE) { 746 unsigned long key[] = { 747 [SERVICES_KEY_HANDLE] = (unsigned long) index 748 }; 749 724 750 725 fibril_mutex_lock(&services_mutex); 751 link_t *lnk = hash_table_find(&services, key);726 ht_link_t *lnk = hash_table_find(&services, &index); 752 727 if (lnk == NULL) { 753 728 fibril_mutex_unlock(&services_mutex); … … 755 730 } 756 731 757 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);732 service_t *dev = hash_table_get_inst(lnk, service_t, link); 758 733 assert(dev->sess); 759 734
Note:
See TracChangeset
for help on using the changeset viewer.