Changes in uspace/lib/c/generic/async.c [649f087:36e2b55] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r649f087 r36e2b55 98 98 #include <ipc/ipc.h> 99 99 #include <async.h> 100 #include "private/async.h" 100 101 #undef LIBC_ASYNC_C_ 101 102 … … 113 114 #include <stdlib.h> 114 115 #include <macros.h> 115 #include "private/async.h"116 116 117 117 #define CLIENT_HASH_TABLE_BUCKETS 32 … … 996 996 session_ns->arg3 = 0; 997 997 998 fibril_mutex_initialize(&session_ns->remote_state_mtx); 999 session_ns->remote_state_data = NULL; 1000 998 1001 list_initialize(&session_ns->exch_list); 999 1002 fibril_mutex_initialize(&session_ns->mutex); … … 1472 1475 return ENOENT; 1473 1476 1474 task_id_t task_id;1475 sysarg_t task_id_lo;1476 sysarg_t task_id_hi;1477 1477 sysarg_t phone_hash; 1478 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1479 NULL, NULL, &task_id_lo, &task_id_hi, &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); 1480 1485 if (rc != EOK) 1481 return rc;1482 1483 task_id = (task_id_t) MERGE_LOUP32(task_id_lo, task_id_hi);1484 1486 return (int) rc; 1487 1488 phone_hash = IPC_GET_ARG5(answer); 1489 1485 1490 if (client_receiver != NULL) 1486 async_new_connection( task_id, phone_hash, 0, NULL,1491 async_new_connection(answer.in_task_id, phone_hash, 0, NULL, 1487 1492 client_receiver, carg); 1488 1493 … … 1559 1564 sess->arg3 = 0; 1560 1565 1566 fibril_mutex_initialize(&sess->remote_state_mtx); 1567 sess->remote_state_data = NULL; 1568 1561 1569 list_initialize(&sess->exch_list); 1562 1570 fibril_mutex_initialize(&sess->mutex); … … 1640 1648 sess->arg3 = arg3; 1641 1649 1650 fibril_mutex_initialize(&sess->remote_state_mtx); 1651 sess->remote_state_data = NULL; 1652 1642 1653 list_initialize(&sess->exch_list); 1643 1654 fibril_mutex_initialize(&sess->mutex); … … 1645 1656 1646 1657 return sess; 1658 } 1659 1660 /** Set arguments for new connections. 1661 * 1662 * FIXME This is an ugly hack to work around the problem that parallel 1663 * exchanges are implemented using parallel connections. When we create 1664 * a callback session, the framework does not know arguments for the new 1665 * connections. 1666 * 1667 * The proper solution seems to be to implement parallel exchanges using 1668 * tagging. 1669 */ 1670 void async_sess_args_set(async_sess_t *sess, sysarg_t arg1, sysarg_t arg2, 1671 sysarg_t arg3) 1672 { 1673 sess->arg1 = arg1; 1674 sess->arg2 = arg2; 1675 sess->arg3 = arg3; 1647 1676 } 1648 1677 … … 1690 1719 sess->arg3 = arg3; 1691 1720 1721 fibril_mutex_initialize(&sess->remote_state_mtx); 1722 sess->remote_state_data = NULL; 1723 1692 1724 list_initialize(&sess->exch_list); 1693 1725 fibril_mutex_initialize(&sess->mutex); … … 1721 1753 sess->arg3 = 0; 1722 1754 1755 fibril_mutex_initialize(&sess->remote_state_mtx); 1756 sess->remote_state_data = NULL; 1757 1723 1758 list_initialize(&sess->exch_list); 1724 1759 fibril_mutex_initialize(&sess->mutex); … … 1742 1777 int async_hangup(async_sess_t *sess) 1743 1778 { 1779 async_exch_t *exch; 1780 1744 1781 assert(sess); 1745 1782 1746 1783 if (atomic_get(&sess->refcnt) > 0) 1747 1784 return EBUSY; 1785 1786 fibril_mutex_lock(&async_sess_mutex); 1748 1787 1749 1788 int rc = async_hangup_internal(sess->phone); 1750 1789 if (rc == EOK) 1751 1790 free(sess); 1791 1792 while (!list_empty(&sess->exch_list)) { 1793 exch = (async_exch_t *) 1794 list_get_instance(list_first(&sess->exch_list), 1795 async_exch_t, sess_link); 1796 1797 list_remove(&exch->sess_link); 1798 list_remove(&exch->global_link); 1799 async_hangup_internal(exch->phone); 1800 free(exch); 1801 } 1802 1803 fibril_mutex_unlock(&async_sess_mutex); 1752 1804 1753 1805 return rc; … … 2384 2436 sess->arg3 = 0; 2385 2437 2438 fibril_mutex_initialize(&sess->remote_state_mtx); 2439 sess->remote_state_data = NULL; 2440 2386 2441 list_initialize(&sess->exch_list); 2387 2442 fibril_mutex_initialize(&sess->mutex); … … 2430 2485 sess->arg3 = 0; 2431 2486 2487 fibril_mutex_initialize(&sess->remote_state_mtx); 2488 sess->remote_state_data = NULL; 2489 2432 2490 list_initialize(&sess->exch_list); 2433 2491 fibril_mutex_initialize(&sess->mutex); … … 2471 2529 sess->arg2 = 0; 2472 2530 sess->arg3 = 0; 2531 2532 fibril_mutex_initialize(&sess->remote_state_mtx); 2533 sess->remote_state_data = NULL; 2473 2534 2474 2535 list_initialize(&sess->exch_list); … … 2512 2573 } 2513 2574 2575 /** Lock and get session remote state 2576 * 2577 * Lock and get the local replica of the remote state 2578 * in stateful sessions. The call should be paired 2579 * with async_remote_state_release*(). 2580 * 2581 * @param[in] sess Stateful session. 2582 * 2583 * @return Local replica of the remote state. 2584 * 2585 */ 2586 void *async_remote_state_acquire(async_sess_t *sess) 2587 { 2588 fibril_mutex_lock(&sess->remote_state_mtx); 2589 return sess->remote_state_data; 2590 } 2591 2592 /** Update the session remote state 2593 * 2594 * Update the local replica of the remote state 2595 * in stateful sessions. The remote state must 2596 * be already locked. 2597 * 2598 * @param[in] sess Stateful session. 2599 * @param[in] state New local replica of the remote state. 2600 * 2601 */ 2602 void async_remote_state_update(async_sess_t *sess, void *state) 2603 { 2604 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2605 sess->remote_state_data = state; 2606 } 2607 2608 /** Release the session remote state 2609 * 2610 * Unlock the local replica of the remote state 2611 * in stateful sessions. 2612 * 2613 * @param[in] sess Stateful session. 2614 * 2615 */ 2616 void async_remote_state_release(async_sess_t *sess) 2617 { 2618 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2619 2620 fibril_mutex_unlock(&sess->remote_state_mtx); 2621 } 2622 2623 /** Release the session remote state and end an exchange 2624 * 2625 * Unlock the local replica of the remote state 2626 * in stateful sessions. This is convenience function 2627 * which gets the session pointer from the exchange 2628 * and also ends the exchange. 2629 * 2630 * @param[in] exch Stateful session's exchange. 2631 * 2632 */ 2633 void async_remote_state_release_exchange(async_exch_t *exch) 2634 { 2635 if (exch == NULL) 2636 return; 2637 2638 async_sess_t *sess = exch->sess; 2639 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2640 2641 async_exchange_end(exch); 2642 fibril_mutex_unlock(&sess->remote_state_mtx); 2643 } 2644 2514 2645 /** @} 2515 2646 */
Note:
See TracChangeset
for help on using the changeset viewer.