Ignore:
File:
1 edited

Legend:

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

    r93ad49a8 rcdc8ee2d  
    9898#include <ipc/ipc.h>
    9999#include <async.h>
    100 #include "private/async.h"
    101100#undef LIBC_ASYNC_C_
    102101
     
    113112#include <mem.h>
    114113#include <stdlib.h>
    115 #include <macros.h>
     114#include "private/async.h"
    116115
    117116#define CLIENT_HASH_TABLE_BUCKETS  32
     
    139138        link_t link;
    140139       
    141         task_id_t in_task_id;
     140        sysarg_t in_task_hash;
    142141        atomic_t refcnt;
    143142        void *data;
     
    151150        link_t link;
    152151       
    153         /** Incoming client task ID. */
    154         task_id_t in_task_id;
     152        /** Incoming client task hash. */
     153        sysarg_t in_task_hash;
    155154       
    156155        /** Incoming phone hash. */
     
    284283{
    285284        assert(key);
    286         assert(keys == 2);
    287285        assert(item);
    288286       
    289287        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);
    292289}
    293290
     
    577574}
    578575
    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         };
     576static client_t *async_client_get(sysarg_t client_hash, bool create)
     577{
     578        unsigned long key = client_hash;
    585579        client_t *client = NULL;
    586580
    587581        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);
    589583        if (lnk) {
    590584                client = hash_table_get_instance(lnk, client_t, link);
     
    593587                client = malloc(sizeof(client_t));
    594588                if (client) {
    595                         client->in_task_id = client_id;
     589                        client->in_task_hash = client_hash;
    596590                        client->data = async_client_data_create();
    597591               
    598592                        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);
    600594                }
    601595        }
     
    608602{
    609603        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;
    614605       
    615606        futex_down(&async_futex);
    616607       
    617608        if (atomic_predec(&client->refcnt) == 0) {
    618                 hash_table_remove(&client_hash_table, key, 2);
     609                hash_table_remove(&client_hash_table, &key, 1);
    619610                destroy = true;
    620611        } else
     
    637628}
    638629
    639 void *async_get_client_data_by_id(task_id_t client_id)
    640 {
    641         client_t *client = async_client_get(client_id, false);
     630void *async_get_client_data_by_hash(sysarg_t client_hash)
     631{
     632        client_t *client = async_client_get(client_hash, false);
    642633        if (!client)
    643634                return NULL;
     
    650641}
    651642
    652 void async_put_client_data_by_id(task_id_t client_id)
    653 {
    654         client_t *client = async_client_get(client_id, false);
     643void async_put_client_data_by_hash(sysarg_t client_hash)
     644{
     645        client_t *client = async_client_get(client_hash, false);
    655646
    656647        assert(client);
     
    689680         */
    690681
    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);
    692683        if (!client) {
    693684                ipc_answer_0(fibril_connection->callid, ENOMEM);
     
    746737 * particular fibrils.
    747738 *
    748  * @param in_task_id    Identification of the incoming connection.
     739 * @param in_task_hash  Identification of the incoming connection.
    749740 * @param in_phone_hash Identification of the incoming connection.
    750741 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    760751 *
    761752 */
    762 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
     753fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
    763754    ipc_callid_t callid, ipc_call_t *call,
    764755    async_client_conn_t cfibril, void *carg)
     
    772763        }
    773764       
    774         conn->in_task_id = in_task_id;
     765        conn->in_task_hash = in_task_hash;
    775766        conn->in_phone_hash = in_phone_hash;
    776767        list_initialize(&conn->msg_queue);
     
    831822        case IPC_M_CONNECT_ME_TO:
    832823                /* 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),
    834825                    callid, call, client_connection, NULL);
    835826                return;
     
    979970{
    980971        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    981             2, &client_hash_table_ops))
     972            1, &client_hash_table_ops))
    982973                abort();
    983974       
     
    995986        session_ns->arg2 = 0;
    996987        session_ns->arg3 = 0;
    997        
    998         fibril_mutex_initialize(&session_ns->remote_state_mtx);
    999         session_ns->remote_state_data = NULL;
    1000988       
    1001989        list_initialize(&session_ns->exch_list);
     
    14751463                return ENOENT;
    14761464       
     1465        sysarg_t task_hash;
    14771466        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);
    14851469        if (rc != EOK)
    1486                 return (int) rc;
    1487 
    1488         phone_hash = IPC_GET_ARG5(answer);
    1489 
     1470                return rc;
     1471       
    14901472        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,
    14921474                    client_receiver, carg);
    14931475       
     
    15641546        sess->arg3 = 0;
    15651547       
    1566         fibril_mutex_initialize(&sess->remote_state_mtx);
    1567         sess->remote_state_data = NULL;
    1568        
    15691548        list_initialize(&sess->exch_list);
    15701549        fibril_mutex_initialize(&sess->mutex);
     
    16481627        sess->arg3 = arg3;
    16491628       
    1650         fibril_mutex_initialize(&sess->remote_state_mtx);
    1651         sess->remote_state_data = NULL;
    1652        
    16531629        list_initialize(&sess->exch_list);
    16541630        fibril_mutex_initialize(&sess->mutex);
     
    16561632       
    16571633        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;
    16761634}
    16771635
     
    17191677        sess->arg3 = arg3;
    17201678       
    1721         fibril_mutex_initialize(&sess->remote_state_mtx);
    1722         sess->remote_state_data = NULL;
    1723        
    17241679        list_initialize(&sess->exch_list);
    17251680        fibril_mutex_initialize(&sess->mutex);
     
    17521707        sess->arg2 = 0;
    17531708        sess->arg3 = 0;
    1754        
    1755         fibril_mutex_initialize(&sess->remote_state_mtx);
    1756         sess->remote_state_data = NULL;
    17571709       
    17581710        list_initialize(&sess->exch_list);
     
    24192371        sess->arg3 = 0;
    24202372       
    2421         fibril_mutex_initialize(&sess->remote_state_mtx);
    2422         sess->remote_state_data = NULL;
    2423        
    24242373        list_initialize(&sess->exch_list);
    24252374        fibril_mutex_initialize(&sess->mutex);
     
    24682417        sess->arg3 = 0;
    24692418       
    2470         fibril_mutex_initialize(&sess->remote_state_mtx);
    2471         sess->remote_state_data = NULL;
    2472        
    24732419        list_initialize(&sess->exch_list);
    24742420        fibril_mutex_initialize(&sess->mutex);
     
    25122458        sess->arg2 = 0;
    25132459        sess->arg3 = 0;
    2514        
    2515         fibril_mutex_initialize(&sess->remote_state_mtx);
    2516         sess->remote_state_data = NULL;
    25172460       
    25182461        list_initialize(&sess->exch_list);
     
    25562499}
    25572500
    2558 /** Lock and get session remote state
    2559  *
    2560  * Lock and get the local replica of the remote state
    2561  * in stateful sessions. The call should be paired
    2562  * with async_remote_state_release*().
    2563  *
    2564  * @param[in] sess Stateful session.
    2565  *
    2566  * @return Local replica of the remote state.
    2567  *
    2568  */
    2569 void *async_remote_state_acquire(async_sess_t *sess)
    2570 {
    2571         fibril_mutex_lock(&sess->remote_state_mtx);
    2572         return sess->remote_state_data;
    2573 }
    2574 
    2575 /** Update the session remote state
    2576  *
    2577  * Update the local replica of the remote state
    2578  * in stateful sessions. The remote state must
    2579  * be already locked.
    2580  *
    2581  * @param[in] sess  Stateful session.
    2582  * @param[in] state New local replica of the remote state.
    2583  *
    2584  */
    2585 void async_remote_state_update(async_sess_t *sess, void *state)
    2586 {
    2587         assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
    2588         sess->remote_state_data = state;
    2589 }
    2590 
    2591 /** Release the session remote state
    2592  *
    2593  * Unlock the local replica of the remote state
    2594  * in stateful sessions.
    2595  *
    2596  * @param[in] sess Stateful session.
    2597  *
    2598  */
    2599 void async_remote_state_release(async_sess_t *sess)
    2600 {
    2601         assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
    2602        
    2603         fibril_mutex_unlock(&sess->remote_state_mtx);
    2604 }
    2605 
    2606 /** Release the session remote state and end an exchange
    2607  *
    2608  * Unlock the local replica of the remote state
    2609  * in stateful sessions. This is convenience function
    2610  * which gets the session pointer from the exchange
    2611  * and also ends the exchange.
    2612  *
    2613  * @param[in] exch Stateful session's exchange.
    2614  *
    2615  */
    2616 void async_remote_state_release_exchange(async_exch_t *exch)
    2617 {
    2618         if (exch == NULL)
    2619                 return;
    2620        
    2621         async_sess_t *sess = exch->sess;
    2622         assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
    2623        
    2624         async_exchange_end(exch);
    2625         fibril_mutex_unlock(&sess->remote_state_mtx);
    2626 }
    2627 
    26282501/** @}
    26292502 */
Note: See TracChangeset for help on using the changeset viewer.