Changeset f9d0a86 in mainline for kernel/generic/src/synch/mutex.c


Ignore:
Timestamp:
2017-11-14T12:24:42Z (6 years ago)
Author:
Aearsis <Hlavaty.Ondrej@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6cad776
Parents:
887c9de (diff), d2d142a (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.
git-author:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 01:04:19)
git-committer:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 12:24:42)
Message:

Merge tag '0.7.1'

The merge wasn't clean, because of changes in build system. The most
significant change was partial revert of usbhc callback refactoring,
which now does not take usb transfer batch, but few named fields again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/mutex.c

    r887c9de rf9d0a86  
    4646/** Initialize mutex.
    4747 *
    48  * @param mtx  Mutex.
    49  * @param type Type of the mutex.
     48 * @param mtx   Mutex.
     49 * @param type  Type of the mutex.
    5050 */
    5151void mutex_initialize(mutex_t *mtx, mutex_type_t type)
    5252{
    5353        mtx->type = type;
     54        mtx->owner = NULL;
     55        mtx->nesting = 0;
    5456        semaphore_initialize(&mtx->sem, 1);
    5557}
     
    5759/** Find out whether the mutex is currently locked.
    5860 *
    59  * @param mtx           Mutex.
    60  * @return              True if the mutex is locked, false otherwise.
     61 * @param mtx  Mutex.
     62 *
     63 * @return  True if the mutex is locked, false otherwise.
    6164 */
    6265bool mutex_locked(mutex_t *mtx)
     
    7174 * Timeout mode and non-blocking mode can be requested.
    7275 *
    73  * @param mtx   Mutex.
    74  * @param usec  Timeout in microseconds.
    75  * @param flags Specify mode of operation.
     76 * @param mtx    Mutex.
     77 * @param usec   Timeout in microseconds.
     78 * @param flags  Specify mode of operation.
    7679 *
    77  * For exact description of possible combinations of
    78  * usec and flags, see comment for waitq_sleep_timeout().
     80 * For exact description of possible combinations of usec and flags, see
     81 * comment for waitq_sleep_timeout().
    7982 *
    8083 * @return See comment for waitq_sleep_timeout().
     
    8588        int rc;
    8689
    87         if ((mtx->type == MUTEX_PASSIVE) && (THREAD)) {
     90        if (mtx->type == MUTEX_PASSIVE && THREAD) {
    8891                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
     92        } else if (mtx->type == MUTEX_RECURSIVE) {
     93                assert(THREAD);
     94
     95                if (mtx->owner == THREAD) {
     96                        mtx->nesting++;
     97                        return ESYNCH_OK_ATOMIC;
     98                } else {
     99                        rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
     100                        if (SYNCH_OK(rc)) {
     101                                mtx->owner = THREAD;
     102                                mtx->nesting = 1;
     103                        }
     104                }
    89105        } else {
    90                 assert((mtx->type == MUTEX_ACTIVE) || (!THREAD));
     106                assert((mtx->type == MUTEX_ACTIVE) || !THREAD);
    91107                assert(usec == SYNCH_NO_TIMEOUT);
    92108                assert(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
     
    114130/** Release mutex.
    115131 *
    116  * @param mtx Mutex.
     132 * @param mtx  Mutex.
    117133 */
    118134void mutex_unlock(mutex_t *mtx)
    119135{
     136        if (mtx->type == MUTEX_RECURSIVE) {
     137                assert(mtx->owner == THREAD);
     138                if (--mtx->nesting > 0)
     139                        return;
     140                mtx->owner = NULL;
     141        }
    120142        semaphore_up(&mtx->sem);
    121143}
Note: See TracChangeset for help on using the changeset viewer.