Changeset c1c0184 in mainline
- Timestamp:
- 2010-12-26T17:18:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d3cce52
- Parents:
- 7907cf9
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r7907cf9 rc1c0184 749 749 return ENOMEM; 750 750 } 751 752 _async_sess_init(); 751 753 752 754 return 0; -
uspace/lib/c/generic/async_sess.c
r7907cf9 rc1c0184 107 107 #include <assert.h> 108 108 109 #define SESSION_HASH_BUCKETS 16110 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 117 109 typedef struct { 118 110 link_t conn_link; /**< Link for the list of connections. */ … … 132 124 133 125 /** 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); 159 129 160 130 /** Initialize the async_sess subsystem. … … 162 132 * Needs to be called prior to any other interface in this file. 163 133 */ 164 intasync_sess_init(void)134 void _async_sess_init(void) 165 135 { 166 136 fibril_mutex_initialize(&async_sess_mutex); 167 137 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 140 void async_session_create(async_sess_t *sess, int phone) 141 { 142 sess->sess_phone = phone; 143 list_initialize(&sess->conn_head); 144 } 145 146 void async_session_destroy(async_sess_t *sess) 147 { 175 148 sess->sess_phone = -1; 176 list_initialize(&sess->conn_head);149 /* todo */ 177 150 } 178 151 … … 186 159 /** Start new transaction in a session. 187 160 * 188 * @param sess_phone Phone representing the session.161 * @param sess_phone Session. 189 162 * @return Phone representing the new transaction or a negative error 190 163 * code. 191 164 */ 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; 165 int async_transaction_begin(async_sess_t *sess) 166 { 197 167 conn_node_t *conn; 198 168 int data_phone; 199 169 200 170 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 allocate205 * 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-time211 * attempt to create a phone without trying to add the212 * 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 }226 171 227 172 if (!list_empty(&sess->conn_head)) { … … 242 187 */ 243 188 retry: 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); 245 190 if (data_phone >= 0) { 246 191 /* success, do nothing */ … … 276 221 /** Finish a transaction. 277 222 * 278 * @param sess _phone Phone representing the session.223 * @param sess Session. 279 224 * @param data_phone Phone representing the transaction within the session. 280 225 */ 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; 226 void async_transaction_end(async_sess_t *sess, int data_phone) 227 { 285 228 conn_node_t *conn; 286 link_t *lnk;287 229 288 230 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);292 231 conn = (conn_node_t *) malloc(sizeof(conn_node_t)); 293 232 if (!conn) { -
uspace/lib/c/generic/libc.c
r7907cf9 rc1c0184 66 66 __heap_init(); 67 67 __async_init(); 68 (void) async_sess_init();69 68 fibril_t *fibril = fibril_setup(); 70 69 __tcb_set(fibril->tcb); -
uspace/lib/c/include/async.h
r7907cf9 rc1c0184 37 37 38 38 #include <ipc/ipc.h> 39 #include <async_sess.h> 39 40 #include <fibril.h> 40 41 #include <sys/time.h> -
uspace/lib/c/include/async_sess.h
r7907cf9 rc1c0184 36 36 #define LIBC_ASYNC_SESS_H_ 37 37 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 40 typedef 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 45 extern void _async_sess_init(void); 46 extern void async_session_create(async_sess_t *, int); 47 extern void async_session_destroy(async_sess_t *); 48 extern int async_transaction_begin(async_sess_t *); 49 extern void async_transaction_end(async_sess_t *, int); 41 50 42 51 #endif -
uspace/srv/vfs/vfs.h
r7907cf9 rc1c0184 34 34 #define VFS_VFS_H_ 35 35 36 #include <async.h> 36 37 #include <ipc/ipc.h> 37 38 #include <adt/list.h> … … 54 55 fs_handle_t fs_handle; 55 56 fibril_mutex_t phone_lock; 56 sysarg_t phone;57 async_sess_t session; 57 58 } fs_info_t; 58 59 -
uspace/srv/vfs/vfs_register.c
r7907cf9 rc1c0184 111 111 void vfs_register(ipc_callid_t rid, ipc_call_t *request) 112 112 { 113 int phone; 114 113 115 dprintf("Processing VFS_REGISTER request received from %p.\n", 114 116 request->in_phone_hash); … … 186 188 return; 187 189 } 188 fs_info->phone = IPC_GET_ARG5(call); 190 191 phone = IPC_GET_ARG5(call); 192 async_session_create(&fs_info->session, phone); 189 193 ipc_answer_0(callid, EOK); 190 194 … … 200 204 list_remove(&fs_info->fs_link); 201 205 fibril_mutex_unlock(&fs_head_lock); 202 ipc_hangup(fs_info->phone); 206 async_session_destroy(&fs_info->session); 207 ipc_hangup(phone); 203 208 free(fs_info); 204 209 ipc_answer_0(callid, EINVAL); … … 214 219 list_remove(&fs_info->fs_link); 215 220 fibril_mutex_unlock(&fs_head_lock); 216 ipc_hangup(fs_info->phone); 221 async_session_destroy(&fs_info->session); 222 ipc_hangup(phone); 217 223 free(fs_info); 218 224 ipc_answer_0(callid, EINVAL); … … 270 276 fibril_mutex_unlock(&fs_head_lock); 271 277 fibril_mutex_lock(&fs->phone_lock); 272 phone = async_transaction_begin( fs->phone);278 phone = async_transaction_begin(&fs->session); 273 279 fibril_mutex_unlock(&fs->phone_lock); 274 280 … … 296 302 fibril_mutex_unlock(&fs_head_lock); 297 303 fibril_mutex_lock(&fs->phone_lock); 298 async_transaction_end( fs->phone, phone);304 async_transaction_end(&fs->session, phone); 299 305 fibril_mutex_unlock(&fs->phone_lock); 300 306 return;
Note:
See TracChangeset
for help on using the changeset viewer.