Ignore:
File:
1 edited

Legend:

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

    rc170438 r9ef495f  
    493493}
    494494
     495static size_t notification_handler_stksz = FIBRIL_DFLT_STK_SIZE;
     496
     497/** Set the stack size for the notification handler notification fibrils.
     498 *
     499 * @param size Stack size in bytes.
     500 */
     501void async_set_notification_handler_stack_size(size_t size)
     502{
     503        notification_handler_stksz = size;
     504}
     505
    495506/** Mutex protecting inactive_exch_list and avail_phone_cv.
    496507 *
     
    987998}
    988999
    989 /** Process notification.
    990  *
    991  * @param callid Hash of the incoming call.
    992  * @param call   Data of the incoming call.
    993  */
    994 static void process_notification(ipc_callid_t callid, ipc_call_t *call)
    995 {
     1000/** Notification fibril.
     1001 *
     1002 * When a notification arrives, a fibril with this implementing function is
     1003 * created. It calls the corresponding notification handler and does the final
     1004 * cleanup.
     1005 *
     1006 * @param arg Message structure pointer.
     1007 *
     1008 * @return Always zero.
     1009 *
     1010 */
     1011static int notification_fibril(void *arg)
     1012{
     1013        assert(arg);
     1014       
     1015        msg_t *msg = (msg_t *) arg;
    9961016        async_notification_handler_t handler = NULL;
    9971017        void *data = NULL;
    998 
    999         assert(call);
    10001018       
    10011019        futex_down(&async_futex);
    10021020       
    10031021        ht_link_t *link = hash_table_find(&notification_hash_table,
    1004             &IPC_GET_IMETHOD(*call));
     1022            &IPC_GET_IMETHOD(msg->call));
    10051023        if (link) {
    10061024                notification_t *notification =
     
    10131031       
    10141032        if (handler)
    1015                 handler(callid, call, data);
     1033                handler(msg->callid, &msg->call, data);
     1034       
     1035        free(msg);
     1036        return 0;
     1037}
     1038
     1039/** Process notification.
     1040 *
     1041 * A new fibril is created which would process the notification.
     1042 *
     1043 * @param callid Hash of the incoming call.
     1044 * @param call   Data of the incoming call.
     1045 *
     1046 * @return False if an error occured.
     1047 *         True if the call was passed to the notification fibril.
     1048 *
     1049 */
     1050static bool process_notification(ipc_callid_t callid, ipc_call_t *call)
     1051{
     1052        assert(call);
     1053       
     1054        futex_down(&async_futex);
     1055       
     1056        msg_t *msg = malloc(sizeof(*msg));
     1057        if (!msg) {
     1058                futex_up(&async_futex);
     1059                return false;
     1060        }
     1061       
     1062        msg->callid = callid;
     1063        msg->call = *call;
     1064       
     1065        fid_t fid = fibril_create_generic(notification_fibril, msg,
     1066            notification_handler_stksz);
     1067        if (fid == 0) {
     1068                free(msg);
     1069                futex_up(&async_futex);
     1070                return false;
     1071        }
     1072       
     1073        fibril_add_ready(fid);
     1074       
     1075        futex_up(&async_futex);
     1076        return true;
    10161077}
    10171078
     
    13141375        /* Kernel notification */
    13151376        if ((callid & IPC_CALLID_NOTIFICATION)) {
    1316                 fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data;
    1317                 unsigned oldsw = fibril->switches;
    1318 
    13191377                process_notification(callid, call);
    1320 
    1321                 if (oldsw != fibril->switches) {
    1322                         /*
    1323                          * The notification handler did not execute atomically
    1324                          * and so the current manager fibril assumed the role of
    1325                          * a notification fibril. While waiting for its
    1326                          * resources, it switched to another manager fibril that
    1327                          * had already existed or it created a new one. We
    1328                          * therefore know there is at least yet another
    1329                          * manager fibril that can take over. We now kill the
    1330                          * current 'notification' fibril to prevent fibril
    1331                          * population explosion.
    1332                          */
    1333                         futex_down(&async_futex);
    1334                         fibril_switch(FIBRIL_FROM_DEAD);
    1335                 }
    13361378                return;
    13371379        }
     
    15081550void async_create_manager(void)
    15091551{
    1510         fid_t fid = fibril_create_generic(async_manager_fibril, NULL, PAGE_SIZE);
     1552        fid_t fid = fibril_create(async_manager_fibril, NULL);
    15111553        if (fid != 0)
    15121554                fibril_add_manager(fid);
     
    16321674       
    16331675        ipc_call_async_4(exch->phone, imethod, arg1, arg2, arg3, arg4, msg,
    1634             reply_received);
     1676            reply_received, true);
    16351677       
    16361678        return (aid_t) msg;
     
    16701712       
    16711713        ipc_call_async_5(exch->phone, imethod, arg1, arg2, arg3, arg4, arg5,
    1672             msg, reply_received);
     1714            msg, reply_received, true);
    16731715       
    16741716        return (aid_t) msg;
     
    19592001{
    19602002        if (exch != NULL)
    1961                 ipc_call_async_0(exch->phone, imethod, NULL, NULL);
     2003                ipc_call_async_0(exch->phone, imethod, NULL, NULL, true);
    19622004}
    19632005
     
    19652007{
    19662008        if (exch != NULL)
    1967                 ipc_call_async_1(exch->phone, imethod, arg1, NULL, NULL);
     2009                ipc_call_async_1(exch->phone, imethod, arg1, NULL, NULL, true);
    19682010}
    19692011
     
    19722014{
    19732015        if (exch != NULL)
    1974                 ipc_call_async_2(exch->phone, imethod, arg1, arg2, NULL, NULL);
     2016                ipc_call_async_2(exch->phone, imethod, arg1, arg2, NULL, NULL,
     2017                    true);
    19752018}
    19762019
     
    19802023        if (exch != NULL)
    19812024                ipc_call_async_3(exch->phone, imethod, arg1, arg2, arg3, NULL,
    1982                     NULL);
     2025                    NULL, true);
    19832026}
    19842027
     
    19882031        if (exch != NULL)
    19892032                ipc_call_async_4(exch->phone, imethod, arg1, arg2, arg3, arg4,
    1990                     NULL, NULL);
     2033                    NULL, NULL, true);
    19912034}
    19922035
     
    19962039        if (exch != NULL)
    19972040                ipc_call_async_5(exch->phone, imethod, arg1, arg2, arg3, arg4,
    1998                     arg5, NULL, NULL);
     2041                    arg5, NULL, NULL, true);
    19992042}
    20002043
     
    21192162       
    21202163        ipc_call_async_0(exch->phone, IPC_M_CLONE_ESTABLISH, msg,
    2121             reply_received);
     2164            reply_received, true);
    21222165       
    21232166        sysarg_t rc;
     
    21682211       
    21692212        ipc_call_async_4(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, arg4,
    2170             msg, reply_received);
     2213            msg, reply_received, true);
    21712214       
    21722215        sysarg_t rc;
Note: See TracChangeset for help on using the changeset viewer.