Subversion Repositories HelenOS-historic

Rev

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

Rev 1503 Rev 1518
Line 131... Line 131...
131
 
131
 
132
    return call;
132
    return call;
133
}
133
}
134
 
134
 
135
/** Epilogue of ipc_async_send functions */
135
/** Epilogue of ipc_async_send functions */
136
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid, async_call_t *call)
136
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
-
 
137
                    async_call_t *call, int can_preempt)
137
{
138
{
138
    if (callid == IPC_CALLRET_FATAL) {
139
    if (callid == IPC_CALLRET_FATAL) {
139
        futex_up(&ipc_futex);
140
        futex_up(&ipc_futex);
140
        /* Call asynchronous handler with error code */
141
        /* Call asynchronous handler with error code */
141
        if (call->callback)
142
        if (call->callback)
Line 146... Line 147...
146
 
147
 
147
    if (callid == IPC_CALLRET_TEMPORARY) {
148
    if (callid == IPC_CALLRET_TEMPORARY) {
148
        futex_up(&ipc_futex);
149
        futex_up(&ipc_futex);
149
 
150
 
150
        call->u.msg.phoneid = phoneid;
151
        call->u.msg.phoneid = phoneid;
151
 
152
       
152
        call->ptid = psthread_get_id();
-
 
153
        futex_down(&async_futex);
153
        futex_down(&async_futex);
154
        list_append(&call->list, &queued_calls);
154
        list_append(&call->list, &queued_calls);
155
 
155
 
-
 
156
        if (can_preempt) {
-
 
157
            call->ptid = psthread_get_id();
156
        psthread_schedule_next_adv(PS_TO_MANAGER);
158
            psthread_schedule_next_adv(PS_TO_MANAGER);
157
        /* Async futex unlocked by previous call */
159
            /* Async futex unlocked by previous call */
-
 
160
        } else {
-
 
161
            call->ptid = 0;
-
 
162
            futex_up(&async_futex);
-
 
163
        }
158
        return;
164
        return;
159
    }
165
    }
160
    call->u.callid = callid;
166
    call->u.callid = callid;
161
    /* Add call to list of dispatched calls */
167
    /* Add call to list of dispatched calls */
162
    list_append(&call->list, &dispatched_calls);
168
    list_append(&call->list, &dispatched_calls);
Line 169... Line 175...
169
 * - if fatal error, call callback handler with proper error code
175
 * - if fatal error, call callback handler with proper error code
170
 * - if message cannot be temporarily sent, add to queue
176
 * - if message cannot be temporarily sent, add to queue
171
 */
177
 */
172
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
178
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
173
              ipcarg_t arg2, void *private,
179
              ipcarg_t arg2, void *private,
174
              ipc_async_callback_t callback)
180
              ipc_async_callback_t callback, int can_preempt)
175
{
181
{
176
    async_call_t *call;
182
    async_call_t *call;
177
    ipc_callid_t callid;
183
    ipc_callid_t callid;
178
 
184
 
179
    call = ipc_prepare_async(private, callback);
185
    call = ipc_prepare_async(private, callback);
Line 188... Line 194...
188
    if (callid == IPC_CALLRET_TEMPORARY) {
194
    if (callid == IPC_CALLRET_TEMPORARY) {
189
        IPC_SET_METHOD(call->u.msg.data, method);
195
        IPC_SET_METHOD(call->u.msg.data, method);
190
        IPC_SET_ARG1(call->u.msg.data, arg1);
196
        IPC_SET_ARG1(call->u.msg.data, arg1);
191
        IPC_SET_ARG2(call->u.msg.data, arg2);
197
        IPC_SET_ARG2(call->u.msg.data, arg2);
192
    }
198
    }
193
    ipc_finish_async(callid, phoneid, call);
199
    ipc_finish_async(callid, phoneid, call, can_preempt);
194
}
200
}
195
 
201
 
196
/** Send asynchronous message
202
/** Send asynchronous message
197
 *
203
 *
198
 * - if fatal error, call callback handler with proper error code
204
 * - if fatal error, call callback handler with proper error code
199
 * - if message cannot be temporarily sent, add to queue
205
 * - if message cannot be temporarily sent, add to queue
200
 */
206
 */
201
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
207
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
202
              ipcarg_t arg2, ipcarg_t arg3, void *private,
208
              ipcarg_t arg2, ipcarg_t arg3, void *private,
203
              ipc_async_callback_t callback)
209
              ipc_async_callback_t callback, int can_preempt)
