Changeset 9591265 in mainline
- Timestamp:
- 2007-06-28T19:45:36Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2f0392
- Parents:
- 12f91130
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
r12f91130 r9591265 36 36 * Asynchronous library 37 37 * 38 * The aim of this library is facilitating writing programs utilizing 39 * the asynchronous nature of HelenOS IPC, yet using a normal way 40 * of programming. 41 * 42 * You should be able to write very simple multithreaded programs, 43 * the async framework will automatically take care of most synchronization 44 * problems. 38 * The aim of this library is facilitating writing programs utilizing the 39 * asynchronous nature of HelenOS IPC, yet using a normal way of programming. 40 * 41 * You should be able to write very simple multithreaded programs, the async 42 * framework will automatically take care of most synchronization problems. 45 43 * 46 44 * Default semantics: 47 * - send() - send asynchronously. If the kernel refuses to send more48 * messages, [ try to get responses from kernel, if nothing49 * 50 * 51 * Example of use :45 * - async_send_*(): send asynchronously. If the kernel refuses to send 46 * more messages, [ try to get responses from kernel, if 47 * nothing found, might try synchronous ] 48 * 49 * Example of use (pseudo C): 52 50 * 53 51 * 1) Multithreaded client application 54 * fibril_create(fibril1); 55 * fibril_create(fibril2); 56 * ... 52 * 53 * fibril_create(fibril1, ...); 54 * fibril_create(fibril2, ...); 55 * ... 57 56 * 58 * fibril1() { 59 * conn = ipc_connect_me_to(); 60 * c1 = send(conn); 61 * c2 = send(conn); 62 * wait_for(c1); 63 * wait_for(c2); 64 * } 57 * int fibril1(void *arg) 58 * { 59 * conn = ipc_connect_me_to(); 60 * c1 = async_send(conn); 61 * c2 = async_send(conn); 62 * async_wait_for(c1); 63 * async_wait_for(c2); 64 * ... 65 * } 65 66 * 66 67 * 67 68 * 2) Multithreaded server application 68 * main() { 69 * async_manager(); 69 * main() 70 * { 71 * async_manager(); 70 72 * } 71 73 * 72 74 * 73 * client_connection(icallid, *icall) { 74 * if (want_refuse) { 75 * ipc_answer_fast(icallid, ELIMIT, 0, 0); 76 * return; 77 * } 78 * ipc_answer_fast(icallid, 0, 0, 0); 79 * 80 * callid = async_get_call(&call); 81 * handle(callid, call); 82 * ipc_answer_fast(callid, 1, 2, 3); 83 * 84 * callid = async_get_call(&call); 85 * .... 75 * client_connection(icallid, *icall) 76 * { 77 * if (want_refuse) { 78 * ipc_answer_fast(icallid, ELIMIT, 0, 0); 79 * return; 80 * } 81 * ipc_answer_fast(icallid, EOK, 0, 0); 82 * 83 * callid = async_get_call(&call); 84 * handle_call(callid, call); 85 * ipc_answer_fast(callid, 1, 2, 3); 86 * 87 * callid = async_get_call(&call); 88 * .... 86 89 * } 87 90 * 88 91 */ 92 89 93 #include <futex.h> 90 94 #include <async.h> … … 568 572 * exist per thread. The particular implementation may change, 569 573 * currently one async_manager is started automatically per kernel 570 * thread except main thread.571 */ 572 static int async_manager_ thread(void *arg)574 * thread except the main thread. 575 */ 576 static int async_manager_fibril(void *arg) 573 577 { 574 578 futex_up(&async_futex); … … 585 589 fid_t fid; 586 590 587 fid = fibril_create(async_manager_ thread, NULL);591 fid = fibril_create(async_manager_fibril, NULL); 588 592 fibril_add_manager(fid); 589 593 }
Note:
See TracChangeset
for help on using the changeset viewer.