Subversion Repositories HelenOS

Rev

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

Rev 1343 Rev 1350
Line 31... Line 31...
31
#include <malloc.h>
31
#include <malloc.h>
32
#include <errno.h>
32
#include <errno.h>
33
#include <list.h>
33
#include <list.h>
34
#include <stdio.h>
34
#include <stdio.h>
35
#include <unistd.h>
35
#include <unistd.h>
-
 
36
#include <futex.h>
36
 
37
 
37
/** Structure used for keeping track of sent async msgs
38
/** Structure used for keeping track of sent async msgs
38
 * and queing unsent msgs
39
 * and queing unsent msgs
39
 *
40
 *
40
 */
41
 */
Line 53... Line 54...
53
} async_call_t;
54
} async_call_t;
54
 
55
 
55
LIST_INITIALIZE(dispatched_calls);
56
LIST_INITIALIZE(dispatched_calls);
56
LIST_INITIALIZE(queued_calls);
57
LIST_INITIALIZE(queued_calls);
57
 
58
 
-
 
59
static atomic_t ipc_futex;
-
 
60
 
-
 
61
void _ipc_init(void)
-
 
62
{
-
 
63
    futex_initialize(&ipc_futex, 1);
-
 
64
}
-
 
65
 
58
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
66
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
59
          ipcarg_t *result)
67
          ipcarg_t *result)
60
{
68
{
61
    ipc_call_t resdata;
69
    ipc_call_t resdata;
62
    int callres;
70
    int callres;
Line 135... Line 143...
135
        /* Add asynchronous call to queue of non-dispatched async calls */
143
        /* Add asynchronous call to queue of non-dispatched async calls */
136
        call->u.msg.phoneid = phoneid;
144
        call->u.msg.phoneid = phoneid;
137
        IPC_SET_METHOD(call->u.msg.data, method);
145
        IPC_SET_METHOD(call->u.msg.data, method);
138
        IPC_SET_ARG1(call->u.msg.data, arg1);
146
        IPC_SET_ARG1(call->u.msg.data, arg1);
139
        IPC_SET_ARG2(call->u.msg.data, arg2);
147
        IPC_SET_ARG2(call->u.msg.data, arg2);
140
 
148
       
-
 
149
        futex_down(&ipc_futex);
141
        list_append(&call->list, &queued_calls);
150
        list_append(&call->list, &queued_calls);
-
 
151
        futex_up(&ipc_futex);
142
        return;
152
        return;
143
    }
153
    }
144
    call->u.callid = callid;
154
    call->u.callid = callid;
145
    /* Add call to list of dispatched calls */
155
    /* Add call to list of dispatched calls */
-
 
156
    futex_down(&ipc_futex);
146
    list_append(&call->list, &dispatched_calls);
157
    list_append(&call->list, &dispatched_calls);
-
 
158
    futex_up(&ipc_futex);
147
}
159
}
148
 
160
 
149
 
161
 
