Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r649f087 r36e2b55  
    9898#include <ipc/ipc.h>
    9999#include <async.h>
     100#include "private/async.h"
    100101#undef LIBC_ASYNC_C_
    101102
     
    113114#include <stdlib.h>
    114115#include <macros.h>
    115 #include "private/async.h"
    116116
    117117#define CLIENT_HASH_TABLE_BUCKETS  32
     
    996996        session_ns->arg3 = 0;
    997997       
     998        fibril_mutex_initialize(&session_ns->remote_state_mtx);
     999        session_ns->remote_state_data = NULL;
     1000       
    9981001        list_initialize(&session_ns->exch_list);
    9991002        fibril_mutex_initialize(&session_ns->mutex);
     
    14721475                return ENOENT;
    14731476       
    1474         task_id_t task_id;
    1475         sysarg_t task_id_lo;
    1476         sysarg_t task_id_hi;
    14771477        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);
    14801485        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
    14851490        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,
    14871492                    client_receiver, carg);
    14881493       
     
    15591564        sess->arg3 = 0;
    15601565       
     1566        fibril_mutex_initialize(&sess->remote_state_mtx);
     1567        sess->remote_state_data = NULL;
     1568       
    15611569        list_initialize(&sess->exch_list);
    15621570        fibril_mutex_initialize(&sess->mutex);
     
    16401648        sess->arg3 = arg3;
    16411649       
     1650        fibril_mutex_initialize(&sess->remote_state_mtx);
     1651        sess->remote_state_data = NULL;
     1652       
    16421653        list_initialize(&sess->exch_list);
    16431654        fibril_mutex_initialize(&sess->mutex);
     
    16451656       
    16461657        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 */
     1670void 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;
    16471676}
    16481677
     
    16901719        sess->arg3 = arg3;
    16911720       
     1721        fibril_mutex_initialize(&sess->remote_state_mtx);
     1722        sess->remote_state_data = NULL;
     1723       
    16921724        list_initialize(&sess->exch_list);
    16931725        fibril_mutex_initialize(&sess->mutex);
     
    17211753        sess->arg3 = 0;
    17221754       
     1755        fibril_mutex_initialize(&sess->remote_state_mtx);
     1756        sess->remote_state_data = NULL;
     1757       
    17231758        list_initialize(&sess->exch_list);
    17241759        fibril_mutex_initialize(&sess->mutex);
     
    17421777int async_hangup(async_sess_t *sess)
    17431778{
     1779        async_exch_t *exch;
     1780       
    17441781        assert(sess);
    17451782       
    17461783        if (atomic_get(&sess->refcnt) > 0)
    17471784                return EBUSY;
     1785       
     1786        fibril_mutex_lock(&async_sess_mutex);
    17481787       
    17491788        int rc = async_hangup_internal(sess->phone);
    17501789        if (rc == EOK)
    17511790                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);
    17521804       
    17531805        return rc;
     
    23842436        sess->arg3 = 0;
    23852437       
     2438        fibril_mutex_initialize(&sess->remote_state_mtx);
     2439        sess->remote_state_data = NULL;
     2440       
    23862441        list_initialize(&sess->exch_list);
    23872442        fibril_mutex_initialize(&sess->mutex);
     
    24302485        sess->arg3 = 0;
    24312486       
     2487        fibril_mutex_initialize(&sess->remote_state_mtx);
     2488        sess->remote_state_data = NULL;
     2489       
    24322490        list_initialize(&sess->exch_list);
    24332491        fibril_mutex_initialize(&sess->mutex);
     
    24712529        sess->arg2 = 0;
    24722530        sess->arg3 = 0;
     2531       
     2532        fibril_mutex_initialize(&sess->remote_state_mtx);
     2533        sess->remote_state_data = NULL;
    24732534       
    24742535        list_initialize(&sess->exch_list);
     
    25122573}
    25132574
     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 */
     2586void *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 */
     2602void 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 */
     2616void 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 */
     2633void 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
    25142645/** @}
    25152646 */
Note: See TracChangeset for help on using the changeset viewer.