Changeset 062d900 in mainline for uspace/srv/fs/locfs/locfs_ops.c
- Timestamp:
- 2012-10-09T11:49:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4e00f87
- Parents:
- 87e9392
- git-author:
- Adam Hraska <adam.hraska+hos@…> (2012-10-09 11:49:43)
- git-committer:
- Jakub Jermar <jakub@…> (2012-10-09 11:49:43)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/locfs/locfs_ops.c
r87e9392 r062d900 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 service_id_t service_index = index; 559 ht_link_t *lnk = hash_table_find(&services, &service_index); 563 560 if (lnk == NULL) { 564 561 fibril_mutex_unlock(&services_mutex); … … 566 563 } 567 564 568 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);565 service_t *dev = hash_table_get_inst(lnk, service_t, link); 569 566 assert(dev->sess); 570 567 … … 621 618 if (type == LOC_OBJECT_SERVICE) { 622 619 /* Device node */ 623 unsigned long key[] = {624 [SERVICES_KEY_HANDLE] = (unsigned long) index625 };626 620 627 621 fibril_mutex_lock(&services_mutex); 628 link_t *lnk = hash_table_find(&services, key); 622 service_id_t service_index = index; 623 ht_link_t *lnk = hash_table_find(&services, &service_index); 629 624 if (lnk == NULL) { 630 625 fibril_mutex_unlock(&services_mutex); … … 632 627 } 633 628 634 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);629 service_t *dev = hash_table_get_inst(lnk, service_t, link); 635 630 assert(dev->sess); 636 631 … … 691 686 692 687 if (type == LOC_OBJECT_SERVICE) { 693 unsigned long key[] = {694 [SERVICES_KEY_HANDLE] = (unsigned long) index695 };696 688 697 689 fibril_mutex_lock(&services_mutex); 698 link_t *lnk = hash_table_find(&services, key); 690 service_id_t service_index = index; 691 ht_link_t *lnk = hash_table_find(&services, &service_index); 699 692 if (lnk == NULL) { 700 693 fibril_mutex_unlock(&services_mutex); … … 702 695 } 703 696 704 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);697 service_t *dev = hash_table_get_inst(lnk, service_t, link); 705 698 assert(dev->sess); 706 699 dev->refcount--; … … 708 701 if (dev->refcount == 0) { 709 702 async_hangup(dev->sess); 710 hash_table_remove(&services, key, SERVICES_KEYS); 703 service_id_t service_index = index; 704 hash_table_remove(&services, &service_index); 711 705 } 712 706 … … 732 726 733 727 if (type == LOC_OBJECT_SERVICE) { 734 unsigned long key[] = { 735 [SERVICES_KEY_HANDLE] = (unsigned long) index 736 }; 737 728 738 729 fibril_mutex_lock(&services_mutex); 739 link_t *lnk = hash_table_find(&services, key); 730 service_id_t service_index = index; 731 ht_link_t *lnk = hash_table_find(&services, &service_index); 740 732 if (lnk == NULL) { 741 733 fibril_mutex_unlock(&services_mutex); … … 743 735 } 744 736 745 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);737 service_t *dev = hash_table_get_inst(lnk, service_t, link); 746 738 assert(dev->sess); 747 739
Note:
See TracChangeset
for help on using the changeset viewer.