204
{
210
{
205
    async_call_t *call;
211
    async_call_t *call;
206
    ipc_callid_t callid;
212
    ipc_callid_t callid;
207
 
213
 
208
    call = ipc_prepare_async(private, callback);
214
    call = ipc_prepare_async(private, callback);
Line 216... Line 222...
216
    /* We need to make sure that we get callid before
222
    /* We need to make sure that we get callid before
217
     * another thread accesses the queue again */
223
     * another thread accesses the queue again */
218
    futex_down(&ipc_futex);
224
    futex_down(&ipc_futex);
219
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
225
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
220
 
226
 
221
    ipc_finish_async(callid, phoneid, call);
227
    ipc_finish_async(callid, phoneid, call, can_preempt);
222
}
228
}
223
 
229
 
224
 
230
 
225
/** Send a fast answer to a received call.
231
/** Send a fast answer to a received call.
226
 *
232
 *
Line 274... Line 280...
274
            break;
280
            break;
275
        }
281
        }
276
        list_remove(&call->list);
282
        list_remove(&call->list);
277
 
283
 
278
        futex_up(&async_futex);
284
        futex_up(&async_futex);
-
 
285
        if (call->ptid)
279
        psthread_add_ready(call->ptid);
286
            psthread_add_ready(call->ptid);
280
       
287
       
281
        if (callid == IPC_CALLRET_FATAL) {
288
        if (callid == IPC_CALLRET_FATAL) {
282
            if (call->callback)
289
            if (call->callback)
283
                call->callback(call->private, ENOENT, NULL);
290
                call->callback(call->private, ENOENT, NULL);
284
            free(call);
291
            free(call);
Line 428... Line 435...
428
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
435
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
429
{
436
{
430
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
437
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
431
}
438
}
432
 
439
 
433
 
-
 
434
/** Open shared memory connection over specified phoneid
-
 
435
 *
-
 
436
 *
-
 
437
 * Allocate as_area, notify the other side about our intention
-
 
438
 * to open the connection
-
 
439
 *
-
 
440
 * @return Connection id identifying this connection
440
/* Primitive functions for simple communication */
441
 */
-
 
442
//int ipc_dgr_open(int pohoneid, size_t bufsize)
441
void send_call_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
443
//{
-
 
444
    /* Find new file descriptor in local descriptor table */
-
 
445
    /* Create AS_area, initialize structures */
-
 
446
    /* Send AS to other side, handle error states */
-
 
447
 
-
 
448
//}
-
 
449
/*
-
 
450
void ipc_dgr_close(int cid)
-
 
451
{
-
 
452
}
-
 
453
 
-
 
454
void * ipc_dgr_alloc(int cid, size_t size)
442
         ipcarg_t arg2, ipcarg_t arg3)
455
{
443
{
-
 
444
    ipc_call_async_3(phoneid, method, arg1, arg2, arg3, NULL, NULL, 1);
456
}
445
}
457
 
446
 
458
void ipc_dgr_free(int cid, void *area)
447
void send_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
459
{
448
{
460
 
-
 
-
 
449
    ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, 1);
461
}
450
}
462
 
451
 
-
 
452
void nsend_call_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
463
int ipc_dgr_send(int cid, void *area)
453
          ipcarg_t arg2, ipcarg_t arg3)
464
{
454
{
-
 
455
    ipc_call_async_3(phoneid, method, arg1, arg2, arg3, NULL, NULL, 0);
465
}
456
}
466
 
457
 
467
 
-
 
468
int ipc_dgr_send_data(int cid, void *data, size_t size)
458
void nsend_call_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2)
469
{
459
{
-
 
460
    ipc_call_async_2(phoneid, method, arg1, arg2, NULL, NULL, 0);
470
}
461
}
471
 
462
 
472
*/
-