Rev 1610 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1610 | Rev 1653 | ||
---|---|---|---|
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 | /** @addtogroup libc |
|
- | 30 | * @{ |
|
- | 31 | */ |
|
- | 32 | /** @file |
|
- | 33 | */ |
|
- | 34 | ||
29 | #ifndef _libc_ASYNC_H_ |
35 | #ifndef _libc_ASYNC_H_ |
30 | #define _libc_ASYNC_H_ |
36 | #define _libc_ASYNC_H_ |
31 | 37 | ||
32 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
33 | #include <psthread.h> |
39 | #include <psthread.h> |
34 | #include <sys/time.h> |
40 | #include <sys/time.h> |
35 | #include <atomic.h> |
41 | #include <atomic.h> |
36 | 42 | ||
37 | typedef ipc_callid_t aid_t; |
43 | typedef ipc_callid_t aid_t; |
38 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
44 | typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); |
39 | 45 | ||
40 | static inline void async_manager(void) |
46 | static inline void async_manager(void) |
41 | { |
47 | { |
42 | psthread_schedule_next_adv(PS_TO_MANAGER); |
48 | psthread_schedule_next_adv(PS_TO_MANAGER); |
43 | } |
49 | } |
44 | 50 | ||
45 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
51 | ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); |
46 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
52 | static inline ipc_callid_t async_get_call(ipc_call_t *data) |
47 | { |
53 | { |
48 | return async_get_call_timeout(data, 0); |
54 | return async_get_call_timeout(data, 0); |
49 | } |
55 | } |
50 | 56 | ||
51 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
57 | aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
52 | ipc_call_t *dataptr); |
58 | ipc_call_t *dataptr); |
53 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
59 | aid_t async_send_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
54 | ipcarg_t arg3, ipc_call_t *dataptr); |
60 | ipcarg_t arg3, ipc_call_t *dataptr); |
55 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
61 | void async_wait_for(aid_t amsgid, ipcarg_t *result); |
56 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
62 | int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, suseconds_t timeout); |
57 | 63 | ||
58 | /** Pseudo-synchronous message sending |
64 | /** Pseudo-synchronous message sending |
59 | * |
65 | * |
60 | * Send message through IPC, wait in the event loop, until it is received |
66 | * Send message through IPC, wait in the event loop, until it is received |
61 | * |
67 | * |
62 | * @return Return code of message |
68 | * @return Return code of message |
63 | */ |
69 | */ |
64 | static inline ipcarg_t async_req_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t *r1, ipcarg_t *r2) |
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) |
65 | { |
71 | { |
66 | ipc_call_t result; |
72 | ipc_call_t result; |
67 | ipcarg_t rc; |
73 | ipcarg_t rc; |
68 | 74 | ||
69 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
75 | aid_t eid = async_send_2(phoneid, method, arg1, arg2, &result); |
70 | async_wait_for(eid, &rc); |
76 | async_wait_for(eid, &rc); |
71 | if (r1) |
77 | if (r1) |
72 | *r1 = IPC_GET_ARG1(result); |
78 | *r1 = IPC_GET_ARG1(result); |
73 | if (r2) |
79 | if (r2) |
74 | *r2 = IPC_GET_ARG2(result); |
80 | *r2 = IPC_GET_ARG2(result); |
75 | return rc; |
81 | return rc; |
76 | } |
82 | } |
77 | #define async_req(phoneid, method, arg1, r1) async_req_2(phoneid, method, arg1, 0, r1, 0) |
83 | #define async_req(phoneid, method, arg1, r1) async_req_2(phoneid, method, arg1, 0, r1, 0) |
78 | 84 | ||
79 | static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
85 | static inline ipcarg_t async_req_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
80 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, |
86 | ipcarg_t arg2, ipcarg_t arg3, ipcarg_t *r1, |
81 | ipcarg_t *r2, ipcarg_t *r3) |
87 | ipcarg_t *r2, ipcarg_t *r3) |
82 | { |
88 | { |
83 | ipc_call_t result; |
89 | ipc_call_t result; |
84 | ipcarg_t rc; |
90 | ipcarg_t rc; |
85 | 91 | ||
86 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result); |
92 | aid_t eid = async_send_3(phoneid, method, arg1, arg2, arg3, &result); |
87 | async_wait_for(eid, &rc); |
93 | async_wait_for(eid, &rc); |
88 | if (r1) |
94 | if (r1) |
89 | *r1 = IPC_GET_ARG1(result); |
95 | *r1 = IPC_GET_ARG1(result); |
90 | if (r2) |
96 | if (r2) |
91 | *r2 = IPC_GET_ARG2(result); |
97 | *r2 = IPC_GET_ARG2(result); |
92 | if (r3) |
98 | if (r3) |
93 | *r3 = IPC_GET_ARG3(result); |
99 | *r3 = IPC_GET_ARG3(result); |
94 | return rc; |
100 | return rc; |
95 | } |
101 | } |
96 | 102 | ||
97 | 103 | ||
98 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
104 | pstid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid, |
99 | ipc_call_t *call, |
105 | ipc_call_t *call, |
100 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
106 | void (*cthread)(ipc_callid_t,ipc_call_t *)); |
101 | void async_usleep(suseconds_t timeout); |
107 | void async_usleep(suseconds_t timeout); |
102 | void async_create_manager(void); |
108 | void async_create_manager(void); |
103 | void async_destroy_manager(void); |
109 | void async_destroy_manager(void); |
104 | void async_set_client_connection(async_client_conn_t conn); |
110 | void async_set_client_connection(async_client_conn_t conn); |
105 | void async_set_interrupt_received(async_client_conn_t conn); |
111 | void async_set_interrupt_received(async_client_conn_t conn); |
106 | int _async_init(void); |
112 | int _async_init(void); |
107 | 113 | ||
108 | 114 | ||
109 | /* Primitve functions for IPC communication */ |
115 | /* Primitve functions for IPC communication */ |
110 | void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
116 | void async_msg_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
111 | ipcarg_t arg3); |
117 | ipcarg_t arg3); |
112 | void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2); |
118 | void async_msg_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2); |
113 | #define async_msg(ph,m,a1) async_msg_2(ph,m,a1,0) |
119 | #define async_msg(ph,m,a1) async_msg_2(ph,m,a1,0) |
114 | 120 | ||
115 | static inline void async_serialize_start(void) |
121 | static inline void async_serialize_start(void) |
116 | { |
122 | { |
117 | psthread_inc_sercount(); |
123 | psthread_inc_sercount(); |
118 | } |
124 | } |
119 | static inline void async_serialize_end(void) |
125 | static inline void async_serialize_end(void) |
120 | { |
126 | { |
121 | psthread_dec_sercount(); |
127 | psthread_dec_sercount(); |
122 | } |
128 | } |
123 | 129 | ||
124 | extern atomic_t async_futex; |
130 | extern atomic_t async_futex; |
125 | #endif |
131 | #endif |
- | 132 | ||
- | 133 | ||
- | 134 | /** @} |
|
- | 135 | */ |
|
- | 136 | ||
- | 137 | ||
126 | 138 |