Changeset bc216a0 in mainline for uspace/lib/c/generic/async.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/lib/c/generic/async.c
rb17518e rbc216a0 202 202 /* Client connection data */ 203 203 typedef struct { 204 link_t link;204 ht_link_t link; 205 205 206 206 task_id_t in_task_id; … … 214 214 215 215 /** Hash table link. */ 216 link_t link;216 ht_link_t link; 217 217 218 218 /** Incoming client task ID. */ … … 390 390 static LIST_INITIALIZE(timeout_list); 391 391 392 static size_t client_key_hash(unsigned long key[]) 393 { 394 assert(key); 395 /* LOWER32(in_task_id) */ 396 return key[0] >> 4; 397 } 398 399 static size_t client_hash(const link_t *item) 400 { 401 client_t *client = hash_table_get_instance(item, client_t, link); 402 403 unsigned long key[2] = { 404 LOWER32(client->in_task_id), 405 UPPER32(client->in_task_id), 406 }; 407 408 return client_key_hash(key); 409 } 410 411 static bool client_match(unsigned long key[], size_t keys, const link_t *item) 412 { 413 assert(key); 414 assert(keys == 2); 415 assert(item); 416 417 client_t *client = hash_table_get_instance(item, client_t, link); 418 return (key[0] == LOWER32(client->in_task_id) && 419 (key[1] == UPPER32(client->in_task_id))); 392 static size_t client_key_hash(void *k) 393 { 394 task_id_t key = *(task_id_t*)k; 395 return key; 396 } 397 398 static size_t client_hash(const ht_link_t *item) 399 { 400 client_t *client = hash_table_get_inst(item, client_t, link); 401 return client_key_hash(&client->in_task_id); 402 } 403 404 static bool client_key_equal(void *k, const ht_link_t *item) 405 { 406 task_id_t key = *(task_id_t*)k; 407 client_t *client = hash_table_get_inst(item, client_t, link); 408 return key == client->in_task_id; 420 409 } 421 410 … … 425 414 .hash = client_hash, 426 415 .key_hash = client_key_hash, 427 . match = client_match,416 .key_equal = client_key_equal, 428 417 .equal = 0, 429 418 .remove_callback = 0 … … 437 426 * 438 427 */ 439 static size_t conn_key_hash(unsigned long key[]) 440 { 441 assert(key); 442 return key[0] >> 4; 443 } 444 445 static size_t conn_hash(const link_t *item) 446 { 447 connection_t *conn = hash_table_get_instance(item, connection_t, link); 448 unsigned long key = conn->in_phone_hash; 449 return conn_key_hash(&key); 450 } 451 452 /** Compare hash table item with a key. 453 * 454 * @param key Array containing the source phone hash as the only item. 455 * @param keys Expected 1 but ignored. 456 * @param item Connection hash table item. 457 * 458 * @return True on match, false otherwise. 459 * 460 */ 461 static bool conn_match(unsigned long key[], size_t keys, const link_t *item) 462 { 463 assert(key); 464 assert(item); 465 466 connection_t *conn = hash_table_get_instance(item, connection_t, link); 467 return (key[0] == conn->in_phone_hash); 468 } 469 470 static bool conn_equal(const link_t *item1, const link_t *item2) 471 { 472 connection_t *c1 = hash_table_get_instance(item1, connection_t, link); 473 connection_t *c2 = hash_table_get_instance(item2, connection_t, link); 474 475 return c1->in_phone_hash == c2->in_phone_hash; 476 } 477 478 static void conn_remove(link_t *item) 479 { 480 } 428 static size_t conn_key_hash(void *key) 429 { 430 sysarg_t in_phone_hash = *(sysarg_t*)key; 431 return in_phone_hash ; 432 } 433 434 static size_t conn_hash(const ht_link_t *item) 435 { 436 connection_t *conn = hash_table_get_inst(item, connection_t, link); 437 return conn_key_hash(&conn->in_phone_hash); 438 } 439 440 static bool conn_key_equal(void *key, const ht_link_t *item) 441 { 442 sysarg_t in_phone_hash = *(sysarg_t*)key; 443 connection_t *conn = hash_table_get_inst(item, connection_t, link); 444 return (in_phone_hash == conn->in_phone_hash); 445 } 446 481 447 482 448 /** Operations for the connection hash table. */ … … 484 450 .hash = conn_hash, 485 451 .key_hash = conn_key_hash, 486 . match = conn_match,487 .equal = conn_equal,488 .remove_callback = conn_remove452 .key_equal = conn_key_equal, 453 .equal = 0, 454 .remove_callback = 0 489 455 }; 490 456 … … 534 500 futex_down(&async_futex); 535 501 536 unsigned long key = call->in_phone_hash; 537 link_t *hlp = hash_table_find(&conn_hash_table, &key); 502 ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash); 538 503 539 504 if (!hlp) { … … 542 507 } 543 508 544 connection_t *conn = hash_table_get_inst ance(hlp, connection_t, link);509 connection_t *conn = hash_table_get_inst(hlp, connection_t, link); 545 510 546 511 msg_t *msg = malloc(sizeof(*msg)); … … 722 687 static client_t *async_client_get(task_id_t client_id, bool create) 723 688 { 724 unsigned long key[2] = {725 LOWER32(client_id),726 UPPER32(client_id),727 };728 689 client_t *client = NULL; 729 690 730 691 futex_down(&async_futex); 731 link_t *lnk = hash_table_find(&client_hash_table, key);692 ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id); 732 693 if (lnk) { 733 client = hash_table_get_inst ance(lnk, client_t, link);694 client = hash_table_get_inst(lnk, client_t, link); 734 695 atomic_inc(&client->refcnt); 735 696 } else if (create) { … … 751 712 { 752 713 bool destroy; 753 unsigned long key[2] = { 754 LOWER32(client->in_task_id), 755 UPPER32(client->in_task_id) 756 }; 757 714 758 715 futex_down(&async_futex); 759 716 760 717 if (atomic_predec(&client->refcnt) == 0) { 761 hash_table_remove(&client_hash_table, key, 2);718 hash_table_remove(&client_hash_table, &client->in_task_id); 762 719 destroy = true; 763 720 } else … … 855 812 */ 856 813 futex_down(&async_futex); 857 unsigned long key = fibril_connection->in_phone_hash; 858 hash_table_remove(&conn_hash_table, &key, 1); 814 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 859 815 futex_up(&async_futex); 860 816 … … 1134 1090 void __async_init(void) 1135 1091 { 1136 if (!hash_table_create(&client_hash_table, 0, 2, &client_hash_table_ops))1092 if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops)) 1137 1093 abort(); 1138 1094 1139 if (!hash_table_create(&conn_hash_table, 0, 1, &conn_hash_table_ops))1095 if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops)) 1140 1096 abort(); 1141 1097
Note:
See TracChangeset
for help on using the changeset viewer.