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