Changeset 5110d0a in mainline for kernel/generic/src


Ignore:
Timestamp:
2023-02-07T16:02:50Z (2 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Turn a bunch of macros into regular functions

Location:
kernel/generic/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    r8a55346 r5110d0a  
    629629}
    630630
     631errno_t thread_join(thread_t *thread)
     632{
     633        return thread_join_timeout(thread, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
     634}
     635
    631636/** Wait for another thread to exit.
    632637 *
  • kernel/generic/src/synch/condvar.c

    r8a55346 r5110d0a  
    7676 * @param mtx           Mutex.
    7777 * @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 when
    82  * SYNCH_FLAGS_NON_BLOCKING is specified here, EAGAIN is always
    83  * returned.
    8478 *
    8579 * @return              See comment for waitq_sleep_timeout().
    8680 */
    87 errno_t _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags)
     81errno_t condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec)
    8882{
    8983        errno_t rc;
     
    9690
    9791        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
     102errno_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);
    99114        assert(blocked || rc != EOK);
    100115
  • kernel/generic/src/synch/mutex.c

    r8a55346 r5110d0a  
    8585 *
    8686 */
    87 errno_t _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags)
     87static errno_t _mutex_lock_timeout(mutex_t *mtx, uint32_t usec, unsigned int flags)
    8888{
    8989        errno_t rc;
     
    128128}
    129129
     130errno_t mutex_trylock(mutex_t *mtx)
     131{
     132        return _mutex_lock_timeout(mtx, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING);
     133}
     134
     135errno_t mutex_lock(mutex_t *mtx)
     136{
     137        return _mutex_lock_timeout(mtx, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
     138}
     139
     140errno_t mutex_lock_timeout(mutex_t *mtx, uint32_t usec)
     141{
     142        return _mutex_lock_timeout(mtx, usec, SYNCH_FLAGS_NON_BLOCKING);
     143}
     144
    130145/** Release mutex.
    131146 *
  • kernel/generic/src/synch/semaphore.c

    r8a55346 r5110d0a  
    5353{
    5454        waitq_initialize(&sem->wq);
    55         waitq_count_set(&sem->wq, val);
     55        if (val != 0)
     56                waitq_count_set(&sem->wq, val);
    5657}
    5758
    58 /** Semaphore down
    59  *
    60  * Semaphore down.
    61  * Conditional mode and mode with timeout can be requested.
     59errno_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
     66errno_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
    6272 *
    6373 * @param sem   Semaphore.
    6474 * @param usec  Timeout in microseconds.
    65  * @param flags Select mode of operation.
    66  *
    67  * For exact description of possible combinations of
    68  * usec and flags, see comment for waitq_sleep_timeout().
    6975 *
    7076 * @return See comment for waitq_sleep_timeout().
    7177 *
    7278 */
    73 errno_t _semaphore_down_timeout(semaphore_t *sem, uint32_t usec, unsigned int flags)
     79errno_t semaphore_down_timeout(semaphore_t *sem, uint32_t usec)
    7480{
    75         return waitq_sleep_timeout(&sem->wq, usec, flags, NULL);
     81        return _semaphore_down_timeout(sem, usec, SYNCH_FLAGS_NON_BLOCKING);
     82}
     83
     84void semaphore_down(semaphore_t *sem)
     85{
     86        errno_t rc = waitq_sleep(&sem->wq);
     87        assert(rc == EOK);
    7688}
    7789
  • kernel/generic/src/synch/waitq.c

    r8a55346 r5110d0a  
    194194#define PARAM_NON_BLOCKING(flags, usec) \
    195195        (((flags) & SYNCH_FLAGS_NON_BLOCKING) && ((usec) == 0))
     196
     197errno_t waitq_sleep(waitq_t *wq)
     198{
     199        return waitq_sleep_timeout(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, NULL);
     200}
    196201
    197202/** Sleep until either wakeup, timeout or interruption occurs
     
    326331
    327332        interrupts_restore(ipl);
     333}
     334
     335errno_t waitq_sleep_unsafe(waitq_t *wq, bool *blocked)
     336{
     337        return waitq_sleep_timeout_unsafe(wq, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, blocked);
    328338}
    329339
Note: See TracChangeset for help on using the changeset viewer.