Changeset bf1fb9f in mainline for kernel/generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2009-06-03T18:45:53Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bbdbf86
Parents:
40313e4
Message:

Streamline locking of phones during cloning.

File:
1 edited

Legend:

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

    r40313e4 rbf1fb9f  
    337337}
    338338
     339static void phones_lock(phone_t *p1, phone_t *p2)
     340{
     341        if (p1 < p2) {
     342                mutex_lock(&p1->lock);
     343                mutex_lock(&p2->lock);
     344        } else if (p1 > p2) {
     345                mutex_lock(&p2->lock);
     346                mutex_lock(&p1->lock);
     347        } else {
     348                mutex_lock(&p1->lock);
     349        }
     350}
     351
     352static void phones_unlock(phone_t *p1, phone_t *p2)
     353{
     354        mutex_unlock(&p1->lock);
     355        if (p1 != p2)
     356                mutex_unlock(&p2->lock);
     357}
     358
    339359/** Called before the request is sent.
    340360 *
     
    356376                GET_CHECK_PHONE(cloned_phone, IPC_GET_ARG1(call->data),
    357377                    return ENOENT);
    358                 if (cloned_phone < phone) {
    359                         mutex_lock(&cloned_phone->lock);
    360                         mutex_lock(&phone->lock);
    361                 } else if (cloned_phone > phone) {
    362                         mutex_lock(&phone->lock);
    363                         mutex_lock(&cloned_phone->lock);
    364                 } else {
    365                         mutex_lock(&phone->lock);
    366                 }
     378                phones_lock(cloned_phone, phone);
    367379                if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
    368380                    phone->state != IPC_PHONE_CONNECTED) {
    369                         if (cloned_phone != phone)
    370                                 mutex_unlock(&cloned_phone->lock);
    371                         mutex_unlock(&phone->lock);
     381                        phones_unlock(cloned_phone, phone);
    372382                        return EINVAL;
    373383                }
     
    380390                newphid = phone_alloc(phone->callee->task);
    381391                if (newphid < 0) {
    382                         if (cloned_phone != phone)
    383                                 mutex_unlock(&cloned_phone->lock);
    384                         mutex_unlock(&phone->lock);
     392                        phones_unlock(cloned_phone, phone);
    385393                        return ELIMIT;
    386394                }
    387395                ipc_phone_connect(&phone->callee->task->phones[newphid],
    388396                    cloned_phone->callee);
    389                 if (cloned_phone != phone)
    390                         mutex_unlock(&cloned_phone->lock);
    391                 mutex_unlock(&phone->lock);
     397                phones_unlock(cloned_phone, phone);
    392398                /* Set the new phone for the callee. */
    393399                IPC_SET_ARG1(call->data, newphid);
Note: See TracChangeset for help on using the changeset viewer.