Subversion Repositories HelenOS-historic

Rev

Rev 1463 | Rev 1503 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1463 Rev 1489
Line 113... Line 113...
113
static  ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
113
static  ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
114
{
114
{
115
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data);
115
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data);
116
}
116
}
117
 
117
 
118
/** Send asynchronous message
118
/** Prolog to ipc_async_send functions */
119
 *
-
 
120
 * - if fatal error, call callback handler with proper error code
-
 
121
 * - if message cannot be temporarily sent, add to queue
-
 
122
 */
-
 
123
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
-
 
124
              ipcarg_t arg2, void *private,
-
 
125
              ipc_async_callback_t callback)
119
static inline async_call_t *ipc_prepare_async(void *private, ipc_async_callback_t callback)
126
{
120
{
127
    async_call_t *call;
121
    async_call_t *call;
128
    ipc_callid_t callid;
-
 
129
 
122
 
130
    call = malloc(sizeof(*call));
123
    call = malloc(sizeof(*call));
131
    if (!call) {
124
    if (!call) {
132
        if (callback)
125
        if (callback)
133
            callback(private, ENOMEM, NULL);
126
            callback(private, ENOMEM, NULL);
134
        return;
127
        return NULL;
135
    }
128
    }
136
 
-
 
137
    call->callback = callback;
129
    call->callback = callback;
138
    call->private = private;
130
    call->private = private;
139
 
131
 
140
    /* We need to make sure that we get callid before
132
    return call;
-
 
133
}
-
 
134
 
141
     * another thread accesses the queue again */
135
/** Epilogue of ipc_async_send functions */
142
    futex_down(&ipc_futex);
-
 
143
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1, arg2);
136
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid, async_call_t *call)
-
 
137
{
144
    if (callid == IPC_CALLRET_FATAL) {
138
    if (callid == IPC_CALLRET_FATAL) {
145
        futex_up(&ipc_futex);
139
        futex_up(&ipc_futex);
146
        /* Call asynchronous handler with error code */
140
        /* Call asynchronous handler with error code */
147
        if (callback)
141
        if (call->callback)
148
            callback(private, ENOENT, NULL);
142
            call->callback(call->private, ENOENT, NULL);
149
        free(call);
143
        free(call);
150
        return;
144
        return;
151
    }
145
    }
152
 
146
 
153
    if (callid == IPC_CALLRET_TEMPORARY) {
147
    if (callid == IPC_CALLRET_TEMPORARY) {
154
        futex_up(&ipc_futex);
148
        futex_up(&ipc_futex);
155
 
149
 
156
        call->u.msg.phoneid = phoneid;
150
        call->u.msg.phoneid = phoneid;
157
        IPC_SET_METHOD(call->u.msg.data, method);
-
 
158
        IPC_SET_ARG1(call->u.msg.data, arg1);
-
 
159
        IPC_SET_ARG2(call->u.msg.data, arg2);
-
 
160
 
151
 
161
        call->ptid = psthread_get_id();
152
        call->ptid = psthread_get_id();
162
        futex_down(&async_futex);
153
        futex_down(&async_futex);
163
        list_append(&call->list, &queued_calls);
154
        list_append(&call->list, &queued_calls);
164
 
155
 
Line 168... Line 159...
168
    }
159
    }
169
    call->u.callid = callid;
160
    call->u.callid = callid;
170
    /* Add call to list of dispatched calls */
161
    /* Add call to list of dispatched calls */
171
    list_append(&call->list, &dispatched_calls);
162
    list_append(&call->list, &dispatched_calls);
172
    futex_up(&ipc_futex);
163
    futex_up(&ipc_futex);
-
 
164
   
-
 
165
}
-
 
166
 
-
 
167
/** Send asynchronous message
-
 
168
 *
-
 
169
 * - if fatal error, call callback handler with proper error code
-
 
170
 * - if message cannot be temporarily sent, add to queue
-
 
171
 */
-
 
172
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
-
 
173
              ipcarg_t arg2, void *private,
-
 
174
              ipc_async_callback_t callback)
-
 
175
{
-
 
176
    async_call_t *call;
-
 
177
    ipc_callid_t callid;
-
 
178
 
-
 
179
    call = ipc_prepare_async(private, callback);
-
 
180
    if (!call)
-
 
181
        return;
-
 
182
 
-
 
183
    /* We need to make sure that we get callid before
-
 
184
     * another thread accesses the queue again */
-
 
185
    futex_down(&ipc_futex);
-
 
186
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1, arg2);
-
 
187
 
-
 
188
    if (callid == IPC_CALLRET_TEMPORARY) {
-
 
189
        IPC_SET_METHOD(call->u.msg.data, method);
-
 
190
        IPC_SET_ARG1(call->u.msg.data, arg1);
-
 
191
        IPC_SET_ARG2(call->u.msg.data, arg2);
-
 
192
    }
-
 
193
    ipc_finish_async(callid, phoneid, call);
-
 
194
}
-
 
195
 
-
 
196
/** Send asynchronous message
-
 
197
 *
-
 
198
 * - if fatal error, call callback handler with proper error code
-
 
199
 * - if message cannot be temporarily sent, add to queue
-
 
200
 */
-
 
201
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
-
 
202
              ipcarg_t arg2, ipcarg_t arg3, void *private,
-
 
203
              ipc_async_callback_t callback)
-
 
204
{
-
 
205
    async_call_t *call;
-
 
206
    ipc_callid_t callid;
-
 
207
 
-
 
208
    call = ipc_prepare_async(private, callback);
-
 
209
    if (!call)
-
 
210
        return;
-
 
211
 
-
 
212
    IPC_SET_METHOD(call->u.msg.data, method);
-
 
213
    IPC_SET_ARG1(call->u.msg.data, arg1);
-
 
214
    IPC_SET_ARG2(call->u.msg.data, arg2);
-
 
215
    IPC_SET_ARG3(call->u.msg.data, arg3);
-
 
216
    /* We need to make sure that we get callid before
-
 
217
     * another thread accesses the queue again */
-
 
218
    futex_down(&ipc_futex);
-
 
219
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
-
 
220
 
-
 
221
    ipc_finish_async(callid, phoneid, call);
173
}
222
}
174
 
223
 
175
 
224
 
176
/** Send a fast answer to a received call.
225
/** Send a fast answer to a received call.
177
 *
226
 *