kernel/sched/wait.c
Source file repositories/reference/linux-study-clean/kernel/sched/wait.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/wait.c- Extension
.c- Size
- 14418 bytes
- Lines
- 466
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sched.h
Detected Declarations
function __init_waitqueue_headfunction add_wait_queuefunction add_wait_queue_exclusivefunction add_wait_queue_priorityfunction add_wait_queue_priority_exclusivefunction remove_wait_queuefunction thisfunction list_for_each_entry_safe_fromfunction __wake_up_common_lockfunction __wake_upfunction __wake_up_on_current_cpufunction __wake_up_lockedfunction __wake_up_locked_keyfunction __wake_up_sync_keyfunction __wake_up_locked_sync_keyfunction __wake_up_syncfunction __wake_up_pollfreefunction spin_unlockfunction prepare_to_wait_exclusivefunction init_wait_entryfunction prepare_to_wait_eventfunction do_wait_intrfunction do_wait_intr_irqfunction finish_waitfunction autoremove_wake_functionfunction wait_wokenfunction woken_wake_functionexport __init_waitqueue_headexport add_wait_queueexport add_wait_queue_exclusiveexport add_wait_queue_priorityexport add_wait_queue_priority_exclusiveexport remove_wait_queueexport __wake_upexport __wake_up_lockedexport __wake_up_locked_keyexport __wake_up_sync_keyexport __wake_up_locked_sync_keyexport __wake_up_syncexport prepare_to_waitexport prepare_to_wait_exclusiveexport init_wait_entryexport prepare_to_wait_eventexport do_wait_intrexport do_wait_intr_irqexport finish_waitexport autoremove_wake_functionexport wait_woken
Annotated Snippet
if (list_empty(&wq_entry->entry)) {
if (wq_entry->flags & WQ_FLAG_EXCLUSIVE)
__add_wait_queue_entry_tail(wq_head, wq_entry);
else
__add_wait_queue(wq_head, wq_entry);
}
set_current_state(state);
}
spin_unlock_irqrestore(&wq_head->lock, flags);
return ret;
}
EXPORT_SYMBOL(prepare_to_wait_event);
/*
* Note! These two wait functions are entered with the
* wait-queue lock held (and interrupts off in the _irq
* case), so there is no race with testing the wakeup
* condition in the caller before they add the wait
* entry to the wake queue.
*/
int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait)
{
if (likely(list_empty(&wait->entry)))
__add_wait_queue_entry_tail(wq, wait);
set_current_state(TASK_INTERRUPTIBLE);
if (signal_pending(current))
return -ERESTARTSYS;
spin_unlock(&wq->lock);
schedule();
spin_lock(&wq->lock);
return 0;
}
EXPORT_SYMBOL(do_wait_intr);
int do_wait_intr_irq(wait_queue_head_t *wq, wait_queue_entry_t *wait)
{
if (likely(list_empty(&wait->entry)))
__add_wait_queue_entry_tail(wq, wait);
set_current_state(TASK_INTERRUPTIBLE);
if (signal_pending(current))
return -ERESTARTSYS;
spin_unlock_irq(&wq->lock);
schedule();
spin_lock_irq(&wq->lock);
return 0;
}
EXPORT_SYMBOL(do_wait_intr_irq);
/**
* finish_wait - clean up after waiting in a queue
* @wq_head: waitqueue waited on
* @wq_entry: wait descriptor
*
* Sets current thread back to running state and removes
* the wait descriptor from the given waitqueue if still
* queued.
*/
void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
{
unsigned long flags;
__set_current_state(TASK_RUNNING);
/*
* We can check for list emptiness outside the lock
* IFF:
* - we use the "careful" check that verifies both
* the next and prev pointers, so that there cannot
* be any half-pending updates in progress on other
* CPU's that we haven't seen yet (and that might
* still change the stack area.
* and
* - all other users take the lock (ie we can only
* have _one_ other CPU that looks at or modifies
* the list).
*/
if (!list_empty_careful(&wq_entry->entry)) {
spin_lock_irqsave(&wq_head->lock, flags);
list_del_init(&wq_entry->entry);
spin_unlock_irqrestore(&wq_head->lock, flags);
}
}
EXPORT_SYMBOL(finish_wait);
Annotation
- Immediate include surface: `sched.h`.
- Detected declarations: `function __init_waitqueue_head`, `function add_wait_queue`, `function add_wait_queue_exclusive`, `function add_wait_queue_priority`, `function add_wait_queue_priority_exclusive`, `function remove_wait_queue`, `function this`, `function list_for_each_entry_safe_from`, `function __wake_up_common_lock`, `function __wake_up`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.