Changeset a2cd194 in mainline for libc/generic/async.c


Ignore:
Timestamp:
2006-05-22T11:14:25Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8bc924e
Parents:
6862338
Message:

Added some cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/async.c

    r6862338 ra2cd194  
    7474 *       ....
    7575 * }
     76 *
     77 * TODO: Detaching/joining dead psthreads? */
    7678 */
    7779#include <futex.h>
     
    100102        pstid_t ptid;                /**< Thread associated with this connection */
    101103        int active;                     /**< If this thread is currently active */
    102         int opened;                    /* If the connection was accepted */
    103104        /* Structures for connection opening packet */
    104105        ipc_callid_t callid;
     
    110111/* Hash table functions */
    111112
    112 #define ASYNC_HASH_TABLE_CHAINS 32
     113#define CONN_HASH_TABLE_CHAINS  32
    113114
    114115static hash_index_t conn_hash(unsigned long *key)
    115116{
    116117        assert(key);
    117         return ((*key) >> 4) % ASYNC_HASH_TABLE_CHAINS;
     118        return ((*key) >> 4) % CONN_HASH_TABLE_CHAINS;
    118119}
    119120
     
    175176}
    176177
     178/** Return new incoming message for current(thread-local) connection */
    177179ipc_callid_t async_get_call(ipc_call_t *call)
    178180{
     
    200202}
    201203
     204/** Thread function that gets created on new connection
     205 *
     206 * This function is defined as a weak symbol - to be redefined in
     207 * user code.
     208 */
    202209void client_connection(ipc_callid_t callid, ipc_call_t *call)
    203210{
    204         printf("Got connection - no handler.\n");
    205         _exit(1);
    206 }
    207 
     211        ipc_answer_fast(callid, ENOENT, 0, 0);
     212}
     213
     214/** Wrapper for client connection thread
     215 *
     216 * When new connection arrives, thread with this function is created.
     217 * It calls client_connection and does final cleanup.
     218 *
     219 * @parameter arg Connection structure pointer
     220 */
    208221static int connection_thread(void  *arg)
    209222{
     223        unsigned long key;
     224        msg_t *msg;
     225
    210226        /* Setup thread local connection pointer */
    211227        PS_connection = (connection_t *)arg;
    212228        client_connection(PS_connection->callid, &PS_connection->call);
    213229
     230        /* Remove myself from connection hash table */
    214231        futex_down(&conn_futex);
    215         /* TODO: remove myself from connection hash table */
     232        key = PS_connection->in_phone_hash;
     233        hash_table_remove(&conn_hash_table, &key, 1);
    216234        futex_up(&conn_futex);
    217         /* TODO: answer all unanswered messages in queue with
    218          *       EHANGUP */
     235        /* Answer all remaining messages with ehangup */
     236        while (!list_empty(&PS_connection->msg_queue)) {
     237                msg = list_get_instance(PS_connection->msg_queue.next, msg_t, link);
     238                list_remove(&msg->link);
     239                ipc_answer_fast(msg->callid, EHANGUP, 0, 0);
     240                free(msg);
     241        }
    219242}
    220243
     
    239262        conn->in_phone_hash = IPC_GET_ARG3(*call);
    240263        list_initialize(&conn->msg_queue);
    241         conn->opened = 0;
    242264        conn->ptid = psthread_create(connection_thread, conn);
    243265        conn->callid = callid;
     
    298320}
    299321
     322/** Function to start async_manager as a standalone thread
     323 *
     324 * When more kernel threads are used, one async manager should
     325 * exist per thread. The particular implementation may change,
     326 * currently one async_manager is started automatically per kernel
     327 * thread except main thread.
     328 */
    300329static int async_manager_thread(void *arg)
    301330{
     
    323352int _async_init(void)
    324353{
    325         if (!hash_table_create(&conn_hash_table, ASYNC_HASH_TABLE_CHAINS, 1, &conn_hash_table_ops)) {
     354        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, &conn_hash_table_ops)) {
    326355                printf("%s: cannot create hash table\n", "async");
    327356                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.