Changeset db4d6de in mainline for kernel/generic/src/ipc/ipc.c


Ignore:
Timestamp:
2009-11-28T16:30:43Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4702804
Parents:
ba8f8cb (diff), 67392fa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/ipc.c

    rba8f8cb rdb4d6de  
    6262
    6363static slab_cache_t *ipc_call_slab;
     64static slab_cache_t *ipc_answerbox_slab;
    6465
    6566/** Initialize a call structure.
     
    9697}
    9798
    98 /** Initialize a statically allocated call structure.
    99  *
    100  * @param call          Statically allocated kernel call structure to be
    101  *                      initialized.
    102  */
    103 void ipc_call_static_init(call_t *call)
    104 {
    105         _ipc_call_init(call);
    106         call->flags |= IPC_CALL_STATIC_ALLOC;
    107 }
    108 
    10999/** Deallocate a call structure.
    110100 *
     
    113103void ipc_call_free(call_t *call)
    114104{
    115         ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    116105        /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */
    117106        if (call->buffer)
     
    130119        spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
    131120        waitq_initialize(&box->wq);
     121        link_initialize(&box->sync_box_link);
    132122        list_initialize(&box->connected_phones);
    133123        list_initialize(&box->calls);
     
    179169int ipc_call_sync(phone_t *phone, call_t *request)
    180170{
    181         answerbox_t sync_box;
    182 
    183         ipc_answerbox_init(&sync_box, TASK);
     171        answerbox_t *sync_box;
     172        ipl_t ipl;
     173
     174        sync_box = slab_alloc(ipc_answerbox_slab, 0);
     175        ipc_answerbox_init(sync_box, TASK);
     176
     177        /*
     178         * Put the answerbox on the TASK's list of synchronous answerboxes so
     179         * that it can be cleaned up if the call is interrupted.
     180         */
     181        ipl = interrupts_disable();
     182        spinlock_lock(&TASK->lock);
     183        list_append(&sync_box->sync_box_link, &TASK->sync_box_head);
     184        spinlock_unlock(&TASK->lock);
     185        interrupts_restore(ipl);
    184186
    185187        /* We will receive data in a special box. */
    186         request->callerbox = &sync_box;
     188        request->callerbox = sync_box;
    187189
    188190        ipc_call(phone, request);
    189         if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT,
    190             SYNCH_FLAGS_INTERRUPTIBLE))
     191        if (!ipc_wait_for_call(sync_box, SYNCH_NO_TIMEOUT,
     192            SYNCH_FLAGS_INTERRUPTIBLE)) {
     193                /* The answerbox and the call will be freed by ipc_cleanup(). */
    191194                return EINTR;
     195        }
     196
     197        /*
     198         * The answer arrived without interruption so we can remove the
     199         * answerbox from the TASK's list of synchronous answerboxes.
     200         */
     201        (void) interrupts_disable();
     202        spinlock_lock(&TASK->lock);
     203        list_remove(&sync_box->sync_box_link);
     204        spinlock_unlock(&TASK->lock);
     205        interrupts_restore(ipl);
     206
     207        slab_free(ipc_answerbox_slab, sync_box);
    192208        return EOK;
    193209}
     
    520536        int i;
    521537        call_t *call;
     538        ipl_t ipl;
    522539
    523540        /* Disconnect all our phones ('ipc_phone_hangup') */
     
    545562        spinlock_unlock(&TASK->answerbox.lock);
    546563       
    547         /* Wait for all async answers to arrive */
     564        /* Wait for all answers to interrupted synchronous calls to arrive */
     565        ipl = interrupts_disable();
     566        while (!list_empty(&TASK->sync_box_head)) {
     567                answerbox_t *box = list_get_instance(TASK->sync_box_head.next,
     568                    answerbox_t, sync_box_link);
     569
     570                list_remove(&box->sync_box_link);
     571                call = ipc_wait_for_call(box, SYNCH_NO_TIMEOUT,
     572                    SYNCH_FLAGS_NONE);
     573                ipc_call_free(call);
     574                slab_free(ipc_answerbox_slab, box);
     575        }
     576        interrupts_restore(ipl);
     577
     578        /* Wait for all answers to asynchronous calls to arrive */
    548579        while (1) {
    549580                /* Go through all phones, until all are FREE... */
     
    552583                for (i = 0; i < IPC_MAX_PHONES; i++) {
    553584                        if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
    554                             atomic_get(&TASK->phones[i].active_calls) == 0)
     585                            atomic_get(&TASK->phones[i].active_calls) == 0) {
    555586                                TASK->phones[i].state = IPC_PHONE_FREE;
     587                                TASK->phones[i].callee = NULL;
     588                        }
    556589                       
    557590                        /* Just for sure, we might have had some
     
    574607                ASSERT((call->flags & IPC_CALL_ANSWERED) ||
    575608                    (call->flags & IPC_CALL_NOTIF));
    576                 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    577609               
    578610                /*
     
    593625        ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
    594626            NULL, 0);
     627        ipc_answerbox_slab = slab_cache_create("ipc_answerbox",
     628            sizeof(answerbox_t), 0, NULL, NULL, 0);
    595629}
    596630
Note: See TracChangeset for help on using the changeset viewer.