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