Changeset 4c78104 in mainline for kernel/generic/src
- Timestamp:
- 2023-02-09T16:55:34Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e994898
- Parents:
- c0b54c9
- Location:
- kernel/generic/src/synch
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/mutex.c
rc0b54c9 r4c78104 66 66 bool mutex_locked(mutex_t *mtx) 67 67 { 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; 69 73 } 70 74 -
kernel/generic/src/synch/semaphore.c
rc0b54c9 r4c78104 52 52 void semaphore_initialize(semaphore_t *sem, int val) 53 53 { 54 waitq_initialize(&sem->wq); 55 if (val != 0) 56 waitq_count_set(&sem->wq, val); 54 waitq_initialize_with_count(&sem->wq, val); 57 55 } 58 56 … … 100 98 } 101 99 102 /** Get the semaphore counter value.103 *104 * @param sem Semaphore.105 * @return The number of threads that can down the semaphore106 * without blocking.107 */108 int semaphore_count_get(semaphore_t *sem)109 {110 return waitq_count_get(&sem->wq);111 }112 113 100 /** @} 114 101 */ -
kernel/generic/src/synch/waitq.c
rc0b54c9 r4c78104 75 75 irq_spinlock_initialize(&wq->lock, "wq.lock"); 76 76 list_initialize(&wq->sleepers); 77 } 78 79 void 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; 77 85 } 78 86 … … 545 553 } 546 554 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 575 555 /** @} 576 556 */
Note:
See TracChangeset
for help on using the changeset viewer.