Changes in uspace/lib/c/generic/async.c [58cbf8d5:cdc8ee2d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r58cbf8d5 rcdc8ee2d 98 98 #include <ipc/ipc.h> 99 99 #include <async.h> 100 #include "private/async.h"101 100 #undef LIBC_ASYNC_C_ 102 101 … … 113 112 #include <mem.h> 114 113 #include <stdlib.h> 115 #include <macros.h>114 #include "private/async.h" 116 115 117 116 #define CLIENT_HASH_TABLE_BUCKETS 32 … … 139 138 link_t link; 140 139 141 task_id_t in_task_id;140 sysarg_t in_task_hash; 142 141 atomic_t refcnt; 143 142 void *data; … … 151 150 link_t link; 152 151 153 /** Incoming client task ID. */154 task_id_t in_task_id;152 /** Incoming client task hash. */ 153 sysarg_t in_task_hash; 155 154 156 155 /** Incoming phone hash. */ … … 284 283 { 285 284 assert(key); 286 assert(keys == 2);287 285 assert(item); 288 286 289 287 client_t *client = hash_table_get_instance(item, client_t, link); 290 return (key[0] == LOWER32(client->in_task_id) && 291 (key[1] == UPPER32(client->in_task_id))); 288 return (key[0] == client->in_task_hash); 292 289 } 293 290 … … 577 574 } 578 575 579 static client_t *async_client_get(task_id_t client_id, bool create) 580 { 581 unsigned long key[2] = { 582 LOWER32(client_id), 583 UPPER32(client_id), 584 }; 576 static client_t *async_client_get(sysarg_t client_hash, bool create) 577 { 578 unsigned long key = client_hash; 585 579 client_t *client = NULL; 586 580 587 581 futex_down(&async_futex); 588 link_t *lnk = hash_table_find(&client_hash_table, key);582 link_t *lnk = hash_table_find(&client_hash_table, &key); 589 583 if (lnk) { 590 584 client = hash_table_get_instance(lnk, client_t, link); … … 593 587 client = malloc(sizeof(client_t)); 594 588 if (client) { 595 client->in_task_ id = client_id;589 client->in_task_hash = client_hash; 596 590 client->data = async_client_data_create(); 597 591 598 592 atomic_set(&client->refcnt, 1); 599 hash_table_insert(&client_hash_table, key, &client->link);593 hash_table_insert(&client_hash_table, &key, &client->link); 600 594 } 601 595 } … … 608 602 { 609 603 bool destroy; 610 unsigned long key[2] = { 611 LOWER32(client->in_task_id), 612 UPPER32(client->in_task_id) 613 }; 604 unsigned long key = client->in_task_hash; 614 605 615 606 futex_down(&async_futex); 616 607 617 608 if (atomic_predec(&client->refcnt) == 0) { 618 hash_table_remove(&client_hash_table, key, 2);609 hash_table_remove(&client_hash_table, &key, 1); 619 610 destroy = true; 620 611 } else … … 637 628 } 638 629 639 void *async_get_client_data_by_ id(task_id_t client_id)640 { 641 client_t *client = async_client_get(client_ id, false);630 void *async_get_client_data_by_hash(sysarg_t client_hash) 631 { 632 client_t *client = async_client_get(client_hash, false); 642 633 if (!client) 643 634 return NULL; … … 650 641 } 651 642 652 void async_put_client_data_by_ id(task_id_t client_id)653 { 654 client_t *client = async_client_get(client_ id, false);643 void async_put_client_data_by_hash(sysarg_t client_hash) 644 { 645 client_t *client = async_client_get(client_hash, false); 655 646 656 647 assert(client); … … 689 680 */ 690 681 691 client_t *client = async_client_get(fibril_connection->in_task_ id, true);682 client_t *client = async_client_get(fibril_connection->in_task_hash, true); 692 683 if (!client) { 693 684 ipc_answer_0(fibril_connection->callid, ENOMEM); … … 746 737 * particular fibrils. 747 738 * 748 * @param in_task_ idIdentification of the incoming connection.739 * @param in_task_hash Identification of the incoming connection. 749 740 * @param in_phone_hash Identification of the incoming connection. 750 741 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 760 751 * 761 752 */ 762 fid_t async_new_connection( task_id_t in_task_id, sysarg_t in_phone_hash,753 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash, 763 754 ipc_callid_t callid, ipc_call_t *call, 764 755 async_client_conn_t cfibril, void *carg) … … 772 763 } 773 764 774 conn->in_task_ id = in_task_id;765 conn->in_task_hash = in_task_hash; 775 766 conn->in_phone_hash = in_phone_hash; 776 767 list_initialize(&conn->msg_queue); … … 831 822 case IPC_M_CONNECT_ME_TO: 832 823 /* Open new connection with fibril, etc. */ 833 async_new_connection(call->in_task_ id, IPC_GET_ARG5(*call),824 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call), 834 825 callid, call, client_connection, NULL); 835 826 return; … … 979 970 { 980 971 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 981 2, &client_hash_table_ops))972 1, &client_hash_table_ops)) 982 973 abort(); 983 974 … … 995 986 session_ns->arg2 = 0; 996 987 session_ns->arg3 = 0; 997 998 fibril_mutex_initialize(&session_ns->remote_state_mtx);999 session_ns->remote_state_data = NULL;1000 988 1001 989 list_initialize(&session_ns->exch_list); … … 1475 1463 return ENOENT; 1476 1464 1465 sysarg_t task_hash; 1477 1466 sysarg_t phone_hash; 1478 sysarg_t rc; 1479 1480 aid_t req; 1481 ipc_call_t answer; 1482 req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1483 &answer); 1484 async_wait_for(req, &rc); 1467 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1468 NULL, NULL, NULL, &task_hash, &phone_hash); 1485 1469 if (rc != EOK) 1486 return (int) rc; 1487 1488 phone_hash = IPC_GET_ARG5(answer); 1489 1470 return rc; 1471 1490 1472 if (client_receiver != NULL) 1491 async_new_connection( answer.in_task_id, phone_hash, 0, NULL,1473 async_new_connection(task_hash, phone_hash, 0, NULL, 1492 1474 client_receiver, carg); 1493 1475 … … 1564 1546 sess->arg3 = 0; 1565 1547 1566 fibril_mutex_initialize(&sess->remote_state_mtx);1567 sess->remote_state_data = NULL;1568 1569 1548 list_initialize(&sess->exch_list); 1570 1549 fibril_mutex_initialize(&sess->mutex); … … 1648 1627 sess->arg3 = arg3; 1649 1628 1650 fibril_mutex_initialize(&sess->remote_state_mtx);1651 sess->remote_state_data = NULL;1652 1653 1629 list_initialize(&sess->exch_list); 1654 1630 fibril_mutex_initialize(&sess->mutex); … … 1701 1677 sess->arg3 = arg3; 1702 1678 1703 fibril_mutex_initialize(&sess->remote_state_mtx);1704 sess->remote_state_data = NULL;1705 1706 1679 list_initialize(&sess->exch_list); 1707 1680 fibril_mutex_initialize(&sess->mutex); … … 1734 1707 sess->arg2 = 0; 1735 1708 sess->arg3 = 0; 1736 1737 fibril_mutex_initialize(&sess->remote_state_mtx);1738 sess->remote_state_data = NULL;1739 1709 1740 1710 list_initialize(&sess->exch_list); … … 2401 2371 sess->arg3 = 0; 2402 2372 2403 fibril_mutex_initialize(&sess->remote_state_mtx);2404 sess->remote_state_data = NULL;2405 2406 2373 list_initialize(&sess->exch_list); 2407 2374 fibril_mutex_initialize(&sess->mutex); … … 2450 2417 sess->arg3 = 0; 2451 2418 2452 fibril_mutex_initialize(&sess->remote_state_mtx);2453 sess->remote_state_data = NULL;2454 2455 2419 list_initialize(&sess->exch_list); 2456 2420 fibril_mutex_initialize(&sess->mutex); … … 2494 2458 sess->arg2 = 0; 2495 2459 sess->arg3 = 0; 2496 2497 fibril_mutex_initialize(&sess->remote_state_mtx);2498 sess->remote_state_data = NULL;2499 2460 2500 2461 list_initialize(&sess->exch_list); … … 2538 2499 } 2539 2500 2540 /** Lock and get session remote state2541 *2542 * Lock and get the local replica of the remote state2543 * in stateful sessions. The call should be paired2544 * with async_remote_state_release*().2545 *2546 * @param[in] sess Stateful session.2547 *2548 * @return Local replica of the remote state.2549 *2550 */2551 void *async_remote_state_acquire(async_sess_t *sess)2552 {2553 fibril_mutex_lock(&sess->remote_state_mtx);2554 return sess->remote_state_data;2555 }2556 2557 /** Update the session remote state2558 *2559 * Update the local replica of the remote state2560 * in stateful sessions. The remote state must2561 * be already locked.2562 *2563 * @param[in] sess Stateful session.2564 * @param[in] state New local replica of the remote state.2565 *2566 */2567 void async_remote_state_update(async_sess_t *sess, void *state)2568 {2569 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));2570 sess->remote_state_data = state;2571 }2572 2573 /** Release the session remote state2574 *2575 * Unlock the local replica of the remote state2576 * in stateful sessions.2577 *2578 * @param[in] sess Stateful session.2579 *2580 */2581 void async_remote_state_release(async_sess_t *sess)2582 {2583 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));2584 2585 fibril_mutex_unlock(&sess->remote_state_mtx);2586 }2587 2588 /** Release the session remote state and end an exchange2589 *2590 * Unlock the local replica of the remote state2591 * in stateful sessions. This is convenience function2592 * which gets the session pointer from the exchange2593 * and also ends the exchange.2594 *2595 * @param[in] exch Stateful session's exchange.2596 *2597 */2598 void async_remote_state_release_exchange(async_exch_t *exch)2599 {2600 if (exch == NULL)2601 return;2602 2603 async_sess_t *sess = exch->sess;2604 assert(fibril_mutex_is_locked(&sess->remote_state_mtx));2605 2606 async_exchange_end(exch);2607 fibril_mutex_unlock(&sess->remote_state_mtx);2608 }2609 2610 2501 /** @} 2611 2502 */
Note:
See TracChangeset
for help on using the changeset viewer.