Rev 1500 | Rev 1552 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1500 | Rev 1547 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef _libc_ASYNC_H_ |
29 | #ifndef _libc_ASYNC_H_ |
30 | #define _libc_ASYNC_H_ |
30 | #define _libc_ASYNC_H_ |
31 | 31 | ||
32 | #include <ipc/ipc.h> |
32 | #include <ipc/ipc.h> |
33 | #include <psthread.h> |
33 | #include <psthread.h> |
34 | #include <sys/time.h> |
34 | #include <sys/time.h> |
35 | #include <atomic.h> |
35 | #include <atomic.h> |
36 | 36 | ||
37 | typedef ipc_callid_t aid_t; |
37 | typedef ipc_callid_t aid_t; |
38 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
38 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
39 | 39 | ||
40 | int async_manager(void); |
40 | int async_manager(void); |
41 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
41 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
42 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
42 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
43 | { |
43 | { |
44 | return async_get_call_timeout(data, 0); |
44 | return async_get_call_timeout(data, 0); |
45 | } |
45 | } |
46 | 46 | ||
47 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
47 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
48 | ipc_call_t *dataptr); |
48 | ipc_call_t *dataptr); |
- | 49 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
|
- | 50 | ipcarg_t arg3, ipc_call_t *dataptr); |
|
49 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
51 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
50 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
52 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
51 | 53 | ||
52 | /** Pseudo-synchronous message sending |
54 | /** Pseudo-synchronous message sending |
53 | * |
55 | * |
54 | * Send message through IPC, wait in the event loop, until it is received |
56 | * Send message through IPC, wait in the event loop, until it is received |
55 | * |
57 | * |
56 | * @return Return code of message |
58 | * @return Return code of message |
57 | */ |
59 | */ |
58 | static inline ipcarg_t sync_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2) |
60 | static inline ipcarg_t sync_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2) |
59 | { |
61 | { |
60 | ipc_call_t result; |
62 | ipc_call_t result; |
61 | ipcarg_t rc; |
63 | ipcarg_t rc; |
62 | 64 | ||
63 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
65 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
64 | async_wait_for(eid, &rc); |
66 | async_wait_for(eid, &rc); |
65 | if (r1) |
67 | if (r1) |
66 | *r1 = IPC_GET_ARG1(result); |
68 | *r1 = IPC_GET_ARG1(result); |
67 | if (r2) |
69 | if (r2) |
68 | *r2 = IPC_GET_ARG2(result); |
70 | *r2 = IPC_GET_ARG2(result); |
69 | return rc; |
71 | return rc; |
- | 72 | } |
|
- | 73 | static inline ipcarg_t sync_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
|
- | 74 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, |
|
- | 75 | ipcarg_t *r2, ipcarg_t *r3) |
|
- | 76 | { |
|
- | 77 | ipc_call_t result; |
|
- | 78 | ipcarg_t rc; |
|
- | 79 | ||
- | 80 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result); |
|
- | 81 | async_wait_for(eid, &rc); |
|
- | 82 | if (r1) |
|
- | 83 | *r1 = IPC_GET_ARG1(result); |
|
- | 84 | if (r2) |
|
- | 85 | *r2 = IPC_GET_ARG2(result); |
|
- | 86 | if (r3) |
|
- | 87 | *r3 = IPC_GET_ARG3(result); |
|
- | 88 | return rc; |
|
70 | } |
89 | } |
71 | 90 | ||
72 | 91 | ||
73 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
92 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
74 | ipc_call_t *call, |
93 | ipc_call_t *call, |
75 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
94 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
76 | void async_usleep(suseconds_t timeout); |
95 | void async_usleep(suseconds_t timeout); |
77 | void async_create_manager(void); |
96 | void async_create_manager(void); |
78 | void async_destroy_manager(void); |
97 | void async_destroy_manager(void); |
79 | void async_set_client_connection(async_client_conn_t conn); |
98 | void async_set_client_connection(async_client_conn_t conn); |
80 | int _async_init(void); |
99 | int _async_init(void); |
81 | 100 | ||
82 | /* Should be defined by application */ |
101 | /* Should be defined by application */ |
83 | void interrupt_received(ipc_call_t *call) __attribute__((weak)); |
102 | void interrupt_received(ipc_call_t *call) __attribute__((weak)); |
84 | 103 | ||
85 | 104 | ||
86 | extern atomic_t async_futex; |
105 | extern atomic_t async_futex; |
87 | 106 | ||
88 | #endif |
107 | #endif |
89 | 108 |