Lines Matching +full:wait +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0-only
10 spin_lock_init(&wq_head->lock); in __init_waitqueue_head()
11 lockdep_set_class_and_name(&wq_head->lock, key, name); in __init_waitqueue_head()
12 INIT_LIST_HEAD(&wq_head->head); in __init_waitqueue_head()
21 wq_entry->flags &= ~WQ_FLAG_EXCLUSIVE; in add_wait_queue()
22 spin_lock_irqsave(&wq_head->lock, flags); in add_wait_queue()
24 spin_unlock_irqrestore(&wq_head->lock, flags); in add_wait_queue()
32 wq_entry->flags |= WQ_FLAG_EXCLUSIVE; in add_wait_queue_exclusive()
33 spin_lock_irqsave(&wq_head->lock, flags); in add_wait_queue_exclusive()
35 spin_unlock_irqrestore(&wq_head->lock, flags); in add_wait_queue_exclusive()
43 wq_entry->flags |= WQ_FLAG_EXCLUSIVE | WQ_FLAG_PRIORITY; in add_wait_queue_priority()
44 spin_lock_irqsave(&wq_head->lock, flags); in add_wait_queue_priority()
46 spin_unlock_irqrestore(&wq_head->lock, flags); in add_wait_queue_priority()
54 spin_lock_irqsave(&wq_head->lock, flags); in remove_wait_queue()
56 spin_unlock_irqrestore(&wq_head->lock, flags); in remove_wait_queue()
61 * Scan threshold to break wait queue walk.
63 * wait queue lock during the wait queue walk.
68 * The core wakeup function. Non-exclusive wakeups (nr_exclusive == 0) just
71 * the non-exclusive tasks. Normally, exclusive tasks will be at the end of
72 * the list and any non-exclusive tasks will be woken first. A priority task
77 * started to run but is not in state TASK_RUNNING. try_to_wake_up() returns
87 lockdep_assert_held(&wq_head->lock); in __wake_up_common()
89 if (bookmark && (bookmark->flags & WQ_FLAG_BOOKMARK)) { in __wake_up_common()
92 list_del(&bookmark->entry); in __wake_up_common()
93 bookmark->flags = 0; in __wake_up_common()
95 curr = list_first_entry(&wq_head->head, wait_queue_entry_t, entry); in __wake_up_common()
97 if (&curr->entry == &wq_head->head) in __wake_up_common()
100 list_for_each_entry_safe_from(curr, next, &wq_head->head, entry) { in __wake_up_common()
101 unsigned flags = curr->flags; in __wake_up_common()
107 ret = curr->func(curr, mode, wake_flags, key); in __wake_up_common()
110 if (ret && (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive) in __wake_up_common()
114 (&next->entry != &wq_head->head)) { in __wake_up_common()
115 bookmark->flags = WQ_FLAG_BOOKMARK; in __wake_up_common()
116 list_add_tail(&bookmark->entry, &next->entry); in __wake_up_common()
137 spin_lock_irqsave(&wq_head->lock, flags); in __wake_up_common_lock()
140 spin_unlock_irqrestore(&wq_head->lock, flags); in __wake_up_common_lock()
143 return nr_exclusive - remaining; in __wake_up_common_lock()
147 * __wake_up - wake up threads blocked on a waitqueue.
150 * @nr_exclusive: how many wake-one or wake-many threads to wake up
154 * before accessing the task state. Returns the number of exclusive
192 * __wake_up_sync_key - wake up threads blocked on a waitqueue.
199 * be migrated to another CPU - ie. the two threads are 'synchronized'
205 * accessing the task state.
218 * __wake_up_locked_sync_key - wake up a thread blocked on a locked waitqueue.
225 * be migrated to another CPU - ie. the two threads are 'synchronized'
231 * accessing the task state.
241 * __wake_up_sync - see __wake_up_sync_key()
257 * Note: we use "set_current_state()" _after_ the wait-queue add,
259 * wake-function that tests for the wait-queue being active
263 * The spin_unlock() itself is semi-permeable and only protects
265 * stops them from bleeding out - it would still allow subsequent
269 prepare_to_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state) in prepare_to_wait() argument
273 wq_entry->flags &= ~WQ_FLAG_EXCLUSIVE; in prepare_to_wait()
274 spin_lock_irqsave(&wq_head->lock, flags); in prepare_to_wait()
275 if (list_empty(&wq_entry->entry)) in prepare_to_wait()
277 set_current_state(state); in prepare_to_wait()
278 spin_unlock_irqrestore(&wq_head->lock, flags); in prepare_to_wait()
284 …re_to_wait_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state) in prepare_to_wait_exclusive() argument
289 wq_entry->flags |= WQ_FLAG_EXCLUSIVE; in prepare_to_wait_exclusive()
290 spin_lock_irqsave(&wq_head->lock, flags); in prepare_to_wait_exclusive()
291 if (list_empty(&wq_entry->entry)) { in prepare_to_wait_exclusive()
292 was_empty = list_empty(&wq_head->head); in prepare_to_wait_exclusive()
295 set_current_state(state); in prepare_to_wait_exclusive()
296 spin_unlock_irqrestore(&wq_head->lock, flags); in prepare_to_wait_exclusive()
303 wq_entry->flags = flags; in init_wait_entry()
304 wq_entry->private = current; in init_wait_entry()
305 wq_entry->func = autoremove_wake_function; in init_wait_entry()
306 INIT_LIST_HEAD(&wq_entry->entry); in init_wait_entry()
310 …repare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state) in prepare_to_wait_event() argument
315 spin_lock_irqsave(&wq_head->lock, flags); in prepare_to_wait_event()
316 if (signal_pending_state(state, current)) { in prepare_to_wait_event()
323 * wakeup locks/unlocks the same wq_head->lock. in prepare_to_wait_event()
325 * But we need to ensure that set-condition + wakeup after that in prepare_to_wait_event()
329 list_del_init(&wq_entry->entry); in prepare_to_wait_event()
330 ret = -ERESTARTSYS; in prepare_to_wait_event()
332 if (list_empty(&wq_entry->entry)) { in prepare_to_wait_event()
333 if (wq_entry->flags & WQ_FLAG_EXCLUSIVE) in prepare_to_wait_event()
338 set_current_state(state); in prepare_to_wait_event()
340 spin_unlock_irqrestore(&wq_head->lock, flags); in prepare_to_wait_event()
347 * Note! These two wait functions are entered with the
348 * wait-queue lock held (and interrupts off in the _irq
350 * condition in the caller before they add the wait
353 int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait) in do_wait_intr() argument
355 if (likely(list_empty(&wait->entry))) in do_wait_intr()
356 __add_wait_queue_entry_tail(wq, wait); in do_wait_intr()
360 return -ERESTARTSYS; in do_wait_intr()
362 spin_unlock(&wq->lock); in do_wait_intr()
364 spin_lock(&wq->lock); in do_wait_intr()
370 int do_wait_intr_irq(wait_queue_head_t *wq, wait_queue_entry_t *wait) in do_wait_intr_irq() argument
372 if (likely(list_empty(&wait->entry))) in do_wait_intr_irq()
373 __add_wait_queue_entry_tail(wq, wait); in do_wait_intr_irq()
377 return -ERESTARTSYS; in do_wait_intr_irq()
379 spin_unlock_irq(&wq->lock); in do_wait_intr_irq()
381 spin_lock_irq(&wq->lock); in do_wait_intr_irq()
388 * finish_wait - clean up after waiting in a queue
390 * @wq_entry: wait descriptor
392 * Sets current thread back to running state and removes
393 * the wait descriptor from the given waitqueue if still
404 * - we use the "careful" check that verifies both in finish_wait()
406 * be any half-pending updates in progress on other in finish_wait()
410 * - all other users take the lock (ie we can only in finish_wait()
414 if (!list_empty_careful(&wq_entry->entry)) { in finish_wait()
415 spin_lock_irqsave(&wq_head->lock, flags); in finish_wait()
416 list_del_init(&wq_entry->entry); in finish_wait()
417 spin_unlock_irqrestore(&wq_head->lock, flags); in finish_wait()
427 list_del_init_careful(&wq_entry->entry); in autoremove_wake_function()
434 * DEFINE_WAIT_FUNC(wait, woken_wake_func);
436 * add_wait_queue(&wq_head, &wait);
443 * p->state = mode; wq_entry->flags |= WQ_FLAG_WOKEN;
445 * if (!(wq_entry->flags & WQ_FLAG_WOKEN)) <full barrier>
446 * schedule() if (p->state & mode)
447 * p->state = TASK_RUNNING; p->state = TASK_RUNNING;
448 * wq_entry->flags &= ~WQ_FLAG_WOKEN; ~~~~~~~~~~~~~~~~~~
451 * remove_wait_queue(&wq_head, &wait); wq_entry->flags |= WQ_FLAG_WOKEN;
458 * either we see the store to wq_entry->flags in woken_wake_function() in wait_woken()
459 * or woken_wake_function() sees our store to current->state. in wait_woken()
462 if (!(wq_entry->flags & WQ_FLAG_WOKEN) && !kthread_should_stop_or_park()) in wait_woken()
468 * in woken_wake_function() such that either we see the wait condition in wait_woken()
469 * being true or the store to wq_entry->flags in woken_wake_function() in wait_woken()
472 smp_store_mb(wq_entry->flags, wq_entry->flags & ~WQ_FLAG_WOKEN); /* B */ in wait_woken()
482 wq_entry->flags |= WQ_FLAG_WOKEN; in woken_wake_function()