Changeset 085bd54 in mainline for libc/generic/async.c


Ignore:
Timestamp:
2006-06-06T15:16:08Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63bb83e
Parents:
d7eafd8
Message:

Revised ipc. Now it is preferrable to use only functions from async.h, they
take care of correct buffering, waiting for answers etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/async.c

    rd7eafd8 r085bd54  
    135135} connection_t;
    136136
    137 
     137/** Identifier of incoming connection handled by current thread */
    138138__thread connection_t *PS_connection;
     139/** If true, it is forbidden to use async_req functions and
     140 *  all preemption is disabled */
     141__thread int in_interrupt_handler;
    139142
    140143static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
     
    226229
    227230        wd->timedout = 0;
     231        wd->inlist = 1;
    228232
    229233        tmp = timeout_list.next;
     
    295299        conn = PS_connection;
    296300
    297         if (usecs < 0) /* TODO: let it get through the ipc_call once */
    298                 return 0;
    299 
    300301        futex_down(&async_futex);
    301302
     
    308309        /* If nothing in queue, wait until something appears */
    309310        while (list_empty(&conn->msg_queue)) {
    310                 if (usecs) {
    311                         conn->wdata.inlist = 1;
     311                if (usecs)
    312312                        insert_timeout(&conn->wdata);
    313                 }
     313
    314314                conn->wdata.active = 0;
    315315                psthread_schedule_next_adv(PS_TO_MANAGER);
     
    363363        PS_connection = (connection_t *)arg;
    364364        PS_connection->cthread(PS_connection->callid, &PS_connection->call);
    365 
    366365        /* Remove myself from connection hash table */
    367366        futex_down(&async_futex);
     
    436435        switch (IPC_GET_METHOD(*call)) {
    437436        case IPC_M_INTERRUPT:
     437                in_interrupt_handler = 1;
    438438                (*interrupt_received)(callid,call);
     439                in_interrupt_handler = 0;
    439440                return;
    440441        case IPC_M_CONNECT_ME_TO:
     
    486487
    487488/** Endless loop dispatching incoming calls and answers */
    488 int async_manager(void)
     489static int async_manager_worker(void)
    489490{
    490491        ipc_call_t call;
     
    522523                }
    523524
    524                 if (callid & IPC_CALLID_ANSWERED)
     525                if (callid & IPC_CALLID_ANSWERED) {
    525526                        continue;
     527                }
    526528
    527529                handle_call(callid, &call);
     
    538540static int async_manager_thread(void *arg)
    539541{
     542        in_interrupt_handler = 0; // TODO: Handle TLS better
    540543        futex_up(&async_futex); /* async_futex is always locked when entering
    541544                                * manager */
    542         async_manager();
     545        async_manager_worker();
    543546}
    544547
     
    608611        amsg_t *msg;
    609612
     613        if (in_interrupt_handler) {
     614                printf("Cannot send asynchronou request in interrupt handler.\n");
     615                _exit(1);
     616        }
     617
    610618        msg = malloc(sizeof(*msg));
    611619        msg->done = 0;
     
    628636{
    629637        amsg_t *msg;
     638
     639        if (in_interrupt_handler) {
     640                printf("Cannot send asynchronou request in interrupt handler.\n");
     641                _exit(1);
     642        }
    630643
    631644        msg = malloc(sizeof(*msg));
     
    699712        msg->wdata.ptid = psthread_get_id();
    700713        msg->wdata.active = 0;
    701         msg->wdata.inlist = 1;
    702 
    703714        insert_timeout(&msg->wdata);
    704715
     
    726737        amsg_t *msg;
    727738       
     739        if (in_interrupt_handler) {
     740                printf("Cannot call async_usleep in interrupt handler.\n");
     741                _exit(1);
     742        }
     743
    728744        msg = malloc(sizeof(*msg));
    729745        if (!msg)
     
    731747
    732748        msg->wdata.ptid = psthread_get_id();
    733         msg->wdata.inlist = 1;
    734749        msg->wdata.active = 0;
    735750
     
    757772        interrupt_received = conn;
    758773}
     774
     775/* Primitive functions for simple communication */
     776void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
     777                 ipcarg_t arg2, ipcarg_t arg3)
     778{
     779        ipc_call_async_3(phoneid, method, arg1, arg2, arg3, NULL, NULL, !in_interrupt_handler);
     780}
     781
     782void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
     783{
     784        ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, !in_interrupt_handler);
     785}
Note: See TracChangeset for help on using the changeset viewer.