Changes in kernel/generic/src/synch/mutex.c [15d9fe6:63e27ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/mutex.c
r15d9fe6 r63e27ef 46 46 /** Initialize mutex. 47 47 * 48 * @param mtx 49 * @param type 48 * @param mtx Mutex. 49 * @param type Type of the mutex. 50 50 */ 51 51 void mutex_initialize(mutex_t *mtx, mutex_type_t type) 52 52 { 53 53 mtx->type = type; 54 mtx->owner = NULL;55 mtx->nesting = 0;56 54 semaphore_initialize(&mtx->sem, 1); 57 55 } … … 59 57 /** Find out whether the mutex is currently locked. 60 58 * 61 * @param mtx Mutex. 62 * 63 * @return True if the mutex is locked, false otherwise. 59 * @param mtx Mutex. 60 * @return True if the mutex is locked, false otherwise. 64 61 */ 65 62 bool mutex_locked(mutex_t *mtx) … … 74 71 * Timeout mode and non-blocking mode can be requested. 75 72 * 76 * @param mtx 77 * @param usec 78 * @param flags 73 * @param mtx Mutex. 74 * @param usec Timeout in microseconds. 75 * @param flags Specify mode of operation. 79 76 * 80 * For exact description of possible combinations of usec and flags, see81 * comment for waitq_sleep_timeout().77 * For exact description of possible combinations of 78 * usec and flags, see comment for waitq_sleep_timeout(). 82 79 * 83 80 * @return See comment for waitq_sleep_timeout(). … … 88 85 int rc; 89 86 90 if ( mtx->type == MUTEX_PASSIVE && THREAD) {87 if ((mtx->type == MUTEX_PASSIVE) && (THREAD)) { 91 88 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 }105 89 } else { 106 assert((mtx->type == MUTEX_ACTIVE) || !THREAD);90 assert((mtx->type == MUTEX_ACTIVE) || (!THREAD)); 107 91 assert(usec == SYNCH_NO_TIMEOUT); 108 92 assert(!(flags & SYNCH_FLAGS_INTERRUPTIBLE)); … … 130 114 /** Release mutex. 131 115 * 132 * @param mtx 116 * @param mtx Mutex. 133 117 */ 134 118 void mutex_unlock(mutex_t *mtx) 135 119 { 136 if (mtx->type == MUTEX_RECURSIVE) {137 assert(mtx->owner == THREAD);138 if (--mtx->nesting > 0)139 return;140 mtx->owner = NULL;141 }142 120 semaphore_up(&mtx->sem); 143 121 }
Note:
See TracChangeset
for help on using the changeset viewer.