Changeset 48bcf49 in mainline for kernel/generic/src/ipc/ipc.c


Ignore:
Timestamp:
2017-09-28T22:08:15Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6636fb19
Parents:
dd20cbb
Message:

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

File:
1 edited

Legend:

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

    rdd20cbb r48bcf49  
    154154/** Connect a phone to an answerbox.
    155155 *
    156  * @param phone Initialized phone structure.
    157  * @param box   Initialized answerbox structure.
    158  * @return      True if the phone was connected, false otherwise.
     156 * This function must be passed a reference to phone->kobject.
     157 *
     158 * @param phone  Initialized phone structure.
     159 * @param box    Initialized answerbox structure.
     160 * @return       True if the phone was connected, false otherwise.
    159161 */
    160162bool ipc_phone_connect(phone_t *phone, answerbox_t *box)
     
    169171                phone->state = IPC_PHONE_CONNECTED;
    170172                phone->callee = box;
     173                /* Pass phone->kobject reference to box->connected_phones */
    171174                list_append(&phone->link, &box->connected_phones);
    172175        }
     
    174177        irq_spinlock_unlock(&box->lock, true);
    175178        mutex_unlock(&phone->lock);
     179
     180        if (!active) {
     181                /* We still have phone->kobject's reference; drop it */
     182                kobject_put(phone->kobject);
     183        }
    176184
    177185        return active;
     
    191199        phone->state = IPC_PHONE_FREE;
    192200        atomic_set(&phone->active_calls, 0);
     201        phone->kobject = NULL;
    193202}
    194203
     
    456465                list_remove(&phone->link);
    457466                irq_spinlock_unlock(&box->lock, true);
     467
     468                /* Drop the answerbox reference */
     469                kobject_put(phone->kobject);
    458470               
    459471                call_t *call = ipc_call_alloc(0);
     
    658670
    659671                        task_release(phone->caller);
     672
     673                        kobject_put(phone->kobject);
    660674                       
    661675                        /* Must start again */
     
    664678               
    665679                mutex_unlock(&phone->lock);
     680                kobject_put(phone->kobject);
    666681        }
    667682       
     
    734749static bool phone_cap_wait_cb(cap_t *cap, void *arg)
    735750{
    736         phone_t *phone = (phone_t *) cap->kobject;
     751        phone_t *phone = cap->kobject->phone;
    737752        bool *restart = (bool *) arg;
    738753
     
    790805         */
    791806        restart = false;
    792         if (caps_apply_to_type(TASK, CAP_TYPE_PHONE, phone_cap_wait_cb,
    793             &restart)) {
     807        if (caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_PHONE,
     808            phone_cap_wait_cb, &restart)) {
    794809                /* Got into cleanup */
    795810                return;
     
    810825static bool phone_cap_cleanup_cb(cap_t *cap, void *arg)
    811826{
    812         phone_t *phone = (phone_t *) cap->kobject;
    813         ipc_phone_hangup(phone);
     827        ipc_phone_hangup(cap->kobject->phone);
    814828        return true;
    815829}
     
    840854
    841855        /* Disconnect all our phones ('ipc_phone_hangup') */
    842         caps_apply_to_type(TASK, CAP_TYPE_PHONE, phone_cap_cleanup_cb, NULL);
     856        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_PHONE,
     857            phone_cap_cleanup_cb, NULL);
    843858       
    844859        /* Unsubscribe from any event notifications. */
     
    846861       
    847862        /* Disconnect all connected IRQs */
    848         caps_apply_to_type(TASK, CAP_TYPE_IRQ, irq_cap_cleanup_cb, NULL);
     863        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_IRQ, irq_cap_cleanup_cb,
     864            NULL);
    849865       
    850866        /* Disconnect all phones connected to our regular answerbox */
     
    912928static bool print_task_phone_cb(cap_t *cap, void *arg)
    913929{
    914         phone_t *phone = (phone_t *) cap->kobject;
     930        phone_t *phone = cap->kobject->phone;
    915931
    916932        mutex_lock(&phone->lock);
     
    963979        printf("[phone cap] [calls] [state\n");
    964980       
    965         caps_apply_to_type(task, CAP_TYPE_PHONE, print_task_phone_cb, NULL);
     981        caps_apply_to_kobject_type(task, KOBJECT_TYPE_PHONE,
     982            print_task_phone_cb, NULL);
    966983       
    967984        irq_spinlock_lock(&task->lock, true);
Note: See TracChangeset for help on using the changeset viewer.