include/linux/lwq.h
Source file repositories/reference/linux-study-clean/include/linux/lwq.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/lwq.h- Extension
.h- Size
- 3776 bytes
- Lines
- 125
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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
linux/container_of.hlinux/spinlock.hlinux/llist.h
Detected Declarations
struct lwq_nodestruct lwqfunction lwq_initfunction lwq_emptyfunction lwq_enqueuefunction lwq_enqueue_batch
Annotated Snippet
struct lwq_node {
struct llist_node node;
};
struct lwq {
spinlock_t lock;
struct llist_node *ready; /* entries to be dequeued */
struct llist_head new; /* entries being enqueued */
};
/**
* lwq_init - initialise a lwq
* @q: the lwq object
*/
static inline void lwq_init(struct lwq *q)
{
spin_lock_init(&q->lock);
q->ready = NULL;
init_llist_head(&q->new);
}
/**
* lwq_empty - test if lwq contains any entry
* @q: the lwq object
*
* This empty test contains an acquire barrier so that if a wakeup
* is sent when lwq_dequeue returns true, it is safe to go to sleep after
* a test on lwq_empty().
*/
static inline bool lwq_empty(struct lwq *q)
{
/* acquire ensures ordering wrt lwq_enqueue() */
return smp_load_acquire(&q->ready) == NULL && llist_empty(&q->new);
}
struct llist_node *__lwq_dequeue(struct lwq *q);
/**
* lwq_dequeue - dequeue first (oldest) entry from lwq
* @q: the queue to dequeue from
* @type: the type of object to return
* @member: them member in returned object which is an lwq_node.
*
* Remove a single object from the lwq and return it. This will take
* a spinlock and so must always be called in the same context, typcially
* process contet.
*/
#define lwq_dequeue(q, type, member) \
({ struct llist_node *_n = __lwq_dequeue(q); \
_n ? container_of(_n, type, member.node) : NULL; })
struct llist_node *lwq_dequeue_all(struct lwq *q);
/**
* lwq_for_each_safe - iterate over detached queue allowing deletion
* @_n: iterator variable
* @_t1: temporary struct llist_node **
* @_t2: temporary struct llist_node *
* @_l: address of llist_node pointer from lwq_dequeue_all()
* @_member: member in _n where lwq_node is found.
*
* Iterate over members in a dequeued list. If the iterator variable
* is set to NULL, the iterator removes that entry from the queue.
*/
#define lwq_for_each_safe(_n, _t1, _t2, _l, _member) \
for (_t1 = (_l); \
*(_t1) ? (_n = container_of(*(_t1), typeof(*(_n)), _member.node),\
_t2 = ((*_t1)->next), \
true) \
: false; \
(_n) ? (_t1 = &(_n)->_member.node.next, 0) \
: ((*(_t1) = (_t2)), 0))
/**
* lwq_enqueue - add a new item to the end of the queue
* @n - the lwq_node embedded in the item to be added
* @q - the lwq to append to.
*
* No locking is needed to append to the queue so this can
* be called from any context.
* Return %true is the list may have previously been empty.
*/
static inline bool lwq_enqueue(struct lwq_node *n, struct lwq *q)
{
/* acquire enqures ordering wrt lwq_dequeue */
return llist_add(&n->node, &q->new) &&
smp_load_acquire(&q->ready) == NULL;
}
/**
* lwq_enqueue_batch - add a list of new items to the end of the queue
Annotation
- Immediate include surface: `linux/container_of.h`, `linux/spinlock.h`, `linux/llist.h`.
- Detected declarations: `struct lwq_node`, `struct lwq`, `function lwq_init`, `function lwq_empty`, `function lwq_enqueue`, `function lwq_enqueue_batch`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source 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.