Changes in uspace/lib/c/generic/async.c [bc216a0:375e501] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
rbc216a0 r375e501 115 115 #include <macros.h> 116 116 117 #define CLIENT_HASH_TABLE_BUCKETS 32 118 #define CONN_HASH_TABLE_BUCKETS 32 117 119 118 120 /** Session data */ … … 202 204 /* Client connection data */ 203 205 typedef struct { 204 ht_link_t link;206 link_t link; 205 207 206 208 task_id_t in_task_id; … … 214 216 215 217 /** Hash table link. */ 216 ht_link_t link;218 link_t link; 217 219 218 220 /** Incoming client task ID. */ … … 390 392 static LIST_INITIALIZE(timeout_list); 391 393 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; 409 } 410 394 static hash_index_t client_hash(unsigned long key[]) 395 { 396 assert(key); 397 398 return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 399 } 400 401 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item) 402 { 403 assert(key); 404 assert(keys == 2); 405 assert(item); 406 407 client_t *client = hash_table_get_instance(item, client_t, link); 408 return (key[0] == LOWER32(client->in_task_id) && 409 (key[1] == UPPER32(client->in_task_id))); 410 } 411 412 static void client_remove(link_t *item) 413 { 414 } 411 415 412 416 /** Operations for the client hash table. */ 413 static hash_table_op s_t client_hash_table_ops = {417 static hash_table_operations_t client_hash_table_ops = { 414 418 .hash = client_hash, 415 .key_hash = client_key_hash, 416 .key_equal = client_key_equal, 417 .equal = 0, 418 .remove_callback = 0 419 .compare = client_compare, 420 .remove_callback = client_remove 419 421 }; 420 422 … … 426 428 * 427 429 */ 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 430 static hash_index_t conn_hash(unsigned long key[]) 431 { 432 assert(key); 433 434 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS); 435 } 436 437 /** Compare hash table item with a key. 438 * 439 * @param key Array containing the source phone hash as the only item. 440 * @param keys Expected 1 but ignored. 441 * @param item Connection hash table item. 442 * 443 * @return True on match, false otherwise. 444 * 445 */ 446 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item) 447 { 448 assert(key); 449 assert(item); 450 451 connection_t *conn = hash_table_get_instance(item, connection_t, link); 452 return (key[0] == conn->in_phone_hash); 453 } 454 455 static void conn_remove(link_t *item) 456 { 457 } 447 458 448 459 /** Operations for the connection hash table. */ 449 static hash_table_op s_t conn_hash_table_ops = {460 static hash_table_operations_t conn_hash_table_ops = { 450 461 .hash = conn_hash, 451 .key_hash = conn_key_hash, 452 .key_equal = conn_key_equal, 453 .equal = 0, 454 .remove_callback = 0 462 .compare = conn_compare, 463 .remove_callback = conn_remove 455 464 }; 456 465 … … 500 509 futex_down(&async_futex); 501 510 502 ht_link_t *hlp = hash_table_find(&conn_hash_table, &call->in_phone_hash); 511 unsigned long key = call->in_phone_hash; 512 link_t *hlp = hash_table_find(&conn_hash_table, &key); 503 513 504 514 if (!hlp) { … … 507 517 } 508 518 509 connection_t *conn = hash_table_get_inst (hlp, connection_t, link);519 connection_t *conn = hash_table_get_instance(hlp, connection_t, link); 510 520 511 521 msg_t *msg = malloc(sizeof(*msg)); … … 687 697 static client_t *async_client_get(task_id_t client_id, bool create) 688 698 { 699 unsigned long key[2] = { 700 LOWER32(client_id), 701 UPPER32(client_id), 702 }; 689 703 client_t *client = NULL; 690 704 691 705 futex_down(&async_futex); 692 ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);706 link_t *lnk = hash_table_find(&client_hash_table, key); 693 707 if (lnk) { 694 client = hash_table_get_inst (lnk, client_t, link);708 client = hash_table_get_instance(lnk, client_t, link); 695 709 atomic_inc(&client->refcnt); 696 710 } else if (create) { … … 701 715 702 716 atomic_set(&client->refcnt, 1); 703 hash_table_insert(&client_hash_table, &client->link);717 hash_table_insert(&client_hash_table, key, &client->link); 704 718 } 705 719 } … … 712 726 { 713 727 bool destroy; 714 728 unsigned long key[2] = { 729 LOWER32(client->in_task_id), 730 UPPER32(client->in_task_id) 731 }; 732 715 733 futex_down(&async_futex); 716 734 717 735 if (atomic_predec(&client->refcnt) == 0) { 718 hash_table_remove(&client_hash_table, &client->in_task_id);736 hash_table_remove(&client_hash_table, key, 2); 719 737 destroy = true; 720 738 } else … … 812 830 */ 813 831 futex_down(&async_futex); 814 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 832 unsigned long key = fibril_connection->in_phone_hash; 833 hash_table_remove(&conn_hash_table, &key, 1); 815 834 futex_up(&async_futex); 816 835 … … 896 915 897 916 /* Add connection to the connection hash table */ 917 unsigned long key = conn->in_phone_hash; 898 918 899 919 futex_down(&async_futex); 900 hash_table_insert(&conn_hash_table, & conn->link);920 hash_table_insert(&conn_hash_table, &key, &conn->link); 901 921 futex_up(&async_futex); 902 922 … … 1090 1110 void __async_init(void) 1091 1111 { 1092 if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops)) 1112 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1113 2, &client_hash_table_ops)) 1093 1114 abort(); 1094 1115 1095 if (!hash_table_create(&conn_hash_table, 0, 0, &conn_hash_table_ops)) 1116 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1117 1, &conn_hash_table_ops)) 1096 1118 abort(); 1097 1119
Note:
See TracChangeset
for help on using the changeset viewer.