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