Changeset 9db9b10 in mainline for uspace/lib/libc/generic/async.c


Ignore:
Timestamp:
2009-06-03T19:16:07Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
937aeee
Parents:
e77994dd
Message:

async framework: add generic support for processing pending operations (in a separate fibril)
coding style

File:
1 edited

Legend:

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

    re77994dd r9db9b10  
    179179static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
    180180static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
     181static void default_pending(void);
    181182
    182183/**
     
    191192static async_client_conn_t interrupt_received = default_interrupt_received;
    192193
     194/**
     195 * Pointer to a fibril function that will be used to handle pending
     196 * operations.
     197 */
     198static async_pending_t pending = default_pending;
    193199
    194200static hash_table_t conn_hash_table;
    195201static LIST_INITIALIZE(timeout_list);
    196 
    197202
    198203#define CONN_HASH_TABLE_CHAINS  32
     
    371376       
    372377        fid_t fid = fibril_create(notification_fibril, msg);
     378        fibril_add_ready(fid);
     379       
     380        futex_up(&async_futex);
     381        return true;
     382}
     383
     384/** Pending fibril.
     385 *
     386 * After each call the pending operations are executed in a separate
     387 * fibril. The function pending() is c.
     388 *
     389 * @param arg Unused.
     390 *
     391 * @return Always zero.
     392 *
     393 */
     394static int pending_fibril(void *arg)
     395{
     396        pending();
     397       
     398        return 0;
     399}
     400
     401/** Process pending actions.
     402 *
     403 * A new fibril is created which would process the pending operations.
     404 *
     405 * @return False if an error occured.
     406 *         True if the execution was passed to the pending fibril.
     407 *
     408 */
     409static bool process_pending(void)
     410{
     411        futex_down(&async_futex);
     412       
     413        fid_t fid = fibril_create(pending_fibril, NULL);
    373414        fibril_add_ready(fid);
    374415       
     
    473514}
    474515
     516/** Default fibril function that gets called to handle pending operations.
     517 *
     518 * This function is defined as a weak symbol - to be redefined in user code.
     519 *
     520 */
     521static void default_pending(void)
     522{
     523}
     524
    475525/** Wrapper for client connection fibril.
    476526 *
     
    564614       
    565615        /* Add connection to the connection hash table */
    566         ipcarg_t key = conn->in_phone_hash;
     616        unsigned long key = conn->in_phone_hash;
    567617       
    568618        futex_down(&async_futex);
     
    589639        if ((callid & IPC_CALLID_NOTIFICATION)) {
    590640                process_notification(callid, call);
    591                 return;
     641                goto out;
    592642        }
    593643       
     
    598648                async_new_connection(IPC_GET_ARG5(*call), callid, call,
    599649                    client_connection);
    600                 return;
     650                goto out;
    601651        }
    602652       
    603653        /* Try to route the call through the connection hash table */
    604654        if (route_call(callid, call))
    605                 return;
     655                goto out;
    606656       
    607657        /* Unknown call from unknown phone - hang it up */
    608658        ipc_answer_0(callid, EHANGUP);
     659        return;
     660       
     661out:
     662        process_pending();
    609663}
    610664
     
    760814static void reply_received(void *arg, int retval, ipc_call_t *data)
    761815{
     816        futex_down(&async_futex);
     817       
    762818        amsg_t *msg = (amsg_t *) arg;
    763819        msg->retval = retval;
    764820       
    765         futex_down(&async_futex);
    766        
    767821        /* Copy data after futex_down, just in case the call was detached */
    768         if (msg->dataptr)
     822        if ((msg->dataptr) && (data))
    769823                *msg->dataptr = *data;
    770824       
     
    9931047{
    9941048        interrupt_received = intr;
     1049}
     1050
     1051/** Setter for pending function pointer.
     1052 *
     1053 * @param pend Function that will implement a new pending
     1054 *             operations fibril.
     1055 */
     1056void async_set_pending(async_pending_t pend)
     1057{
     1058        pending = pend;
    9951059}
    9961060
Note: See TracChangeset for help on using the changeset viewer.