Changes in uspace/srv/ns/task.c [007e6efa:96b02eb9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/task.c
r007e6efa r96b02eb9 43 43 44 44 #define TASK_HASH_TABLE_CHAINS 256 45 #define P2I_HASH_TABLE_CHAINS 256 45 #define P2I_HASH_TABLE_CHAINS 256 46 47 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id); 46 48 47 49 /* TODO: … … 55 57 typedef struct { 56 58 link_t link; 57 58 task_id_t id; /**< Task ID. */ 59 bool finished; /**< Task is done. */ 60 bool have_rval; /**< Task returned a value. */ 61 int retval; /**< The return value. */ 59 task_id_t id; /**< Task ID. */ 60 bool finished; /**< Task is done. */ 61 bool have_rval; /**< Task returned a value. */ 62 int retval; /**< The return value. */ 62 63 } hashed_task_t; 63 64 … … 70 71 * 71 72 */ 72 static hash_index_t task_hash(unsigned long key[])73 static hash_index_t task_hash(unsigned long *key) 73 74 { 74 75 assert(key); 75 return (LOWER32( key[0]) % TASK_HASH_TABLE_CHAINS);76 return (LOWER32(*key) % TASK_HASH_TABLE_CHAINS); 76 77 } 77 78 … … 123 124 typedef struct { 124 125 link_t link; 125 sysarg_t in_phone_hash; /**< Incoming phone hash. */126 task_id_t id; 126 sysarg_t phash; /**< Task ID. */ 127 task_id_t id; /**< Task ID. */ 127 128 } p2i_entry_t; 128 129 … … 130 131 * 131 132 * @param key Array of keys. 132 *133 133 * @return Hash index corresponding to key[0]. 134 134 * 135 135 */ 136 static hash_index_t p2i_hash(unsigned long key[])136 static hash_index_t p2i_hash(unsigned long *key) 137 137 { 138 138 assert(key); 139 return ( key[0]% TASK_HASH_TABLE_CHAINS);139 return (*key % TASK_HASH_TABLE_CHAINS); 140 140 } 141 141 … … 154 154 assert(keys == 1); 155 155 assert(item); 156 157 p2i_entry_t *e ntry= hash_table_get_instance(item, p2i_entry_t, link);158 159 return (key[0] == e ntry->in_phone_hash);156 157 p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link); 158 159 return (key[0] == e->phash); 160 160 } 161 161 … … 197 197 return ENOMEM; 198 198 } 199 199 200 200 if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS, 201 201 1, &p2i_ops)) { … … 205 205 206 206 list_initialize(&pending_wait); 207 207 208 return EOK; 208 209 } … … 237 238 ht->retval); 238 239 } 239 240 240 241 hash_table_remove(&task_hash_table, keys, 2); 241 242 list_remove(cur); … … 249 250 sysarg_t retval; 250 251 task_exit_t texit; 251 252 252 253 unsigned long keys[2] = { 253 254 LOWER32(id), 254 255 UPPER32(id) 255 256 }; 256 257 257 258 link_t *link = hash_table_find(&task_hash_table, keys); 258 259 hashed_task_t *ht = (link != NULL) ? 259 260 hash_table_get_instance(link, hashed_task_t, link) : NULL; 260 261 261 262 if (ht == NULL) { 262 263 /* No such task exists. */ … … 264 265 return; 265 266 } 266 267 267 268 if (!ht->finished) { 268 269 /* Add to pending list */ … … 274 275 } 275 276 276 link_initialize(&pr->link);277 277 pr->id = id; 278 278 pr->callid = callid; … … 293 293 int ns_task_id_intro(ipc_call_t *call) 294 294 { 295 task_id_t id; 295 296 unsigned long keys[2]; 296 297 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 297 link_t *link; 298 p2i_entry_t *e; 299 hashed_task_t *ht; 300 301 id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 302 298 303 keys[0] = call->in_phone_hash; 299 300 link _t *link= hash_table_find(&phone_to_id, keys);304 305 link = hash_table_find(&phone_to_id, keys); 301 306 if (link != NULL) 302 307 return EEXISTS; 303 304 p2i_entry_t *entry= (p2i_entry_t *) malloc(sizeof(p2i_entry_t));305 if (e ntry== NULL)308 309 e = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); 310 if (e == NULL) 306 311 return ENOMEM; 307 308 h ashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));312 313 ht = (hashed_task_t *) malloc(sizeof(hashed_task_t)); 309 314 if (ht == NULL) 310 315 return ENOMEM; 311 312 /* 313 * Insert into the phone-to-id map. 314 */ 315 316 link_initialize(&entry->link); 317 entry->in_phone_hash = call->in_phone_hash; 318 entry->id = id; 319 hash_table_insert(&phone_to_id, keys, &entry->link); 320 321 /* 322 * Insert into the main table. 323 */ 324 316 317 /* Insert to phone-to-id map. */ 318 319 link_initialize(&e->link); 320 e->phash = call->in_phone_hash; 321 e->id = id; 322 hash_table_insert(&phone_to_id, keys, &e->link); 323 324 /* Insert to main table. */ 325 325 326 keys[0] = LOWER32(id); 326 327 keys[1] = UPPER32(id); 327 328 328 329 link_initialize(&ht->link); 329 330 ht->id = id; … … 332 333 ht->retval = -1; 333 334 hash_table_insert(&task_hash_table, keys, &ht->link); 334 335 335 336 return EOK; 336 337 } 337 338 338 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id)339 {340 unsigned long keys[1] = {phone_hash};341 342 link_t *link = hash_table_find(&phone_to_id, keys);343 if (link == NULL)344 return ENOENT;345 346 p2i_entry_t *entry = hash_table_get_instance(link, p2i_entry_t, link);347 *id = entry->id;348 349 return EOK;350 }351 352 339 int ns_task_retval(ipc_call_t *call) 353 340 { 354 341 task_id_t id; 355 int rc = get_id_by_phone(call->in_phone_hash, &id); 342 unsigned long keys[2]; 343 int rc; 344 345 rc = get_id_by_phone(call->in_phone_hash, &id); 356 346 if (rc != EOK) 357 347 return rc; 358 359 unsigned long keys[2] = { 360 LOWER32(id), 361 UPPER32(id) 362 }; 348 349 keys[0] = LOWER32(id); 350 keys[1] = UPPER32(id); 363 351 364 352 link_t *link = hash_table_find(&task_hash_table, keys); … … 366 354 hash_table_get_instance(link, hashed_task_t, link) : NULL; 367 355 368 if ((ht == NULL) || (ht->finished))356 if ((ht == NULL) || ht->finished) 369 357 return EINVAL; 370 358 371 359 ht->finished = true; 372 360 ht->have_rval = true; 373 361 ht->retval = IPC_GET_ARG1(*call); 374 362 375 363 return EOK; 376 364 } … … 379 367 { 380 368 unsigned long keys[2]; 381 382 369 task_id_t id; 383 int rc = get_id_by_phone(call->in_phone_hash, &id); 370 int rc; 371 372 rc = get_id_by_phone(call->in_phone_hash, &id); 384 373 if (rc != EOK) 385 374 return rc; 386 375 387 376 /* Delete from phone-to-id map. */ 388 377 keys[0] = call->in_phone_hash; 389 378 hash_table_remove(&phone_to_id, keys, 1); 390 379 391 380 /* Mark task as finished. */ 392 381 keys[0] = LOWER32(id); 393 382 keys[1] = UPPER32(id); 394 383 395 384 link_t *link = hash_table_find(&task_hash_table, keys); 396 385 hashed_task_t *ht = … … 398 387 if (ht == NULL) 399 388 return EOK; 400 389 401 390 ht->finished = true; 402 391 392 return EOK; 393 } 394 395 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id) 396 { 397 unsigned long keys[1]; 398 link_t *link; 399 p2i_entry_t *e; 400 401 keys[0] = phone_hash; 402 link = hash_table_find(&phone_to_id, keys); 403 if (link == NULL) 404 return ENOENT; 405 406 e = hash_table_get_instance(link, p2i_entry_t, link); 407 *id = e->id; 408 403 409 return EOK; 404 410 }
Note:
See TracChangeset
for help on using the changeset viewer.