[c594489] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[c594489] | 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 |
|
---|
[fadd381] | 29 | /** @addtogroup libc
|
---|
[b2951e2] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[fadd381] | 35 | #ifndef LIBC_ASYNC_H_
|
---|
| 36 | #define LIBC_ASYNC_H_
|
---|
[630c3a9] | 37 |
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
[bc1f1c2] | 39 | #include <fibril.h>
|
---|
[f25b73d6] | 40 | #include <sys/time.h>
|
---|
[fc42b28] | 41 | #include <atomic.h>
|
---|
[630c3a9] | 42 |
|
---|
[01ff41c] | 43 | typedef ipc_callid_t aid_t;
|
---|
[da0c91e7] | 44 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call);
|
---|
[01ff41c] | 45 |
|
---|
[085bd54] | 46 | static inline void async_manager(void)
|
---|
| 47 | {
|
---|
[116d3f6f] | 48 | fibril_switch(FIBRIL_TO_MANAGER);
|
---|
[085bd54] | 49 | }
|
---|
| 50 |
|
---|
[49d072e] | 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 | }
|
---|
[440cff5] | 56 |
|
---|
[01ff41c] | 57 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
|
---|
[5d4e90f0] | 58 | ipc_call_t *dataptr);
|
---|
[90f5d64] | 59 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
|
---|
[5d4e90f0] | 60 | ipcarg_t arg3, ipc_call_t *dataptr);
|
---|
[01ff41c] | 61 | void async_wait_for(aid_t amsgid, ipcarg_t *result);
|
---|
[c042bdd] | 62 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout);
|
---|
[440cff5] | 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 | */
|
---|
[5d4e90f0] | 70 | static inline ipcarg_t async_req_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
|
---|
| 71 | ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2)
|
---|
[440cff5] | 72 | {
|
---|
| 73 | ipc_call_t result;
|
---|
| 74 | ipcarg_t rc;
|
---|
| 75 |
|
---|
| 76 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result);
|
---|
| 77 | async_wait_for(eid, &rc);
|
---|
| 78 | if (r1)
|
---|
| 79 | *r1 = IPC_GET_ARG1(result);
|
---|
| 80 | if (r2)
|
---|
| 81 | *r2 = IPC_GET_ARG2(result);
|
---|
| 82 | return rc;
|
---|
| 83 | }
|
---|
[5d4e90f0] | 84 | #define async_req(phoneid, method, arg1, r1) \
|
---|
| 85 | async_req_2(phoneid, method, arg1, 0, r1, 0)
|
---|
[429acb9] | 86 |
|
---|
[085bd54] | 87 | static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
|
---|
[5d4e90f0] | 88 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, ipcarg_t *r2, ipcarg_t *r3)
|
---|
[90f5d64] | 89 | {
|
---|
| 90 | ipc_call_t result;
|
---|
| 91 | ipcarg_t rc;
|
---|
| 92 |
|
---|
| 93 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result);
|
---|
| 94 | async_wait_for(eid, &rc);
|
---|
| 95 | if (r1)
|
---|
| 96 | *r1 = IPC_GET_ARG1(result);
|
---|
| 97 | if (r2)
|
---|
| 98 | *r2 = IPC_GET_ARG2(result);
|
---|
| 99 | if (r3)
|
---|
| 100 | *r3 = IPC_GET_ARG3(result);
|
---|
| 101 | return rc;
|
---|
| 102 | }
|
---|
[440cff5] | 103 |
|
---|
| 104 |
|
---|
[bc1f1c2] | 105 | fid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid,
|
---|
[26f2af0] | 106 | ipc_call_t *call, void (*cthread)(ipc_callid_t,ipc_call_t *));
|
---|
[44c6d88d] | 107 | void async_usleep(suseconds_t timeout);
|
---|
[440cff5] | 108 | void async_create_manager(void);
|
---|
| 109 | void async_destroy_manager(void);
|
---|
[da0c91e7] | 110 | void async_set_client_connection(async_client_conn_t conn);
|
---|
[51dbadf3] | 111 | void async_set_interrupt_received(async_client_conn_t conn);
|
---|
[440cff5] | 112 | int _async_init(void);
|
---|
[01ff41c] | 113 |
|
---|
[fc42b28] | 114 |
|
---|
[085bd54] | 115 | /* Primitve functions for IPC communication */
|
---|
| 116 | void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
|
---|
[5d4e90f0] | 117 | ipcarg_t arg3);
|
---|
[085bd54] | 118 | void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2);
|
---|
[3dbe2d1f] | 119 | #define async_msg(ph, m, a1) async_msg_2(ph, m, a1, 0)
|
---|
[085bd54] | 120 |
|
---|
| 121 | static inline void async_serialize_start(void)
|
---|
| 122 | {
|
---|
[bc1f1c2] | 123 | fibril_inc_sercount();
|
---|
[085bd54] | 124 | }
|
---|
[3dbe2d1f] | 125 |
|
---|
[085bd54] | 126 | static inline void async_serialize_end(void)
|
---|
| 127 | {
|
---|
[bc1f1c2] | 128 | fibril_dec_sercount();
|
---|
[085bd54] | 129 | }
|
---|
[fc42b28] | 130 |
|
---|
[085bd54] | 131 | extern atomic_t async_futex;
|
---|
[630c3a9] | 132 | #endif
|
---|
[b2951e2] | 133 |
|
---|
[fadd381] | 134 | /** @}
|
---|
[b2951e2] | 135 | */
|
---|