Changeset c1c0184 in mainline


Ignore:
Timestamp:
2010-12-26T17:18:36Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d3cce52
Parents:
7907cf9
Message:

Make session management explicit.

Location:
uspace
Files:
7 edited

Legend:

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

    r7907cf9 rc1c0184  
    749749                return ENOMEM;
    750750        }
     751
     752        _async_sess_init();
    751753       
    752754        return 0;
  • uspace/lib/c/generic/async_sess.c

    r7907cf9 rc1c0184  
    107107#include <assert.h>
    108108
    109 #define SESSION_HASH_BUCKETS    16
    110 
    111 typedef struct {
    112         link_t link;            /**< Session hash table link. */
    113         int sess_phone;         /**< The phone serving as session identifier. */
    114         link_t conn_head;       /**< List of open connections. */
    115 } sess_node_t;
    116 
    117109typedef struct {
    118110        link_t conn_link;       /**< Link for the list of connections. */
     
    132124
    133125/**
    134  * Hash table mapping session phone IDs to session records.
    135  */
    136 static hash_table_t session_ht;
    137 
    138 static hash_index_t sess_ht_hash(unsigned long *key)
    139 {
    140         return *key % SESSION_HASH_BUCKETS;
    141 }
    142 
    143 static int sess_ht_compare(unsigned long *key, hash_count_t keys, link_t *item)
    144 {
    145         sess_node_t *sess = hash_table_get_instance(item, sess_node_t, link);
    146 
    147         return *key == (unsigned long) sess->sess_phone;
    148 }
    149 
    150 static void sess_ht_remove(link_t *item)
    151 {
    152 }
    153 
    154 static hash_table_operations_t session_hash_ops = {
    155         .hash = sess_ht_hash,
    156         .compare = sess_ht_compare,
    157         .remove_callback = sess_ht_remove
    158 };
     126 * List of all existing sessions.
     127 */
     128//static LIST_INITIALIZE(session_list);
    159129
    160130/** Initialize the async_sess subsystem.
     
    162132 * Needs to be called prior to any other interface in this file.
    163133 */
    164 int async_sess_init(void)
     134void _async_sess_init(void)
    165135{
    166136        fibril_mutex_initialize(&async_sess_mutex);
    167137        list_initialize(&inactive_conn_head);
    168         return hash_table_create(&session_ht, SESSION_HASH_BUCKETS, 1,
    169             &session_hash_ops);
    170 }
    171 
    172 static void sess_node_initialize(sess_node_t *sess)
    173 {
    174         link_initialize(&sess->link);
     138}
     139
     140void async_session_create(async_sess_t *sess, int phone)
     141{
     142        sess->sess_phone = phone;
     143        list_initialize(&sess->conn_head);
     144}
     145
     146void async_session_destroy(async_sess_t *sess)
     147{
    175148        sess->sess_phone = -1;
    176         list_initialize(&sess->conn_head);
     149        /* todo */
    177150}
    178151
     
    186159/** Start new transaction in a session.
    187160 *
    188  * @param sess_phone    Phone representing the session.
     161 * @param sess_phone    Session.
    189162 * @return              Phone representing the new transaction or a negative error
    190163 *                      code.
    191164 */
    192 int async_transaction_begin(int sess_phone)
    193 {
    194         unsigned long key = (unsigned long) sess_phone;
    195         link_t *lnk;
    196         sess_node_t *sess;
     165int async_transaction_begin(async_sess_t *sess)
     166{
    197167        conn_node_t *conn;
    198168        int data_phone;
    199169
    200170        fibril_mutex_lock(&async_sess_mutex);
    201         lnk = hash_table_find(&session_ht, &key);
    202         if (!lnk) {
    203                 /*
    204                  * The session node was not found in the hash table. Try to allocate
    205                  * and hash in a new one.
    206                  */
    207                 sess = (sess_node_t *) malloc(sizeof(sess_node_t));
    208                 if (!sess) {
    209                         /*
    210                          * As a possible improvement, we could make a one-time
    211                          * attempt to create a phone without trying to add the
    212                          * key node into the hash.
    213                          */
    214                         fibril_mutex_unlock(&async_sess_mutex);
    215                         return ENOMEM;
    216                 }
    217                 sess_node_initialize(sess);
    218                 sess->sess_phone = sess_phone;
    219                 hash_table_insert(&session_ht, &key, &sess->link);
    220         } else {
    221                 /*
    222                  * Found the session node.
    223                  */
    224                 sess = hash_table_get_instance(lnk, sess_node_t, link);
    225         }
    226171
    227172        if (!list_empty(&sess->conn_head)) {
     
    242187                 */
    243188retry:
    244                 data_phone = async_connect_me_to(sess_phone, 0, 0, 0);
     189                data_phone = async_connect_me_to(sess->sess_phone, 0, 0, 0);
    245190                if (data_phone >= 0) {
    246191                        /* success, do nothing */
     
    276221/** Finish a transaction.
    277222 *
    278  * @param sess_phone    Phone representing the session.
     223 * @param sess          Session.
    279224 * @param data_phone    Phone representing the transaction within the session.
    280225 */
    281 void async_transaction_end(int sess_phone, int data_phone)
    282 {
    283         unsigned long key = (unsigned long) sess_phone;
    284         sess_node_t *sess;
     226void async_transaction_end(async_sess_t *sess, int data_phone)
     227{
    285228        conn_node_t *conn;
    286         link_t *lnk;
    287229
    288230        fibril_mutex_lock(&async_sess_mutex);
    289         lnk = hash_table_find(&session_ht, &key);
    290         assert(lnk);
    291         sess = hash_table_get_instance(lnk, sess_node_t, link);
    292231        conn = (conn_node_t *) malloc(sizeof(conn_node_t));
    293232        if (!conn) {
  • uspace/lib/c/generic/libc.c

    r7907cf9 rc1c0184  
    6666        __heap_init();
    6767        __async_init();
    68         (void) async_sess_init();
    6968        fibril_t *fibril = fibril_setup();
    7069        __tcb_set(fibril->tcb);
  • uspace/lib/c/include/async.h

    r7907cf9 rc1c0184  
    3737
    3838#include <ipc/ipc.h>
     39#include <async_sess.h>
    3940#include <fibril.h>
    4041#include <sys/time.h>
  • uspace/lib/c/include/async_sess.h

    r7907cf9 rc1c0184  
    3636#define LIBC_ASYNC_SESS_H_
    3737
    38 extern int async_sess_init(void);
    39 extern int async_transaction_begin(int);
    40 extern void async_transaction_end(int, int);
     38#include <adt/list.h>
     39
     40typedef struct {
     41        int sess_phone;         /**< Phone for cloning off the connections. */
     42        link_t conn_head;       /**< List of open data connections. */
     43} async_sess_t;
     44
     45extern void _async_sess_init(void);
     46extern void async_session_create(async_sess_t *, int);
     47extern void async_session_destroy(async_sess_t *);
     48extern int async_transaction_begin(async_sess_t *);
     49extern void async_transaction_end(async_sess_t *, int);
    4150
    4251#endif
  • uspace/srv/vfs/vfs.h

    r7907cf9 rc1c0184  
    3434#define VFS_VFS_H_
    3535
     36#include <async.h>
    3637#include <ipc/ipc.h>
    3738#include <adt/list.h>
     
    5455        fs_handle_t fs_handle;
    5556        fibril_mutex_t phone_lock;
    56         sysarg_t phone;
     57        async_sess_t session;
    5758} fs_info_t;
    5859
  • uspace/srv/vfs/vfs_register.c

    r7907cf9 rc1c0184  
    111111void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    112112{
     113        int phone;
     114       
    113115        dprintf("Processing VFS_REGISTER request received from %p.\n",
    114116            request->in_phone_hash);
     
    186188                return;
    187189        }
    188         fs_info->phone = IPC_GET_ARG5(call);
     190       
     191        phone = IPC_GET_ARG5(call);
     192        async_session_create(&fs_info->session, phone);
    189193        ipc_answer_0(callid, EOK);
    190194       
     
    200204                list_remove(&fs_info->fs_link);
    201205                fibril_mutex_unlock(&fs_head_lock);
    202                 ipc_hangup(fs_info->phone);
     206                async_session_destroy(&fs_info->session);
     207                ipc_hangup(phone);
    203208                free(fs_info);
    204209                ipc_answer_0(callid, EINVAL);
     
    214219                list_remove(&fs_info->fs_link);
    215220                fibril_mutex_unlock(&fs_head_lock);
    216                 ipc_hangup(fs_info->phone);
     221                async_session_destroy(&fs_info->session);
     222                ipc_hangup(phone);
    217223                free(fs_info);
    218224                ipc_answer_0(callid, EINVAL);
     
    270276                        fibril_mutex_unlock(&fs_head_lock);
    271277                        fibril_mutex_lock(&fs->phone_lock);
    272                         phone = async_transaction_begin(fs->phone);
     278                        phone = async_transaction_begin(&fs->session);
    273279                        fibril_mutex_unlock(&fs->phone_lock);
    274280
     
    296302                        fibril_mutex_unlock(&fs_head_lock);
    297303                        fibril_mutex_lock(&fs->phone_lock);
    298                         async_transaction_end(fs->phone, phone);
     304                        async_transaction_end(&fs->session, phone);
    299305                        fibril_mutex_unlock(&fs->phone_lock);
    300306                        return;
Note: See TracChangeset for help on using the changeset viewer.