Changeset a2cd194 in mainline for libc/generic/async.c
- Timestamp:
- 2006-05-22T11:14:25Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8bc924e
- Parents:
- 6862338
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/async.c
r6862338 ra2cd194 74 74 * .... 75 75 * } 76 * 77 * TODO: Detaching/joining dead psthreads? */ 76 78 */ 77 79 #include <futex.h> … … 100 102 pstid_t ptid; /**< Thread associated with this connection */ 101 103 int active; /**< If this thread is currently active */ 102 int opened; /* If the connection was accepted */103 104 /* Structures for connection opening packet */ 104 105 ipc_callid_t callid; … … 110 111 /* Hash table functions */ 111 112 112 #define ASYNC_HASH_TABLE_CHAINS 32113 #define CONN_HASH_TABLE_CHAINS 32 113 114 114 115 static hash_index_t conn_hash(unsigned long *key) 115 116 { 116 117 assert(key); 117 return ((*key) >> 4) % ASYNC_HASH_TABLE_CHAINS;118 return ((*key) >> 4) % CONN_HASH_TABLE_CHAINS; 118 119 } 119 120 … … 175 176 } 176 177 178 /** Return new incoming message for current(thread-local) connection */ 177 179 ipc_callid_t async_get_call(ipc_call_t *call) 178 180 { … … 200 202 } 201 203 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 */ 202 209 void client_connection(ipc_callid_t callid, ipc_call_t *call) 203 210 { 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 */ 208 221 static int connection_thread(void *arg) 209 222 { 223 unsigned long key; 224 msg_t *msg; 225 210 226 /* Setup thread local connection pointer */ 211 227 PS_connection = (connection_t *)arg; 212 228 client_connection(PS_connection->callid, &PS_connection->call); 213 229 230 /* Remove myself from connection hash table */ 214 231 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); 216 234 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 } 219 242 } 220 243 … … 239 262 conn->in_phone_hash = IPC_GET_ARG3(*call); 240 263 list_initialize(&conn->msg_queue); 241 conn->opened = 0;242 264 conn->ptid = psthread_create(connection_thread, conn); 243 265 conn->callid = callid; … … 298 320 } 299 321 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 */ 300 329 static int async_manager_thread(void *arg) 301 330 { … … 323 352 int _async_init(void) 324 353 { 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)) { 326 355 printf("%s: cannot create hash table\n", "async"); 327 356 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.