Changeset 53ca318 in mainline for libc/generic/async.c


Ignore:
Timestamp:
2006-05-23T11:01:31Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8c6b45f
Parents:
07d960a
Message:

Small updates to asynchronous framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/async.c

    r07d960a r53ca318  
    6161 * 2) Multithreaded server application
    6262 * main() {
    63  *      wait_for_connection(new_connection);
     63 *      async_manager();
    6464 * }
    6565 *
    6666 *
    67  * new_connection(int connection) {
    68  *       accept(connection);
    69  *       msg = get_msg();
    70  *       handle(msg);
    71  *       answer(msg);
    72  *
    73  *       msg = get_msg();
     67 * client_connection(icallid, *icall) {
     68 *       if (want_refuse) {
     69 *           ipc_answer_fast(icallid, ELIMIT, 0, 0);
     70 *           return;
     71 *       }
     72 *       ipc_answer_fast(icallid, 0, 0, 0);
     73 *
     74 *       callid = async_get_call(&call);
     75 *       handle(callid, call);
     76 *       ipc_answer_fast(callid, 1,2,3);
     77 *
     78 *       callid = async_get_call(&call);
    7479 *       ....
    7580 * }
     
    105110        ipc_callid_t callid;
    106111        ipc_call_t call;
     112        void (*cthread)(ipc_callid_t,ipc_call_t *);
    107113} connection_t;
    108114
     
    226232        /* Setup thread local connection pointer */
    227233        PS_connection = (connection_t *)arg;
    228         client_connection(PS_connection->callid, &PS_connection->call);
     234        PS_connection->cthread(PS_connection->callid, &PS_connection->call);
    229235
    230236        /* Remove myself from connection hash table */
     
    248254 * later we can easily do routing of messages to particular
    249255 * threads.
    250  */
    251 static void new_connection(ipc_callid_t callid, ipc_call_t *call)
     256 *
     257 * @param callid Callid of the IPC_M_CONNECT_ME_TO packet
     258 * @param call Call data of the opening packet
     259 * @param cthread Thread function that should be called upon
     260 *                opening the connection
     261 * @return New thread id
     262 */
     263pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
     264                             void (*cthread)(ipc_callid_t,ipc_call_t *))
    252265{
    253266        pstid_t ptid;
     
    258271        if (!conn) {
    259272                ipc_answer_fast(callid, ENOMEM, 0, 0);
    260                 return;
     273                return NULL;
    261274        }
    262275        conn->in_phone_hash = IPC_GET_ARG3(*call);
     
    266279        conn->call = *call;
    267280        conn->active = 1; /* We will activate it asap */
     281        conn->cthread = cthread;
    268282        list_initialize(&conn->link);
    269283        if (!conn->ptid) {
    270284                free(conn);
    271285                ipc_answer_fast(callid, ENOMEM, 0, 0);
    272                 return;
     286                return NULL;
    273287        }
    274288        key = conn->in_phone_hash;
     
    279293
    280294        psthread_add_ready(conn->ptid);
     295
     296        return conn->ptid;
    281297}
    282298
     
    292308        case IPC_M_CONNECT_ME_TO:
    293309                /* Open new connection with thread etc. */
    294                 new_connection(callid, call);
     310                async_new_connection(callid, call, client_connection);
    295311                break;
    296312        default:
Note: See TracChangeset for help on using the changeset viewer.