Rev 2131 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1472 | palkovsky | 1 | /* |
| 2071 | jermar | 2 | * Copyright (c) 2006 Ondrej Palkovsky |
| 1472 | palkovsky | 3 | * All rights reserved. |
| 4 | * |
||
| 5 | * Redistribution and use in source and binary forms, with or without |
||
| 6 | * modification, are permitted provided that the following conditions |
||
| 7 | * are met: |
||
| 8 | * |
||
| 9 | * - Redistributions of source code must retain the above copyright |
||
| 10 | * notice, this list of conditions and the following disclaimer. |
||
| 11 | * - Redistributions in binary form must reproduce the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer in the |
||
| 13 | * documentation and/or other materials provided with the distribution. |
||
| 14 | * - The name of the author may not be used to endorse or promote products |
||
| 15 | * derived from this software without specific prior written permission. |
||
| 16 | * |
||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 27 | */ |
||
| 28 | |||
| 1866 | jermar | 29 | /** @addtogroup libc |
| 1653 | cejka | 30 | * @{ |
| 31 | */ |
||
| 32 | /** @file |
||
| 33 | */ |
||
| 34 | |||
| 1866 | jermar | 35 | #ifndef LIBC_ASYNC_H_ |
| 36 | #define LIBC_ASYNC_H_ |
||
| 1394 | palkovsky | 37 | |
| 38 | #include <ipc/ipc.h> |
||
| 1407 | palkovsky | 39 | #include <psthread.h> |
| 1449 | palkovsky | 40 | #include <sys/time.h> |
| 1463 | palkovsky | 41 | #include <atomic.h> |
| 1394 | palkovsky | 42 | |
| 1427 | palkovsky | 43 | typedef ipc_callid_t aid_t; |
| 1490 | palkovsky | 44 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
| 1427 | palkovsky | 45 | |
| 1610 | palkovsky | 46 | static inline void async_manager(void) |
| 47 | { |
||
| 48 | psthread_schedule_next_adv(PS_TO_MANAGER); |
||
| 49 | } |
||
| 50 | |||
| 1500 | palkovsky | 51 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
| 52 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
||
| 53 | { |
||
| 54 | return async_get_call_timeout(data, 0); |
||
| 55 | } |
||
| 1394 | palkovsky | 56 | |
| 1427 | palkovsky | 57 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
| 58 | ipc_call_t *dataptr); |
||
| 1547 | palkovsky | 59 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
| 60 | ipcarg_t arg3, ipc_call_t *dataptr); |
||
| 1427 | palkovsky | 61 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
| 1441 | palkovsky | 62 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
| 1464 | palkovsky | 63 | |
| 64 | /** Pseudo-synchronous message sending |
||
| 65 | * |
||
| 66 | * Send message through IPC, wait in the event loop, until it is received |
||
| 67 | * |
||
| 68 | * @return Return code of message |
||
| 69 | */ |
||
| 1610 | palkovsky | 70 | static inline ipcarg_t async_req_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2) |
| 1464 | palkovsky | 71 | { |
| 72 | ipc_call_t result; |
||
| 73 | ipcarg_t rc; |
||
| 74 | |||
| 75 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
||
| 76 | async_wait_for(eid, &rc); |
||
| 77 | if (r1) |
||
| 78 | *r1 = IPC_GET_ARG1(result); |
||
| 79 | if (r2) |
||
| 80 | *r2 = IPC_GET_ARG2(result); |
||
| 81 | return rc; |
||
| 82 | } |
||
| 1610 | palkovsky | 83 | #define async_req(phoneid, method, arg1, r1) async_req_2(phoneid, method, arg1, 0, r1, 0) |
| 1552 | palkovsky | 84 | |
| 1610 | palkovsky | 85 | static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
| 1547 | palkovsky | 86 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, |
| 87 | ipcarg_t *r2, ipcarg_t *r3) |
||
| 88 | { |
||
| 89 | ipc_call_t result; |
||
| 90 | ipcarg_t rc; |
||
| 1464 | palkovsky | 91 | |
| 1547 | palkovsky | 92 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result); |
| 93 | async_wait_for(eid, &rc); |
||
| 94 | if (r1) |
||
| 95 | *r1 = IPC_GET_ARG1(result); |
||
| 96 | if (r2) |
||
| 97 | *r2 = IPC_GET_ARG2(result); |
||
| 98 | if (r3) |
||
| 99 | *r3 = IPC_GET_ARG3(result); |
||
| 100 | return rc; |
||
| 101 | } |
||
| 1464 | palkovsky | 102 | |
| 1547 | palkovsky | 103 | |
| 1452 | palkovsky | 104 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
| 105 | ipc_call_t *call, |
||
| 106 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
||
| 107 | void async_usleep(suseconds_t timeout); |
||
| 1464 | palkovsky | 108 | void async_create_manager(void); |
| 109 | void async_destroy_manager(void); |
||
| 1490 | palkovsky | 110 | void async_set_client_connection(async_client_conn_t conn); |
| 1596 | palkovsky | 111 | void async_set_interrupt_received(async_client_conn_t conn); |
| 1464 | palkovsky | 112 | int _async_init(void); |
| 1427 | palkovsky | 113 | |
| 1394 | palkovsky | 114 | |
| 1610 | palkovsky | 115 | /* Primitve functions for IPC communication */ |
| 116 | void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
||
| 117 | ipcarg_t arg3); |
||
| 118 | void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2); |
||
| 2307 | hudecek | 119 | #define async_msg(ph, m, a1) async_msg_2(ph, m, a1, 0) |
| 1610 | palkovsky | 120 | |
| 121 | static inline void async_serialize_start(void) |
||
| 122 | { |
||
| 123 | psthread_inc_sercount(); |
||
| 124 | } |
||
| 2307 | hudecek | 125 | |
| 1610 | palkovsky | 126 | static inline void async_serialize_end(void) |
| 127 | { |
||
| 128 | psthread_dec_sercount(); |
||
| 129 | } |
||
| 130 | |||
| 1463 | palkovsky | 131 | extern atomic_t async_futex; |
| 1394 | palkovsky | 132 | #endif |
| 1653 | cejka | 133 | |
| 1866 | jermar | 134 | /** @} |
| 1653 | cejka | 135 | */ |