Acquire reader lock on node. If node is busy, queue the packet. */
| 2045 | |
| 2046 | /* Acquire reader lock on node. If node is busy, queue the packet. */ |
| 2047 | static __inline item_p |
| 2048 | ng_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. */ |
| 2075 | static __inline item_p |
no test coverage detected