Changes in uspace/srv/ns/service.c [b72efe8:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/service.c
rb72efe8 r4e00f87 40 40 #include "ns.h" 41 41 42 #define SERVICE_HASH_TABLE_CHAINS 2043 42 44 43 /** Service hash table item. */ 45 44 typedef struct { 46 link_t link;45 ht_link_t link; 47 46 sysarg_t service; /**< Service ID. */ 48 47 sysarg_t phone; /**< Phone registered with the service. */ … … 50 49 } hashed_service_t; 51 50 52 /** Compute hash index into service hash table. 53 * 54 * @param key Pointer keys. However, only the first key (i.e. service number) 55 * is used to compute the hash index. 56 * 57 * @return Hash index corresponding to key[0]. 58 * 59 */ 60 static hash_index_t service_hash(unsigned long key[]) 51 52 static size_t service_key_hash(void *key) 61 53 { 62 assert(key); 63 return (key[0] % SERVICE_HASH_TABLE_CHAINS); 54 return *(sysarg_t*)key; 64 55 } 65 56 66 /** Compare a key with hashed item. 67 * 68 * This compare function always ignores the third key. 69 * It exists only to make it possible to remove records 70 * originating from connection with key[1] in_phone_hash 71 * value. Note that this is close to being classified 72 * as a nasty hack. 73 * 74 * @param key Array of keys. 75 * @param keys Must be lesser or equal to 3. 76 * @param item Pointer to a hash table item. 77 * 78 * @return Non-zero if the key matches the item, zero otherwise. 79 * 80 */ 81 static int service_compare(unsigned long key[], hash_count_t keys, link_t *item) 57 static size_t service_hash(const ht_link_t *item) 82 58 { 83 assert(key); 84 assert(keys <= 3); 85 assert(item); 86 87 hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link); 88 89 if (keys == 2) 90 return ((key[0] == hs->service) && (key[1] == hs->in_phone_hash)); 91 else 92 return (key[0] == hs->service); 59 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 60 return hs->service; 93 61 } 94 62 95 /** Perform actions after removal of item from the hash table. 96 * 97 * @param item Item that was removed from the hash table. 98 * 99 */ 100 static void service_remove(link_t *item) 63 static bool service_key_equal(void *key, const ht_link_t *item) 101 64 { 102 assert(item);103 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; 104 67 } 105 68 106 69 /** Operations for service hash table. */ 107 static hash_table_op erations_t service_hash_table_ops = {70 static hash_table_ops_t service_hash_table_ops = { 108 71 .hash = service_hash, 109 .compare = service_compare, 110 .remove_callback = service_remove 72 .key_hash = service_key_hash, 73 .key_equal = service_key_equal, 74 .equal = NULL, 75 .remove_callback = NULL 111 76 }; 112 77 … … 127 92 int service_init(void) 128 93 { 129 if (!hash_table_create(&service_hash_table, SERVICE_HASH_TABLE_CHAINS, 130 3, &service_hash_table_ops)) { 94 if (!hash_table_create(&service_hash_table, 0, 0, &service_hash_table_ops)) { 131 95 printf(NAME ": No memory available for services\n"); 132 96 return ENOMEM; … … 145 109 pending_conn_t *pr = list_get_instance(cur, pending_conn_t, link); 146 110 147 unsigned long keys[3] = { 148 pr->service, 149 0, 150 0 151 }; 152 153 link_t *link = hash_table_find(&service_hash_table, keys); 111 ht_link_t *link = hash_table_find(&service_hash_table, &pr->service); 154 112 if (!link) 155 113 continue; 156 114 157 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); 158 116 (void) ipc_forward_fast(pr->callid, hs->phone, pr->arg2, 159 117 pr->arg3, 0, IPC_FF_NONE); … … 176 134 int register_service(sysarg_t service, sysarg_t phone, ipc_call_t *call) 177 135 { 178 unsigned long keys[3] = { 179 service, 180 call->in_phone_hash, 181 0 182 }; 183 184 if (hash_table_find(&service_hash_table, keys)) 136 if (hash_table_find(&service_hash_table, &service)) 185 137 return EEXISTS; 186 138 … … 189 141 return ENOMEM; 190 142 191 link_initialize(&hs->link);192 143 hs->service = service; 193 144 hs->phone = phone; 194 145 hs->in_phone_hash = call->in_phone_hash; 195 hash_table_insert(&service_hash_table, keys,&hs->link);146 hash_table_insert(&service_hash_table, &hs->link); 196 147 197 148 return EOK; … … 210 161 { 211 162 sysarg_t retval; 212 unsigned long keys[3] = {213 service,214 0,215 0216 };217 163 218 link_t *link = hash_table_find(&service_hash_table, keys);164 ht_link_t *link = hash_table_find(&service_hash_table, &service); 219 165 if (!link) { 220 166 if (IPC_GET_ARG4(*call) & IPC_FLAG_BLOCKING) { … … 239 185 } 240 186 241 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); 242 188 (void) ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call), 243 189 IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
Note:
See TracChangeset
for help on using the changeset viewer.