MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_acquire_read

Function ng_acquire_read

lib/ff_ng_base.c:2047–2072  ·  view source on GitHub ↗

Acquire reader lock on node. If node is busy, queue the packet. */

Source from the content-addressed store, hash-verified

2045
2046/* Acquire reader lock on node. If node is busy, queue the packet. */
2047static __inline item_p
2048ng_acquire_read(node_p node, item_p item)
2049{
2050 KASSERT(node != &ng_deadnode,
2051 ("%s: working on deadnode", __func__));
2052
2053 /* Reader needs node without writer and pending items. */
2054 for (;;) {
2055 long t = node->nd_input_queue.q_flags;
2056 if (t & NGQ_RMASK)
2057 break; /* Node is not ready for reader. */
2058 if (atomic_cmpset_acq_int(&node->nd_input_queue.q_flags, t,
2059 t + READER_INCREMENT)) {
2060 /* Successfully grabbed node */
2061 CTR4(KTR_NET, "%20s: node [%x] (%p) acquired item %p",
2062 __func__, node->nd_ID, node, item);
2063 return (item);
2064 }
2065 cpu_spinwait();
2066 }
2067
2068 /* Queue the request for later. */
2069 ng_queue_rw(node, item, NGQRW_R);
2070
2071 return (NULL);
2072}
2073
2074/* Acquire writer lock on node. If node is busy, queue the packet. */
2075static __inline item_p

Callers 1

ng_snd_itemFunction · 0.70

Calls 1

ng_queue_rwFunction · 0.70

Tested by

no test coverage detected