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

Function ng_upgrade_write

freebsd/netgraph/ng_base.c:2090–2153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

ng_apply_itemFunction · 0.70
ng_worklist_addFunction · 0.70

Tested by

no test coverage detected