Changeset 35509652 in mainline for libipc/generic/ipc.c


Ignore:
Timestamp:
2006-05-16T11:05:18Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
450cd3a
Parents:
c2b43de
Message:

Make IPC thread safe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libipc/generic/ipc.c

    rc2b43de r35509652  
    3434#include <stdio.h>
    3535#include <unistd.h>
     36#include <futex.h>
    3637
    3738/** Structure used for keeping track of sent async msgs
     
    5657LIST_INITIALIZE(queued_calls);
    5758
     59static atomic_t ipc_futex;
     60
     61void _ipc_init(void)
     62{
     63        futex_initialize(&ipc_futex, 1);
     64}
     65
    5866int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
    5967                  ipcarg_t *result)
     
    138146                IPC_SET_ARG1(call->u.msg.data, arg1);
    139147                IPC_SET_ARG2(call->u.msg.data, arg2);
    140 
     148               
     149                futex_down(&ipc_futex);
    141150                list_append(&call->list, &queued_calls);
     151                futex_up(&ipc_futex);
    142152                return;
    143153        }
    144154        call->u.callid = callid;
    145155        /* Add call to list of dispatched calls */
     156        futex_down(&ipc_futex);
    146157        list_append(&call->list, &dispatched_calls);
     158        futex_up(&ipc_futex);
    147159}
    148160
     
    185197        ipc_callid_t callid;
    186198
     199        futex_down(&ipc_futex);
    187200        while (!list_empty(&queued_calls)) {
    188201                call = list_get_instance(queued_calls.next, async_call_t,
     
    194207                        break;
    195208                list_remove(&call->list);
     209
    196210                if (callid == IPC_CALLRET_FATAL) {
     211                        futex_up(&ipc_futex);
    197212                        call->callback(call->private, ENOENT, NULL);
    198213                        free(call);
     214                        futex_down(&ipc_futex);
    199215                } else {
    200216                        call->u.callid = callid;
     
    202218                }
    203219        }
     220        futex_up(&ipc_futex);
    204221}
    205222
     
    217234        callid &= ~IPC_CALLID_ANSWERED;
    218235       
     236        futex_down(&ipc_futex);
    219237        for (item = dispatched_calls.next; item != &dispatched_calls;
    220238             item = item->next) {
     
    222240                if (call->u.callid == callid) {
    223241                        list_remove(&call->list);
     242                        futex_up(&ipc_futex);
    224243                        call->callback(call->private,
    225244                                       IPC_GET_RETVAL(*data),
     
    228247                }
    229248        }
     249        futex_up(&ipc_futex);
    230250        printf("Received unidentified answer: %P!!!\n", callid);
    231251}
     
    302322}
    303323
     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//}
    304340/*
    305 int ipc_open_dgrconn(int pohoneid, size_t max_dgram)
    306 {
    307        
    308 }
    309 
     341void ipc_dgr_close(int cid)
     342{
     343}
     344
     345void * ipc_dgr_alloc(int cid, size_t size)
     346{
     347}
     348
     349void ipc_dgr_free(int cid, void *area)
     350{
     351
     352}
     353
     354int ipc_dgr_send(int cid, void *area)
     355{
     356}
     357
     358
     359int ipc_dgr_send_data(int cid, void *data, size_t size)
     360{
     361}
    310362
    311363*/
Note: See TracChangeset for help on using the changeset viewer.