Lines Matching +full:count +full:- +full:up
1 // SPDX-License-Identifier: GPL-2.0-only
8 * See mutex.c for single-acquisition sleeping locks which enforce
16 * down_trylock() and up() can be called from interrupt context, so we
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
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()
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
174 int count; in down_trylock() local
176 raw_spin_lock_irqsave(&sem->lock, flags); in down_trylock()
177 count = sem->count - 1; in down_trylock()
178 if (likely(count >= 0)) in down_trylock()
180 raw_spin_unlock_irqrestore(&sem->lock, flags); in down_trylock()
182 return (count < 0); 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
217 * Release the semaphore. Unlike mutexes, up() may be called from any
220 void __sched up(struct semaphore *sem) in up() function
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()
237 EXPORT_SYMBOL(up);
244 bool up; member
257 list_add_tail(&waiter.list, &sem->wait_list); in ___down_common()
259 waiter.up = false; in ___down_common()
267 raw_spin_unlock_irq(&sem->lock); in ___down_common()
269 raw_spin_lock_irq(&sem->lock); in ___down_common()
270 if (waiter.up) { 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()