Changeset 0ca7286 in mainline for uspace/lib/c/generic/async.c
- Timestamp:
- 2012-07-21T11:19:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2732c94
- Parents:
- 1c1da4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r1c1da4b r0ca7286 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 */ … … 392 390 static LIST_INITIALIZE(timeout_list); 393 391 394 static hash_index_t client_hash(unsigned long key[])392 static size_t client_key_hash(unsigned long key[]) 395 393 { 396 394 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) 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) 402 412 { 403 413 assert(key); … … 410 420 } 411 421 412 static void client_remove(link_t *item)413 {414 }415 422 416 423 /** Operations for the client hash table. */ 417 static hash_table_op erations_t client_hash_table_ops = {424 static hash_table_ops_t client_hash_table_ops = { 418 425 .hash = client_hash, 419 .compare = client_compare, 420 .remove_callback = client_remove 426 .key_hash = client_key_hash, 427 .match = client_match, 428 .equal = 0, 429 .remove_callback = 0 421 430 }; 422 431 … … 428 437 * 429 438 */ 430 static hash_index_t conn_hash(unsigned long key[])439 static size_t conn_key_hash(unsigned long key[]) 431 440 { 432 441 assert(key); 433 434 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS); 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); 435 450 } 436 451 … … 444 459 * 445 460 */ 446 static int conn_compare(unsigned long key[], hash_count_t keys,link_t *item)461 static bool conn_match(unsigned long key[], size_t keys, const link_t *item) 447 462 { 448 463 assert(key); … … 453 468 } 454 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 455 478 static void conn_remove(link_t *item) 456 479 { … … 458 481 459 482 /** Operations for the connection hash table. */ 460 static hash_table_op erations_t conn_hash_table_ops = {483 static hash_table_ops_t conn_hash_table_ops = { 461 484 .hash = conn_hash, 462 .compare = conn_compare, 485 .key_hash = conn_key_hash, 486 .match = conn_match, 487 .equal = conn_equal, 463 488 .remove_callback = conn_remove 464 489 }; … … 715 740 716 741 atomic_set(&client->refcnt, 1); 717 hash_table_insert(&client_hash_table, key,&client->link);742 hash_table_insert(&client_hash_table, &client->link); 718 743 } 719 744 } … … 915 940 916 941 /* Add connection to the connection hash table */ 917 unsigned long key = conn->in_phone_hash;918 942 919 943 futex_down(&async_futex); 920 hash_table_insert(&conn_hash_table, & key, &conn->link);944 hash_table_insert(&conn_hash_table, &conn->link); 921 945 futex_up(&async_futex); 922 946 … … 1110 1134 void __async_init(void) 1111 1135 { 1112 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1113 2, &client_hash_table_ops)) 1136 if (!hash_table_create(&client_hash_table, 0, 2, &client_hash_table_ops)) 1114 1137 abort(); 1115 1138 1116 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1117 1, &conn_hash_table_ops)) 1139 if (!hash_table_create(&conn_hash_table, 0, 1, &conn_hash_table_ops)) 1118 1140 abort(); 1119 1141
Note:
See TracChangeset
for help on using the changeset viewer.