Changeset 5110d0a in mainline
- Timestamp:
- 2023-02-07T16:02:50Z (20 months 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
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/proc/thread.h
r8a55346 r5110d0a 237 237 extern void thread_usleep(uint32_t); 238 238 239 #define thread_join(t) \ 240 thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) 241 239 extern errno_t thread_join(thread_t *); 242 240 extern errno_t thread_join_timeout(thread_t *, uint32_t, unsigned int); 243 241 extern void thread_detach(thread_t *); -
kernel/generic/include/synch/condvar.h
r8a55346 r5110d0a 46 46 } condvar_t; 47 47 48 #define condvar_wait(cv, mtx) \49 _condvar_wait_timeout((cv), (mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)50 #define condvar_wait_timeout(cv, mtx, usec) \51 _condvar_wait_timeout((cv), (mtx), (usec), SYNCH_FLAGS_NONE)52 53 48 #ifdef CONFIG_SMP 54 49 #define _condvar_wait_timeout_spinlock(cv, lock, usec, flags) \ … … 62 57 extern void condvar_signal(condvar_t *cv); 63 58 extern void condvar_broadcast(condvar_t *cv); 64 extern errno_t _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, 65 int flags); 59 60 extern errno_t condvar_wait(condvar_t *cv, mutex_t *mtx); 61 extern errno_t condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec); 62 66 63 extern errno_t _condvar_wait_timeout_spinlock_impl(condvar_t *cv, spinlock_t *lock, 67 64 uint32_t usec, int flags); -
kernel/generic/include/synch/mutex.h
r8a55346 r5110d0a 56 56 } mutex_t; 57 57 58 #define mutex_lock(mtx) \59 _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)60 61 #define mutex_trylock(mtx) \62 _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)63 64 #define mutex_lock_timeout(mtx, usec) \65 _mutex_lock_timeout((mtx), (usec), SYNCH_FLAGS_NON_BLOCKING)66 67 58 extern void mutex_initialize(mutex_t *, mutex_type_t); 68 59 extern bool mutex_locked(mutex_t *); 69 extern errno_t _mutex_lock_timeout(mutex_t *, uint32_t, unsigned int); 60 extern errno_t mutex_trylock(mutex_t *); 61 extern errno_t mutex_lock(mutex_t *); 62 extern errno_t mutex_lock_timeout(mutex_t *, uint32_t); 70 63 extern void mutex_unlock(mutex_t *); 71 64 -
kernel/generic/include/synch/semaphore.h
r8a55346 r5110d0a 45 45 } semaphore_t; 46 46 47 #define semaphore_down(s) \48 _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)49 50 #define semaphore_trydown(s) \51 _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)52 53 #define semaphore_down_timeout(s, usec) \54 _semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)55 56 #define semaphore_down_interruptable(s) \57 (_semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, \58 SYNCH_FLAGS_INTERRUPTIBLE) != EINTR)59 60 47 extern void semaphore_initialize(semaphore_t *, int); 61 extern errno_t _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned int); 48 extern errno_t _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned); 49 extern errno_t semaphore_down_timeout(semaphore_t *, uint32_t); 50 extern errno_t semaphore_trydown(semaphore_t *); 51 extern void semaphore_down(semaphore_t *); 62 52 extern void semaphore_up(semaphore_t *); 63 53 extern int semaphore_count_get(semaphore_t *); -
kernel/generic/include/synch/waitq.h
r8a55346 r5110d0a 69 69 } waitq_t; 70 70 71 #define waitq_sleep(wq) \72 waitq_sleep_timeout((wq), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, NULL)73 74 71 struct thread; 75 72 76 73 extern void waitq_initialize(waitq_t *); 74 extern errno_t waitq_sleep(waitq_t *); 77 75 extern errno_t waitq_sleep_timeout(waitq_t *, uint32_t, unsigned int, bool *); 78 76 extern ipl_t waitq_sleep_prepare(waitq_t *); 77 extern errno_t waitq_sleep_unsafe(waitq_t *, bool *); 79 78 extern errno_t waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, unsigned int, bool *); 80 79 extern void waitq_sleep_finish(waitq_t *, bool, ipl_t); -
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.