| 2095 | |
| 2096 | #if 0 |
| 2097 | static __inline item_p |
| 2098 | ng_upgrade_write(node_p node, item_p item) |
| 2099 | { |
| 2100 | struct ng_queue *ngq = &node->nd_input_queue; |
| 2101 | KASSERT(node != &ng_deadnode, |
| 2102 | ("%s: working on deadnode", __func__)); |
| 2103 | |
| 2104 | NGI_SET_WRITER(item); |
| 2105 | |
| 2106 | NG_QUEUE_LOCK(ngq); |
| 2107 | |
| 2108 | /* |
| 2109 | * There will never be no readers as we are there ourselves. |
| 2110 | * Set the WRITER_ACTIVE flags ASAP to block out fast track readers. |
| 2111 | * The caller we are running from will call ng_leave_read() |
| 2112 | * soon, so we must account for that. We must leave again with the |
| 2113 | * READER lock. If we find other readers, then |
| 2114 | * queue the request for later. However "later" may be rignt now |
| 2115 | * if there are no readers. We don't really care if there are queued |
| 2116 | * items as we will bypass them anyhow. |
| 2117 | */ |
| 2118 | atomic_add_int(&ngq->q_flags, WRITER_ACTIVE - READER_INCREMENT); |
| 2119 | if ((ngq->q_flags & (NGQ_WMASK & ~OP_PENDING)) == WRITER_ACTIVE) { |
| 2120 | NG_QUEUE_UNLOCK(ngq); |
| 2121 | |
| 2122 | /* It's just us, act on the item. */ |
| 2123 | /* will NOT drop writer lock when done */ |
| 2124 | ng_apply_item(node, item, 0); |
| 2125 | |
| 2126 | /* |
| 2127 | * Having acted on the item, atomically |
| 2128 | * downgrade back to READER and finish up. |
| 2129 | */ |
| 2130 | atomic_add_int(&ngq->q_flags, READER_INCREMENT - WRITER_ACTIVE); |
| 2131 | |
| 2132 | /* Our caller will call ng_leave_read() */ |
| 2133 | return; |
| 2134 | } |
| 2135 | /* |
| 2136 | * It's not just us active, so queue us AT THE HEAD. |
| 2137 | * "Why?" I hear you ask. |
| 2138 | * Put us at the head of the queue as we've already been |
| 2139 | * through it once. If there is nothing else waiting, |
| 2140 | * set the correct flags. |
| 2141 | */ |
| 2142 | if (STAILQ_EMPTY(&ngq->queue)) { |
| 2143 | /* We've gone from, 0 to 1 item in the queue */ |
| 2144 | atomic_set_int(&ngq->q_flags, OP_PENDING); |
| 2145 | |
| 2146 | CTR3(KTR_NET, "%20s: node [%x] (%p) set OP_PENDING", __func__, |
| 2147 | node->nd_ID, node); |
| 2148 | }; |
| 2149 | STAILQ_INSERT_HEAD(&ngq->queue, item, el_next); |
| 2150 | CTR4(KTR_NET, "%20s: node [%x] (%p) requeued item %p as WRITER", |
| 2151 | __func__, node->nd_ID, node, item ); |
| 2152 | |
| 2153 | /* Reverse what we did above. That downgrades us back to reader */ |
| 2154 | atomic_add_int(&ngq->q_flags, READER_INCREMENT - WRITER_ACTIVE); |
nothing calls this directly
no test coverage detected