Changes in kernel/generic/src/synch/mutex.c [08a19ba:d7da4284] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/mutex.c
r08a19ba rd7da4284 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Mutexes. 36 36 */ 37 37 38 38 #include <synch/mutex.h> 39 39 #include <synch/semaphore.h> 40 40 #include <synch/synch.h> 41 41 #include <debug.h> 42 #include <arch.h> 42 43 43 44 /** Initialize mutex. 44 45 * 45 * @param mtx 46 * @param type 46 * @param mtx Mutex. 47 * @param type Type of the mutex. 47 48 */ 48 49 void mutex_initialize(mutex_t *mtx, mutex_type_t type) … … 52 53 } 53 54 55 /** Find out whether the mutex is currently locked. 56 * 57 * @param mtx Mutex. 58 * @return True if the mutex is locked, false otherwise. 59 */ 60 bool mutex_locked(mutex_t *mtx) 61 { 62 return semaphore_count_get(&mtx->sem) <= 0; 63 } 64 54 65 /** Acquire mutex. 55 66 * 56 67 * Timeout mode and non-blocking mode can be requested. 57 68 * 58 * @param mtx 59 * @param usec 60 * @param flags 69 * @param mtx Mutex. 70 * @param usec Timeout in microseconds. 71 * @param flags Specify mode of operation. 61 72 * 62 73 * For exact description of possible combinations of 63 74 * usec and flags, see comment for waitq_sleep_timeout(). 64 75 * 65 * @return See comment for waitq_sleep_timeout(). 76 * @return See comment for waitq_sleep_timeout(). 77 * 66 78 */ 67 int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, int flags)79 int _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags) 68 80 { 69 81 int rc; 70 82 71 if ( mtx->type == MUTEX_PASSIVE) {83 if ((mtx->type == MUTEX_PASSIVE) && (THREAD)) { 72 84 rc = _semaphore_down_timeout(&mtx->sem, usec, flags); 73 85 } else { 74 ASSERT( mtx->type == MUTEX_ACTIVE);86 ASSERT((mtx->type == MUTEX_ACTIVE) || (!THREAD)); 75 87 ASSERT(usec == SYNCH_NO_TIMEOUT); 76 88 ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE)); 89 77 90 do { 78 91 rc = semaphore_trydown(&mtx->sem); … … 86 99 /** Release mutex. 87 100 * 88 * @param mtx 101 * @param mtx Mutex. 89 102 */ 90 103 void mutex_unlock(mutex_t *mtx)
Note:
See TracChangeset
for help on using the changeset viewer.