Changeset 4c78104 in mainline


Ignore:
Timestamp:
2023-02-09T16:55:34Z (22 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e994898
Parents:
c0b54c9
Message:

Get rid of waitq_count_get/set

Location:
kernel/generic
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/synch/semaphore.h

    rc0b54c9 r4c78104  
    5151extern void semaphore_down(semaphore_t *);
    5252extern void semaphore_up(semaphore_t *);
    53 extern int semaphore_count_get(semaphore_t *);
    5453
    5554#endif
  • kernel/generic/include/synch/waitq.h

    rc0b54c9 r4c78104  
    7272
    7373extern void waitq_initialize(waitq_t *);
     74extern void waitq_initialize_with_count(waitq_t *, int);
    7475extern errno_t waitq_sleep(waitq_t *);
    7576extern errno_t waitq_sleep_timeout(waitq_t *, uint32_t, unsigned int, bool *);
     
    8182extern void _waitq_wakeup_unsafe(waitq_t *, wakeup_mode_t);
    8283extern void waitq_interrupt_sleep(struct thread *);
    83 extern int waitq_count_get(waitq_t *);
    84 extern void waitq_count_set(waitq_t *, int val);
    8584
    8685#endif
  • kernel/generic/src/synch/mutex.c

    rc0b54c9 r4c78104  
    6666bool mutex_locked(mutex_t *mtx)
    6767{
    68         return semaphore_count_get(&mtx->sem) <= 0;
     68        bool success = semaphore_trydown(&mtx->sem);
     69        if (success) {
     70                semaphore_up(&mtx->sem);
     71        }
     72        return !success;
    6973}
    7074
  • kernel/generic/src/synch/semaphore.c

    rc0b54c9 r4c78104  
    5252void semaphore_initialize(semaphore_t *sem, int val)
    5353{
    54         waitq_initialize(&sem->wq);
    55         if (val != 0)
    56                 waitq_count_set(&sem->wq, val);
     54        waitq_initialize_with_count(&sem->wq, val);
    5755}
    5856
     
    10098}
    10199
    102 /** Get the semaphore counter value.
    103  *
    104  * @param sem           Semaphore.
    105  * @return              The number of threads that can down the semaphore
    106  *                      without blocking.
    107  */
    108 int semaphore_count_get(semaphore_t *sem)
    109 {
    110         return waitq_count_get(&sem->wq);
    111 }
    112 
    113100/** @}
    114101 */
  • kernel/generic/src/synch/waitq.c

    rc0b54c9 r4c78104  
    7575        irq_spinlock_initialize(&wq->lock, "wq.lock");
    7676        list_initialize(&wq->sleepers);
     77}
     78
     79void waitq_initialize_with_count(waitq_t *wq, int count)
     80{
     81        memsetb(wq, sizeof(*wq), 0);
     82        irq_spinlock_initialize(&wq->lock, "wq.lock");
     83        list_initialize(&wq->sleepers);
     84        wq->missed_wakeups = count;
    7785}
    7886
     
    545553}
    546554
    547 /** Get the missed wakeups count.
    548  *
    549  * @param wq    Pointer to wait queue.
    550  * @return      The wait queue's missed_wakeups count.
    551  */
    552 int waitq_count_get(waitq_t *wq)
    553 {
    554         int cnt;
    555 
    556         irq_spinlock_lock(&wq->lock, true);
    557         cnt = wq->missed_wakeups;
    558         irq_spinlock_unlock(&wq->lock, true);
    559 
    560         return cnt;
    561 }
    562 
    563 /** Set the missed wakeups count.
    564  *
    565  * @param wq    Pointer to wait queue.
    566  * @param val   New value of the missed_wakeups count.
    567  */
    568 void waitq_count_set(waitq_t *wq, int val)
    569 {
    570         irq_spinlock_lock(&wq->lock, true);
    571         wq->missed_wakeups = val;
    572         irq_spinlock_unlock(&wq->lock, true);
    573 }
    574 
    575555/** @}
    576556 */
Note: See TracChangeset for help on using the changeset viewer.