Lines Matching +full:down +full:- +full:counting

1 // SPDX-License-Identifier: GPL-2.0-only
6 * This file implements counting semaphores.
7 * A counting semaphore may be acquired 'n' times before sleeping.
8 * See mutex.c for single-acquisition sleeping locks which enforce
18 * parts of the kernel expect to be able to use down() on a semaphore in
20 * irqsave variants for down(), down_interruptible() and down_killable()
23 * The ->count variable represents how many more tasks can acquire this
48 WRITE_ONCE((sem)->last_holder, (unsigned long)current); in hung_task_sem_set_holder()
53 if (READ_ONCE((sem)->last_holder) == (unsigned long)current) in hung_task_sem_clear_if_holder()
54 WRITE_ONCE((sem)->last_holder, 0UL); in hung_task_sem_clear_if_holder()
59 return READ_ONCE(sem->last_holder); in sem_last_holder()
76 sem->count--; in __sem_acquire()
81 * down - acquire the semaphore
91 void __sched down(struct semaphore *sem) in down() function
96 raw_spin_lock_irqsave(&sem->lock, flags); in down()
97 if (likely(sem->count > 0)) in down()
101 raw_spin_unlock_irqrestore(&sem->lock, flags); in down()
103 EXPORT_SYMBOL(down);
106 * down_interruptible - acquire the semaphore unless interrupted
111 * If the sleep is interrupted by a signal, this function will return -EINTR.
120 raw_spin_lock_irqsave(&sem->lock, flags); in down_interruptible()
121 if (likely(sem->count > 0)) in down_interruptible()
125 raw_spin_unlock_irqrestore(&sem->lock, flags); in down_interruptible()
132 * down_killable - acquire the semaphore unless killed
138 * -EINTR. If the semaphore is successfully acquired, this function returns
147 raw_spin_lock_irqsave(&sem->lock, flags); in down_killable()
148 if (likely(sem->count > 0)) in down_killable()
152 raw_spin_unlock_irqrestore(&sem->lock, flags); in down_killable()
159 * down_trylock - try to acquire the semaphore, without waiting
176 raw_spin_lock_irqsave(&sem->lock, flags); in down_trylock()
177 count = sem->count - 1; in down_trylock()
180 raw_spin_unlock_irqrestore(&sem->lock, flags); in down_trylock()
187 * down_timeout - acquire the semaphore within a specified time
194 * this function returns -ETIME. It returns 0 if the semaphore was acquired.
202 raw_spin_lock_irqsave(&sem->lock, flags); in down_timeout()
203 if (likely(sem->count > 0)) in down_timeout()
207 raw_spin_unlock_irqrestore(&sem->lock, flags); in down_timeout()
214 * up - release the semaphore
218 * context and even by tasks which have never called down().
225 raw_spin_lock_irqsave(&sem->lock, flags); in up()
229 if (likely(list_empty(&sem->wait_list))) in up()
230 sem->count++; in up()
233 raw_spin_unlock_irqrestore(&sem->lock, flags); in up()
257 list_add_tail(&waiter.list, &sem->wait_list); in ___down_common()
267 raw_spin_unlock_irq(&sem->lock); in ___down_common()
269 raw_spin_lock_irq(&sem->lock); in ___down_common()
278 return -ETIME; in ___down_common()
282 return -EINTR; in ___down_common()
324 struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list, in __up()
326 list_del(&waiter->list); in __up()
327 waiter->up = true; in __up()
328 wake_q_add(wake_q, waiter->task); in __up()