Changeset 53ca318 in mainline


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.

Location:
libc
Files:
4 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:
  • libc/generic/psthread.c

    r07d960a r53ca318  
    3636#include <futex.h>
    3737#include <assert.h>
     38#include <async.h>
    3839
    3940#ifndef PSTHREAD_INITIAL_STACK_PAGES_NO
     
    135136                goto ret_0;
    136137        }
    137         assert(!(ctype == PS_TO_MANAGER && list_empty(&manager_list)));
     138        /* If we are going to manager and none exists, create it */
     139        if (ctype == PS_TO_MANAGER && list_empty(&manager_list))
     140                async_create_manager();
    138141
    139142        pt = __tcb_get()->pst_data;
     
    251254        futex_down(&psthread_futex);
    252255        if (list_empty(&manager_list)) {
    253                 printf("No manager found!.\n");
    254256                futex_up(&psthread_futex);
    255257                return;
  • libc/generic/thread.c

    r07d960a r53ca318  
    9292        __tcb_set(pt->tcb);
    9393       
    94         async_create_manager();
    95 
    9694        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    9795        free(uarg->uspace_stack);
    9896        free(uarg);
    9997
     98        /* If there is a manager, destroy it */
    10099        async_destroy_manager();
    101100        psthread_teardown(pt);
  • libc/include/async.h

    r07d960a r53ca318  
    33
    44#include <ipc/ipc.h>
     5#include <psthread.h>
    56
    67int async_manager(void);
     
    1112
    1213/* Should be defined by application */
     14pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call,
     15                             void (*cthread)(ipc_callid_t,ipc_call_t *));
    1316void client_connection(ipc_callid_t callid, ipc_call_t *call) __attribute__((weak));
    1417
Note: See TracChangeset for help on using the changeset viewer.