150
/** Send a fast answer to a received call.
162
/** Send a fast answer to a received call.
151
 *
163
 *
Line 182... Line 194...
182
static void try_dispatch_queued_calls(void)
194
static void try_dispatch_queued_calls(void)
183
{
195
{
184
    async_call_t *call;
196
    async_call_t *call;
185
    ipc_callid_t callid;
197
    ipc_callid_t callid;
186
 
198
 
-
 
199
    futex_down(&ipc_futex);
187
    while (!list_empty(&queued_calls)) {
200
    while (!list_empty(&queued_calls)) {
188
        call = list_get_instance(queued_calls.next, async_call_t,
201
        call = list_get_instance(queued_calls.next, async_call_t,
189
                     list);
202
                     list);
190
 
203
 
191
        callid = _ipc_call_async(call->u.msg.phoneid,
204
        callid = _ipc_call_async(call->u.msg.phoneid,
192
                     &call->u.msg.data);
205
                     &call->u.msg.data);
193
        if (callid == IPC_CALLRET_TEMPORARY)
206
        if (callid == IPC_CALLRET_TEMPORARY)
194
            break;
207
            break;
195
        list_remove(&call->list);
208
        list_remove(&call->list);
-
 
209
 
196
        if (callid == IPC_CALLRET_FATAL) {
210
        if (callid == IPC_CALLRET_FATAL) {
-
 
211
            futex_up(&ipc_futex);
197
            call->callback(call->private, ENOENT, NULL);
212
            call->callback(call->private, ENOENT, NULL);
198
            free(call);
213
            free(call);
-
 
214
            futex_down(&ipc_futex);
199
        } else {
215
        } else {
200
            call->u.callid = callid;
216
            call->u.callid = callid;
201
            list_append(&call->list, &dispatched_calls);
217
            list_append(&call->list, &dispatched_calls);
202
        }
218
        }
203
    }
219
    }
-
 
220
    futex_up(&ipc_futex);
204
}
221
}
205
 
222
 
206
/** Handle received answer
223
/** Handle received answer
207
 *
224
 *
208
 * TODO: Make it use hash table
225
 * TODO: Make it use hash table
Line 214... Line 231...
214
    link_t *item;
231
    link_t *item;
215
    async_call_t *call;
232
    async_call_t *call;
216
 
233
 
217
    callid &= ~IPC_CALLID_ANSWERED;
234
    callid &= ~IPC_CALLID_ANSWERED;
218
   
235
   
-
 
236
    futex_down(&ipc_futex);
219
    for (item = dispatched_calls.next; item != &dispatched_calls;
237
    for (item = dispatched_calls.next; item != &dispatched_calls;
220
         item = item->next) {
238
         item = item->next) {
221
        call = list_get_instance(item, async_call_t, list);
239
        call = list_get_instance(item, async_call_t, list);
222
        if (call->u.callid == callid) {
240
        if (call->u.callid == callid) {
223
            list_remove(&call->list);
241
            list_remove(&call->list);
-
 
242
            futex_up(&ipc_futex);
224
            call->callback(call->private,
243
            call->callback(call->private,
225
                       IPC_GET_RETVAL(*data),
244
                       IPC_GET_RETVAL(*data),
226
                       data);
245
                       data);
227
            return;
246
            return;
228
        }
247
        }
229
    }
248
    }
-
 
249
    futex_up(&ipc_futex);
230
    printf("Received unidentified answer: %P!!!\n", callid);
250
    printf("Received unidentified answer: %P!!!\n", callid);
231
}
251
}
232
 
252
 
233
 
253
 
234
/** Wait for IPC call and return
254
/** Wait for IPC call and return
Line 299... Line 319...
299
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
319
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
300
{
320
{
301
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
321
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
302
}
322
}
303
 
323
 
-
 
324
 
-
 
325
/** Open shared memory connection over specified phoneid
-
 
326
 *
-
 
327
 *
-
 
328
 * Allocates AS_area, notify the other side about our intention
-
 
329
 * to open the connection
-
 
330
 *
-
 
331
 * @return Connection id identifying this connection
-
 
332
 */
-
 
333
//int ipc_dgr_open(int pohoneid, size_t bufsize)
-
 
334
//{
-
 
335
    /* Find new file descriptor in local descriptor table */
-
 
336
    /* Create AS_area, initialize structures */
-
 
337
    /* Send AS to other side, handle error states */
-
 
338
 
-
 
339
//}
304
/*
340
/*
305
int ipc_open_dgrconn(int pohoneid, size_t max_dgram)
341
void ipc_dgr_close(int cid)
306
{
342
{
307
   
-
 
308
}
343
}
309
 
344
 
-
 
345
void * ipc_dgr_alloc(int cid, size_t size)
-
 
346
{
-
 
347
}
-
 
348
 
-
 
349
void ipc_dgr_free(int cid, void *area)
-
 
350
{
-
 
351
 
-
 
352
}
-
 
353
 
-
 
354
int ipc_dgr_send(int cid, void *area)
-
 
355
{
-
 
356
}
-
 
357
 
-
 
358
 
-
 
359
int ipc_dgr_send_data(int cid, void *data, size_t size)
-
 
360
{
-
 
361
}
310
 
362
 
311
*/
363
*/