Changeset 53ca318 in mainline
- Timestamp:
- 2006-05-23T11:01:31Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c6b45f
- Parents:
- 07d960a
- Location:
- libc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/async.c
r07d960a r53ca318 61 61 * 2) Multithreaded server application 62 62 * main() { 63 * wait_for_connection(new_connection);63 * async_manager(); 64 64 * } 65 65 * 66 66 * 67 * new_connection(int connection) { 68 * accept(connection); 69 * msg = get_msg(); 70 * handle(msg); 71 * answer(msg); 72 * 73 * msg = get_msg(); 67 * client_connection(icallid, *icall) { 68 * if (want_refuse) { 69 * ipc_answer_fast(icallid, ELIMIT, 0, 0); 70 * return; 71 * } 72 * ipc_answer_fast(icallid, 0, 0, 0); 73 * 74 * callid = async_get_call(&call); 75 * handle(callid, call); 76 * ipc_answer_fast(callid, 1,2,3); 77 * 78 * callid = async_get_call(&call); 74 79 * .... 75 80 * } … … 105 110 ipc_callid_t callid; 106 111 ipc_call_t call; 112 void (*cthread)(ipc_callid_t,ipc_call_t *); 107 113 } connection_t; 108 114 … … 226 232 /* Setup thread local connection pointer */ 227 233 PS_connection = (connection_t *)arg; 228 client_connection(PS_connection->callid, &PS_connection->call);234 PS_connection->cthread(PS_connection->callid, &PS_connection->call); 229 235 230 236 /* Remove myself from connection hash table */ … … 248 254 * later we can easily do routing of messages to particular 249 255 * threads. 250 */ 251 static void new_connection(ipc_callid_t callid, ipc_call_t *call) 256 * 257 * @param callid Callid of the IPC_M_CONNECT_ME_TO packet 258 * @param call Call data of the opening packet 259 * @param cthread Thread function that should be called upon 260 * opening the connection 261 * @return New thread id 262 */ 263 pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call, 264 void (*cthread)(ipc_callid_t,ipc_call_t *)) 252 265 { 253 266 pstid_t ptid; … … 258 271 if (!conn) { 259 272 ipc_answer_fast(callid, ENOMEM, 0, 0); 260 return ;273 return NULL; 261 274 } 262 275 conn->in_phone_hash = IPC_GET_ARG3(*call); … … 266 279 conn->call = *call; 267 280 conn->active = 1; /* We will activate it asap */ 281 conn->cthread = cthread; 268 282 list_initialize(&conn->link); 269 283 if (!conn->ptid) { 270 284 free(conn); 271 285 ipc_answer_fast(callid, ENOMEM, 0, 0); 272 return ;286 return NULL; 273 287 } 274 288 key = conn->in_phone_hash; … … 279 293 280 294 psthread_add_ready(conn->ptid); 295 296 return conn->ptid; 281 297 } 282 298 … … 292 308 case IPC_M_CONNECT_ME_TO: 293 309 /* Open new connection with thread etc. */ 294 new_connection(callid, call);310 async_new_connection(callid, call, client_connection); 295 311 break; 296 312 default: -
libc/generic/psthread.c
r07d960a r53ca318 36 36 #include <futex.h> 37 37 #include <assert.h> 38 #include <async.h> 38 39 39 40 #ifndef PSTHREAD_INITIAL_STACK_PAGES_NO … … 135 136 goto ret_0; 136 137 } 137 assert(!(ctype == PS_TO_MANAGER && list_empty(&manager_list))); 138 /* If we are going to manager and none exists, create it */ 139 if (ctype == PS_TO_MANAGER && list_empty(&manager_list)) 140 async_create_manager(); 138 141 139 142 pt = __tcb_get()->pst_data; … … 251 254 futex_down(&psthread_futex); 252 255 if (list_empty(&manager_list)) { 253 printf("No manager found!.\n");254 256 futex_up(&psthread_futex); 255 257 return; -
libc/generic/thread.c
r07d960a r53ca318 92 92 __tcb_set(pt->tcb); 93 93 94 async_create_manager();95 96 94 uarg->uspace_thread_function(uarg->uspace_thread_arg); 97 95 free(uarg->uspace_stack); 98 96 free(uarg); 99 97 98 /* If there is a manager, destroy it */ 100 99 async_destroy_manager(); 101 100 psthread_teardown(pt); -
libc/include/async.h
r07d960a r53ca318 3 3 4 4 #include <ipc/ipc.h> 5 #include <psthread.h> 5 6 6 7 int async_manager(void); … … 11 12 12 13 /* Should be defined by application */ 14 pstid_t async_new_connection(ipc_callid_t callid, ipc_call_t *call, 15 void (*cthread)(ipc_callid_t,ipc_call_t *)); 13 16 void client_connection(ipc_callid_t callid, ipc_call_t *call) __attribute__((weak)); 14 17
Note:
See TracChangeset
for help on using the changeset viewer.