Changeset b688fd8 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2015-08-17T18:54:56Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
abf2dfd
Parents:
b10460a
Message:

gradually introduce async ports, initial phase

The initial phase is to reimplement the traditional async client connections as an untyped fallback port. This creates the possibility to introduce ports typed by interface type gradually in later changesets.

File:
1 edited

Legend:

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

    rb10460a rb688fd8  
    7777 *   }
    7878 *
    79  *   my_client_connection(icallid, *icall)
     79 *   port_handler(icallid, *icall)
    8080 *   {
    8181 *     if (want_refuse) {
     
    232232        /** Identification of the opening call. */
    233233        ipc_callid_t callid;
     234       
    234235        /** Call data of the opening call. */
    235236        ipc_call_t call;
    236         /** Local argument or NULL if none. */
    237         void *carg;
    238237       
    239238        /** Identification of the closing call. */
     
    241240       
    242241        /** Fibril function that will be used to handle the connection. */
    243         async_client_conn_t cfibril;
     242        async_port_handler_t handler;
     243       
     244        /** Client data */
     245        void *data;
    244246} connection_t;
    245247
     
    335337}
    336338
    337 /** Default fibril function that gets called to handle new connection.
    338  *
    339  * This function is defined as a weak symbol - to be redefined in user code.
     339/** Default fallback fibril function.
     340 *
     341 * This fallback fibril function gets called on incomming
     342 * connections that do not have a specific handler defined.
    340343 *
    341344 * @param callid Hash of the incoming call.
     
    344347 *
    345348 */
    346 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call,
     349static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call,
    347350    void *arg)
    348351{
     
    350353}
    351354
    352 static async_client_conn_t client_connection = default_client_connection;
     355static async_port_handler_t fallback_port_handler =
     356    default_fallback_port_handler;
     357static void *fallback_port_data = NULL;
     358
    353359static size_t notification_handler_stksz = FIBRIL_DFLT_STK_SIZE;
    354360
    355 /** Setter for client_connection function pointer.
    356  *
    357  * @param conn Function that will implement a new connection fibril.
    358  *
    359  */
    360 void async_set_client_connection(async_client_conn_t conn)
    361 {
    362         assert(client_connection == default_client_connection);
    363         client_connection = conn;
    364 }
    365 
    366361/** Set the stack size for the notification handler notification fibrils.
    367362 *
     
    387382 */
    388383static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv);
     384
     385void async_set_fallback_port_handler(async_port_handler_t handler, void *data)
     386{
     387        assert(handler != NULL);
     388       
     389        fallback_port_handler = handler;
     390        fallback_port_data = data;
     391}
    389392
    390393static hash_table_t client_hash_table;
     
    959962 *
    960963 * When a new connection arrives, a fibril with this implementing function is
    961  * created. It calls client_connection() and does the final cleanup.
     964 * created. It calls handler() and does the final cleanup.
    962965 *
    963966 * @param arg Connection structure pointer.
     
    992995         * Call the connection handler function.
    993996         */
    994         fibril_connection->cfibril(fibril_connection->callid,
    995             &fibril_connection->call, fibril_connection->carg);
     997        fibril_connection->handler(fibril_connection->callid,
     998            &fibril_connection->call, fibril_connection->data);
    996999       
    9971000        /*
     
    10441047 *                      is called directly by the server.
    10451048 * @param call          Call data of the opening call.
    1046  * @param cfibril       Fibril function that should be called upon opening the
     1049 * @param handler       Fibril function that should be called upon opening the
    10471050 *                      connection.
    1048  * @param carg          Extra argument to pass to the connection fibril
     1051 * @param data          Extra argument to pass to the connection fibril
    10491052 *
    10501053 * @return New fibril id or NULL on failure.
     
    10531056fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    10541057    ipc_callid_t callid, ipc_call_t *call,
    1055     async_client_conn_t cfibril, void *carg)
     1058    async_port_handler_t handler, void *data)
    10561059{
    10571060        connection_t *conn = malloc(sizeof(*conn));
     
    10681071        conn->callid = callid;
    10691072        conn->close_callid = 0;
    1070         conn->carg = carg;
     1073        conn->data = data;
    10711074       
    10721075        if (call)
     
    10751078        /* We will activate the fibril ASAP */
    10761079        conn->wdata.active = true;
    1077         conn->cfibril = cfibril;
     1080        conn->handler = handler;
    10781081        conn->wdata.fid = fibril_create(connection_fibril, conn);
    10791082       
     
    11111114        assert(call);
    11121115       
    1113         /* Unrouted call - take some default action */
     1116        /* Kernel notification */
    11141117        if ((callid & IPC_CALLID_NOTIFICATION)) {
    11151118                process_notification(callid, call);
     
    11221125                /* Open new connection with fibril, etc. */
    11231126                async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),
    1124                     callid, call, client_connection, NULL);
     1127                    callid, call, fallback_port_handler, fallback_port_data);
    11251128                return;
    11261129        }
     
    18201823 */
    18211824int async_connect_to_me(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
    1822     sysarg_t arg3, async_client_conn_t client_receiver, void *carg)
     1825    sysarg_t arg3, async_port_handler_t client_receiver, void *data)
    18231826{
    18241827        if (exch == NULL)
     
    18401843        if (client_receiver != NULL)
    18411844                async_new_connection(answer.in_task_id, phone_hash, 0, NULL,
    1842                     client_receiver, carg);
     1845                    client_receiver, data);
    18431846       
    18441847        return EOK;
Note: See TracChangeset for help on using the changeset viewer.