Changeset 8b5690f in mainline for uspace/lib/c/generic/async_sess.c


Ignore:
Timestamp:
2011-02-03T05:11:01Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba38f72c
Parents:
22027b6e (diff), 86d7bfa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r22027b6e r8b5690f  
    9999
    100100#include <async_sess.h>
    101 #include <ipc/ipc.h>
    102101#include <fibril_synch.h>
    103102#include <adt/list.h>
     
    106105#include <errno.h>
    107106#include <assert.h>
     107#include "private/async_sess.h"
    108108
    109109/** An inactive open connection. */
    110110typedef struct {
    111111        link_t sess_link;       /**< Link for the session list of inactive connections. */
    112         link_t global_link;     /**< Link for the global list of inactive connectinos. */
     112        link_t global_link;     /**< Link for the global list of inactive connections. */
    113113        int data_phone;         /**< Connected data phone. */
    114114} conn_node_t;
    115115
    116116/**
    117  * Mutex protecting the inactive_conn_head list and the session list.
     117 * Mutex protecting the inactive_conn_head list, the session list and the
     118 * avail_phone condition variable.
    118119 */
    119120static fibril_mutex_t async_sess_mutex;
     
    129130static LIST_INITIALIZE(session_list_head);
    130131
     132/**
     133 * Condition variable used to wait for a phone to become available.
     134 */
     135static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv);
     136
    131137/** Initialize the async_sess subsystem.
    132138 *
    133139 * Needs to be called prior to any other interface in this file.
    134  */
    135 void _async_sess_init(void)
     140 *
     141 */
     142void __async_sess_init(void)
    136143{
    137144        fibril_mutex_initialize(&async_sess_mutex);
     
    194201                list_remove(&conn->global_link);
    195202               
    196                 ipc_hangup(conn->data_phone);
     203                async_hangup(conn->data_phone);
    197204                free(conn);
    198205        }
     206       
     207        fibril_condvar_broadcast(&avail_phone_cv);
    199208}
    200209
     
    252261                        data_phone = conn->data_phone;
    253262                        free(conn);
    254                         ipc_hangup(data_phone);
     263                        async_hangup(data_phone);
    255264                        goto retry;
    256265                } else {
    257266                        /*
    258                          * This is unfortunate. We failed both to find a cached
    259                          * connection or to create a new one even after cleaning up
    260                          * the cache. This is most likely due to too many
    261                          * open sessions (connected session phones).
     267                         * Wait for a phone to become available.
    262268                         */
    263                         data_phone = ELIMIT;
     269                        fibril_condvar_wait(&avail_phone_cv, &async_sess_mutex);
     270                        goto retry;
    264271                }
    265272        }
     
    279286
    280287        fibril_mutex_lock(&async_sess_mutex);
     288        fibril_condvar_signal(&avail_phone_cv);
    281289        conn = (conn_node_t *) malloc(sizeof(conn_node_t));
    282290        if (!conn) {
     
    285293                 * means that we simply hang up.
    286294                 */
     295                async_hangup(data_phone);
    287296                fibril_mutex_unlock(&async_sess_mutex);
    288                 ipc_hangup(data_phone);
    289297                return;
    290298        }
Note: See TracChangeset for help on using the changeset viewer.