Changeset bc216a0 in mainline for uspace/srv/ns/service.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/ns/service.c
rb17518e rbc216a0 43 43 /** Service hash table item. */ 44 44 typedef struct { 45 link_t link;45 ht_link_t link; 46 46 sysarg_t service; /**< Service ID. */ 47 47 sysarg_t phone; /**< Phone registered with the service. */ … … 49 49 } hashed_service_t; 50 50 51 /** Compute hash index into service hash table. 52 * 53 * @param key Pointer keys. However, only the first key (i.e. service number) 54 * is used to compute the hash index. 55 * 56 * @return Hash index corresponding to key[0]. 57 * 58 */ 59 static size_t service_key_hash(unsigned long key[]) 51 52 static size_t service_key_hash(void *key) 60 53 { 61 assert(key); 62 return key[0]; 54 return *(sysarg_t*)key; 63 55 } 64 56 65 static size_t service_hash(const link_t *item)57 static size_t service_hash(const ht_link_t *item) 66 58 { 67 hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link); 68 unsigned long key = hs->service; 69 return service_key_hash(&key); 59 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 60 return hs->service; 70 61 } 71 62 72 /** Compare a key with hashed item. 73 * 74 * This compare function always ignores the third key. 75 * It exists only to make it possible to remove records 76 * originating from connection with key[1] in_phone_hash 77 * value. Note that this is close to being classified 78 * as a nasty hack. 79 * 80 * @param key Array of keys. 81 * @param keys Must be lesser or equal to 3. 82 * @param item Pointer to a hash table item. 83 * 84 * @return Non-zero if the key matches the item, zero otherwise. 85 * 86 */ 87 static bool service_match(unsigned long key[], size_t keys, const link_t *item) 63 static bool service_key_equal(void *key, const ht_link_t *item) 88 64 { 89 assert(key); 90 assert(keys <= 3); 91 assert(item); 92 93 hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link); 94 95 if (keys == 2) 96 return ((key[0] == hs->service) && (key[1] == hs->in_phone_hash)); 97 else 98 return (key[0] == hs->service); 99 } 100 101 /** Perform actions after removal of item from the hash table. 102 * 103 * @param item Item that was removed from the hash table. 104 * 105 */ 106 static void service_remove(link_t *item) 107 { 108 assert(item); 109 free(hash_table_get_instance(item, hashed_service_t, link)); 65 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 66 return hs->service == *(sysarg_t*)key; 110 67 } 111 68 … … 114 71 .hash = service_hash, 115 72 .key_hash = service_key_hash, 116 . match = service_match,73 .key_equal = service_key_equal, 117 74 .equal = 0, 118 .remove_callback = service_remove75 .remove_callback = 0 119 76 }; 120 77 … … 135 92 int service_init(void) 136 93 { 137 if (!hash_table_create(&service_hash_table, 0, 3, &service_hash_table_ops)) {94 if (!hash_table_create(&service_hash_table, 0, 0, &service_hash_table_ops)) { 138 95 printf(NAME ": No memory available for services\n"); 139 96 return ENOMEM; … … 152 109 pending_conn_t *pr = list_get_instance(cur, pending_conn_t, link); 153 110 154 unsigned long keys[3] = { 155 pr->service, 156 0, 157 0 158 }; 159 160 link_t *link = hash_table_find(&service_hash_table, keys); 111 ht_link_t *link = hash_table_find(&service_hash_table, &pr->service); 161 112 if (!link) 162 113 continue; 163 114 164 hashed_service_t *hs = hash_table_get_inst ance(link, hashed_service_t, link);115 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 165 116 (void) ipc_forward_fast(pr->callid, hs->phone, pr->arg2, 166 117 pr->arg3, 0, IPC_FF_NONE); … … 183 134 int register_service(sysarg_t service, sysarg_t phone, ipc_call_t *call) 184 135 { 185 unsigned long keys[3] = { 186 service, 187 call->in_phone_hash, 188 0 189 }; 190 191 if (hash_table_find(&service_hash_table, keys)) 136 if (hash_table_find(&service_hash_table, &service)) 192 137 return EEXISTS; 193 138 … … 196 141 return ENOMEM; 197 142 198 link_initialize(&hs->link);199 143 hs->service = service; 200 144 hs->phone = phone; … … 217 161 { 218 162 sysarg_t retval; 219 unsigned long keys[3] = {220 service,221 0,222 0223 };224 163 225 link_t *link = hash_table_find(&service_hash_table, keys);164 ht_link_t *link = hash_table_find(&service_hash_table, &service); 226 165 if (!link) { 227 166 if (IPC_GET_ARG4(*call) & IPC_FLAG_BLOCKING) { … … 246 185 } 247 186 248 hashed_service_t *hs = hash_table_get_inst ance(link, hashed_service_t, link);187 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 249 188 (void) ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call), 250 189 IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
Note:
See TracChangeset
for help on using the changeset viewer.