Changeset 5110d0a in mainline for kernel/generic/src
- Timestamp:
- 2023-02-07T16:02:50Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7c5320c
- Parents:
- 8a55346
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-06 16:44:26)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-07 16:02:50)
- Location:
- kernel/generic/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/thread.c
r8a55346 r5110d0a 629 629 } 630 630 631 errno_t thread_join(thread_t *thread) 632 { 633 return thread_join_timeout(thread, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); 634 } 635 631 636 /** Wait for another thread to exit. 632 637 * -
kernel/generic/src/synch/condvar.c
r8a55346 r5110d0a 76 76 * @param mtx Mutex. 77 77 * @param usec Timeout value in microseconds. 78 * @param flags Select mode of operation.79 *80 * For exact description of meaning of possible combinations of usec and flags,81 * see comment for waitq_sleep_timeout(). Note that when82 * SYNCH_FLAGS_NON_BLOCKING is specified here, EAGAIN is always83 * returned.84 78 * 85 79 * @return See comment for waitq_sleep_timeout(). 86 80 */ 87 errno_t _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags)81 errno_t condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec) 88 82 { 89 83 errno_t rc; … … 96 90 97 91 cv->wq.missed_wakeups = 0; /* Enforce blocking. */ 98 rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, flags, &blocked); 92 rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, SYNCH_FLAGS_NON_BLOCKING, &blocked); 93 assert(blocked || rc != EOK); 94 95 waitq_sleep_finish(&cv->wq, blocked, ipl); 96 /* Lock only after releasing the waitq to avoid a possible deadlock. */ 97 mutex_lock(mtx); 98 99 return rc; 100 } 101 102 errno_t condvar_wait(condvar_t *cv, mutex_t *mtx) 103 { 104 errno_t rc; 105 ipl_t ipl; 106 bool blocked; 107 108 ipl = waitq_sleep_prepare(&cv->wq); 109 /* Unlock only after the waitq is locked so we don't miss a wakeup. */ 110 mutex_unlock(mtx); 111 112 cv->wq.missed_wakeups = 0; /* Enforce blocking. */ 113 rc = waitq_sleep_unsafe(&cv->wq, &blocked); 99 114 assert(blocked || rc != EOK); 100 115 -
kernel/generic/src/synch/mutex.c
r8a55346 r5110d0a 85 85 * 86 86 */ 87 errno_t _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags)87 static errno_t _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags) 88 88 { 89 89 errno_t rc; … … 128 128 } 129 129 130 errno_t mutex_trylock(mutex_t *mtx) 131 { 132 return _mutex_lock_timeout(mtx, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 133 } 134 135 errno_t mutex_lock(mutex_t *mtx) 136 { 137 return _mutex_lock_timeout(mtx, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE); 138 } 139 140 errno_t mutex_lock_timeout(mutex_t *mtx, uint32_t usec) 141 { 142 return _mutex_lock_timeout(mtx, usec, SYNCH_FLAGS_NON_BLOCKING); 143 } 144 130 145 /** Release mutex. 131 146 * -
kernel/generic/src/synch/semaphore.c
r8a55346 r5110d0a 53 53 { 54 54 waitq_initialize(&sem->wq); 55 waitq_count_set(&sem->wq, val); 55 if (val != 0) 56 waitq_count_set(&sem->wq, val); 56 57 } 57 58 58 /** Semaphore down 59 * 60 * Semaphore down. 61 * Conditional mode and mode with timeout can be requested. 59 errno_t _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned flags) 60 { 61 errno_t rc = waitq_sleep_timeout(&sem->wq, usec, flags, NULL); 62 assert(rc == EOK || rc == ETIMEOUT || rc == EAGAIN); 63 return rc; 64 } 65 66 errno_t semaphore_trydown(semaphore_t *sem) 67 { 68 return _semaphore_down_timeout(sem, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 69 } 70 71 /** Semaphore down with timeout 62 72 * 63 73 * @param sem Semaphore. 64 74 * @param usec Timeout in microseconds. 65 * @param flags Select mode of operation.66 *67 * For exact description of possible combinations of68 * usec and flags, see comment for waitq_sleep_timeout().69 75 * 70 76 * @return See comment for waitq_sleep_timeout(). 71 77 * 72 78 */ 73 errno_t _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned int flags)79 errno_t semaphore_down_timeout(semaphore_t *sem, uint32_t usec) 74 80 { 75 return waitq_sleep_timeout(&sem->wq, usec, flags, NULL); 81 return _semaphore_down_timeout(sem, usec, SYNCH_FLAGS_NON_BLOCKING); 82 } 83 84 void semaphore_down(semaphore_t *sem) 85 { 86 errno_t rc = waitq_sleep(&sem->wq); 87 assert(rc == EOK); 76 88 } 77 89 -
kernel/generic/src/synch/waitq.c
r8a55346 r5110d0a 194 194 #define PARAM_NON_BLOCKING(flags, usec) \ 195 195 (((flags) & SYNCH_FLAGS_NON_BLOCKING) && ((usec) == 0)) 196 197 errno_t waitq_sleep(waitq_t *wq) 198 { 199 return waitq_sleep_timeout(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, NULL); 200 } 196 201 197 202 /** Sleep until either wakeup, timeout or interruption occurs … … 326 331 327 332 interrupts_restore(ipl); 333 } 334 335 errno_t waitq_sleep_unsafe(waitq_t *wq, bool *blocked) 336 { 337 return waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, blocked); 328 338 } 329 339
Note:
See TracChangeset
for help on using the changeset viewer.