Changeset 5110d0a in mainline


Ignore:
Timestamp:
2023-02-07T16:02:50Z (20 months 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
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    r8a55346 r5110d0a  
    237237extern void thread_usleep(uint32_t);
    238238
    239 #define thread_join(t) \
    240         thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    241 
     239extern errno_t thread_join(thread_t *);
    242240extern errno_t thread_join_timeout(thread_t *, uint32_t, unsigned int);
    243241extern void thread_detach(thread_t *);
  • kernel/generic/include/synch/condvar.h

    r8a55346 r5110d0a  
    4646} condvar_t;
    4747
    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 
    5348#ifdef CONFIG_SMP
    5449#define _condvar_wait_timeout_spinlock(cv, lock, usec, flags) \
     
    6257extern void condvar_signal(condvar_t *cv);
    6358extern 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
     60extern errno_t condvar_wait(condvar_t *cv, mutex_t *mtx);
     61extern errno_t condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec);
     62
    6663extern errno_t _condvar_wait_timeout_spinlock_impl(condvar_t *cv, spinlock_t *lock,
    6764    uint32_t usec, int flags);
  • kernel/generic/include/synch/mutex.h

    r8a55346 r5110d0a  
    5656} mutex_t;
    5757
    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 
    6758extern void mutex_initialize(mutex_t *, mutex_type_t);
    6859extern bool mutex_locked(mutex_t *);
    69 extern errno_t _mutex_lock_timeout(mutex_t *, uint32_t, unsigned int);
     60extern errno_t mutex_trylock(mutex_t *);
     61extern errno_t mutex_lock(mutex_t *);
     62extern errno_t mutex_lock_timeout(mutex_t *, uint32_t);
    7063extern void mutex_unlock(mutex_t *);
    7164
  • kernel/generic/include/synch/semaphore.h

    r8a55346 r5110d0a  
    4545} semaphore_t;
    4646
    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 
    6047extern void semaphore_initialize(semaphore_t *, int);
    61 extern errno_t _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned int);
     48extern errno_t _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned);
     49extern errno_t semaphore_down_timeout(semaphore_t *, uint32_t);
     50extern errno_t semaphore_trydown(semaphore_t *);
     51extern void semaphore_down(semaphore_t *);
    6252extern void semaphore_up(semaphore_t *);
    6353extern int semaphore_count_get(semaphore_t *);
  • kernel/generic/include/synch/waitq.h

    r8a55346 r5110d0a  
    6969} waitq_t;
    7070
    71 #define waitq_sleep(wq) \
    72         waitq_sleep_timeout((wq), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE, NULL)
    73 
    7471struct thread;
    7572
    7673extern void waitq_initialize(waitq_t *);
     74extern errno_t waitq_sleep(waitq_t *);
    7775extern errno_t waitq_sleep_timeout(waitq_t *, uint32_t, unsigned int, bool *);
    7876extern ipl_t waitq_sleep_prepare(waitq_t *);
     77extern errno_t waitq_sleep_unsafe(waitq_t *, bool *);
    7978extern errno_t waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, unsigned int, bool *);
    8079extern void waitq_sleep_finish(waitq_t *, bool, ipl_t);
  • 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.