Changes in uspace/lib/c/generic/async.c [4e00f87:45cbcaf4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r4e00f87 r45cbcaf4 114 114 #include <stdlib.h> 115 115 #include <macros.h> 116 #include "private/libc.h" 117 116 117 #define CLIENT_HASH_TABLE_BUCKETS 32 118 #define CONN_HASH_TABLE_BUCKETS 32 118 119 119 120 /** Session data */ … … 203 204 /* Client connection data */ 204 205 typedef struct { 205 ht_link_t link;206 link_t link; 206 207 207 208 task_id_t in_task_id; … … 215 216 216 217 /** Hash table link. */ 217 ht_link_t link;218 link_t link; 218 219 219 220 /** Incoming client task ID. */ … … 391 392 static LIST_INITIALIZE(timeout_list); 392 393 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 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 } 412 415 413 416 /** Operations for the client hash table. */ 414 static hash_table_op s_t client_hash_table_ops = {417 static hash_table_operations_t client_hash_table_ops = { 415 418 .hash = client_hash, 416 .key_hash = client_key_hash, 417 .key_equal = client_key_equal, 418 .equal = NULL, 419 .remove_callback = NULL 419 .compare = client_compare, 420 .remove_callback = client_remove 420 421 }; 421 422 … … 427 428 * 428 429 */ 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 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 } 448 458 449 459 /** Operations for the connection hash table. */ 450 static hash_table_op s_t conn_hash_table_ops = {460 static hash_table_operations_t conn_hash_table_ops = { 451 461 .hash = conn_hash, 452 .key_hash = conn_key_hash, 453 .key_equal = conn_key_equal, 454 .equal = NULL, 455 .remove_callback = NULL 462 .compare = conn_compare, 463 .remove_callback = conn_remove 456 464 }; 457 465 … … 501 509 futex_down(&async_futex); 502 510 503 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); 504 513 505 514 if (!hlp) { … … 508 517 } 509 518 510 connection_t *conn = hash_table_get_inst (hlp, connection_t, link);519 connection_t *conn = hash_table_get_instance(hlp, connection_t, link); 511 520 512 521 msg_t *msg = malloc(sizeof(*msg)); … … 688 697 static client_t *async_client_get(task_id_t client_id, bool create) 689 698 { 699 unsigned long key[2] = { 700 LOWER32(client_id), 701 UPPER32(client_id), 702 }; 690 703 client_t *client = NULL; 691 704 692 705 futex_down(&async_futex); 693 ht_link_t *lnk = hash_table_find(&client_hash_table, &client_id);706 link_t *lnk = hash_table_find(&client_hash_table, key); 694 707 if (lnk) { 695 client = hash_table_get_inst (lnk, client_t, link);708 client = hash_table_get_instance(lnk, client_t, link); 696 709 atomic_inc(&client->refcnt); 697 710 } else if (create) { … … 702 715 703 716 atomic_set(&client->refcnt, 1); 704 hash_table_insert(&client_hash_table, &client->link);717 hash_table_insert(&client_hash_table, key, &client->link); 705 718 } 706 719 } … … 713 726 { 714 727 bool destroy; 715 728 unsigned long key[2] = { 729 LOWER32(client->in_task_id), 730 UPPER32(client->in_task_id) 731 }; 732 716 733 futex_down(&async_futex); 717 734 718 735 if (atomic_predec(&client->refcnt) == 0) { 719 hash_table_remove(&client_hash_table, &client->in_task_id);736 hash_table_remove(&client_hash_table, key, 2); 720 737 destroy = true; 721 738 } else … … 813 830 */ 814 831 futex_down(&async_futex); 815 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); 816 834 futex_up(&async_futex); 817 835 … … 897 915 898 916 /* Add connection to the connection hash table */ 917 unsigned long key = conn->in_phone_hash; 899 918 900 919 futex_down(&async_futex); 901 hash_table_insert(&conn_hash_table, & conn->link);920 hash_table_insert(&conn_hash_table, &key, &conn->link); 902 921 futex_up(&async_futex); 903 922 … … 1091 1110 void __async_init(void) 1092 1111 { 1093 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)) 1094 1114 abort(); 1095 1115 1096 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)) 1097 1118 abort(); 1098 1119 … … 2145 2166 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags) 2146 2167 { 2147 return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags, 2148 (sysarg_t) __entry); 2168 return ipc_share_in_finalize(callid, src, flags); 2149 2169 } 2150 2170 … … 2213 2233 int async_share_out_finalize(ipc_callid_t callid, void **dst) 2214 2234 { 2215 return ipc_ answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t)dst);2235 return ipc_share_out_finalize(callid, dst); 2216 2236 } 2217 2237 … … 2297 2317 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size) 2298 2318 { 2299 return ipc_ answer_2(callid, EOK, (sysarg_t) src, (sysarg_t)size);2319 return ipc_data_read_finalize(callid, src, size); 2300 2320 } 2301 2321 … … 2400 2420 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size) 2401 2421 { 2402 return ipc_ answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t)size);2422 return ipc_data_write_finalize(callid, dst, size); 2403 2423 } 2404 2424
Note:
See TracChangeset
for help on using the changeset viewer.