Changeset 9f4067b6 in mainline for uspace/lib/c/generic/async.c
- Timestamp:
- 2012-10-09T21:16:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6659037, 7d248e3
- Parents:
- d1ef4a1 (diff), 97b199b1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rd1ef4a1 r9f4067b6 116 116 #include "private/libc.h" 117 117 118 #define CLIENT_HASH_TABLE_BUCKETS 32119 #define CONN_HASH_TABLE_BUCKETS 32120 118 121 119 /** Session data */ … … 205 203 /* Client connection data */ 206 204 typedef struct { 207 link_t link;205 ht_link_t link; 208 206 209 207 task_id_t in_task_id; … … 217 215 218 216 /** Hash table link. */ 219 link_t link;217 ht_link_t link; 220 218 221 219 /** Incoming client task ID. */ … … 393 391 static LIST_INITIALIZE(timeout_list); 394 392 395 static hash_index_t client_hash(unsigned long key[]) 396 { 397 assert(key); 398 399 return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 400 } 401 402 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item) 403 { 404 assert(key); 405 assert(keys == 2); 406 assert(item); 407 408 client_t *client = hash_table_get_instance(item, client_t, link); 409 return (key[0] == LOWER32(client->in_task_id) && 410 (key[1] == UPPER32(client->in_task_id))); 411 } 412 413 static void client_remove(link_t *item) 414 { 415 } 393 static size_t client_key_hash(void *k) 394 { 395 task_id_t key = *(task_id_t*)k; 396 return key; 397 } 398 399 static size_t client_hash(const ht_link_t *item) 400 { 401 client_t *client = hash_table_get_inst(item, client_t, link); 402 return client_key_hash(&client->in_task_id); 403 } 404 405 static bool client_key_equal(void *k, const ht_link_t *item) 406 { 407 task_id_t key = *(task_id_t*)k; 408 client_t *client = hash_table_get_inst(item, client_t, link); 409 return key == client->in_task_id; 410 } 411 416 412 417 413 /** Operations for the client hash table. */ 418 static hash_table_op erations_t client_hash_table_ops = {414 static hash_table_ops_t client_hash_table_ops = { 419 415 .hash = client_hash, 420 .compare = client_compare, 421 .remove_callback = client_remove 416 .key_hash = client_key_hash, 417 .key_equal = client_key_equal, 418 .equal = NULL, 419 .remove_callback = NULL 422 420 }; 423 421 … … 429 427 * 430 428 */ 431 static hash_index_t conn_hash(unsigned long key[]) 432 { 433 assert(key); 434 435 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS); 436 } 437 438 /** Compare hash table item with a key. 439 * 440 * @param key Array containing the source phone hash as the only item. 441 * @param keys Expected 1 but ignored. 442 * @param item Connection hash table item. 443 * 444 * @return True on match, false otherwise. 445 * 446 */ 447 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item) 448 { 449 assert(key); 450 assert(item); 451 452 connection_t *conn = hash_table_get_instance(item, connection_t, link); 453 return (key[0] == conn->in_phone_hash); 454 } 455 456 static void conn_remove(link_t *item) 457 { 458 } 429 static size_t conn_key_hash(void *key) 430 { 431 sysarg_t in_phone_hash = *(sysarg_t*)key; 432 return in_phone_hash ; 433 } 434 435 static size_t conn_hash(const ht_link_t *item) 436 { 437 connection_t *conn = hash_table_get_inst(item, connection_t, link); 438 return conn_key_hash(&conn->in_phone_hash); 439 } 440 441 static bool conn_key_equal(void *key, const ht_link_t *item) 442 { 443 sysarg_t in_phone_hash = *(sysarg_t*)key; 444 connection_t *conn = hash_table_get_inst(item, connection_t, link); 445 return (in_phone_hash == conn->in_phone_hash); 446 } 447 459 448 460 449 /** Operations for the connection hash table. */ 461 static hash_table_op erations_t conn_hash_table_ops = {450 static hash_table_ops_t conn_hash_table_ops = { 462 451 .hash = conn_hash, 463 .compare = conn_compare, 464 .remove_callback = conn_remove 452 .key_hash = conn_key_hash, 453 .key_equal = conn_key_equal, 454 .equal = NULL, 455 .remove_callback = NULL 465 456 }; 466 457 … … 510 501 futex_down(&async_futex); 511 502 512 unsigned long key = call->in_phone_hash; 513 link_t *hlp = hash_table_find(&conn_hash_table, &key); 503 ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash); 514 504 515 505 if (!hlp) { … … 518 508 } 519 509 520 connection_t *conn = hash_table_get_inst ance(hlp, connection_t, link);510 connection_t *conn = hash_table_get_inst(hlp, connection_t, link); 521 511 522 512 msg_t *msg = malloc(sizeof(*msg)); … … 698 688 static client_t *async_client_get(task_id_t client_id, bool create) 699 689 { 700 unsigned long key[2] = {701 LOWER32(client_id),702 UPPER32(client_id),703 };704 690 client_t *client = NULL; 705 691 706 692 futex_down(&async_futex); 707 link_t *lnk = hash_table_find(&client_hash_table, key);693 ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id); 708 694 if (lnk) { 709 client = hash_table_get_inst ance(lnk, client_t, link);695 client = hash_table_get_inst(lnk, client_t, link); 710 696 atomic_inc(&client->refcnt); 711 697 } else if (create) { … … 716 702 717 703 atomic_set(&client->refcnt, 1); 718 hash_table_insert(&client_hash_table, key,&client->link);704 hash_table_insert(&client_hash_table, &client->link); 719 705 } 720 706 } … … 727 713 { 728 714 bool destroy; 729 unsigned long key[2] = { 730 LOWER32(client->in_task_id), 731 UPPER32(client->in_task_id) 732 }; 733 715 734 716 futex_down(&async_futex); 735 717 736 718 if (atomic_predec(&client->refcnt) == 0) { 737 hash_table_remove(&client_hash_table, key, 2);719 hash_table_remove(&client_hash_table, &client->in_task_id); 738 720 destroy = true; 739 721 } else … … 831 813 */ 832 814 futex_down(&async_futex); 833 unsigned long key = fibril_connection->in_phone_hash; 834 hash_table_remove(&conn_hash_table, &key, 1); 815 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 835 816 futex_up(&async_futex); 836 817 … … 916 897 917 898 /* Add connection to the connection hash table */ 918 unsigned long key = conn->in_phone_hash;919 899 920 900 futex_down(&async_futex); 921 hash_table_insert(&conn_hash_table, & key, &conn->link);901 hash_table_insert(&conn_hash_table, &conn->link); 922 902 futex_up(&async_futex); 923 903 … … 1111 1091 void __async_init(void) 1112 1092 { 1113 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1114 2, &client_hash_table_ops)) 1093 if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops)) 1115 1094 abort(); 1116 1095 1117 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1118 1, &conn_hash_table_ops)) 1096 if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops)) 1119 1097 abort(); 1120 1098
Note:
See TracChangeset
for help on using the changeset viewer.