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

Function ngthread

freebsd/netgraph/ng_base.c:3398–3445  ·  view source on GitHub ↗

* Worklist routines **********************************************************************/ * Pick a node off the list of nodes with work, * try get an item to process off it. Remove the node from the list. */

Source from the content-addressed store, hash-verified

3396 * try get an item to process off it. Remove the node from the list.
3397 */
3398static void
3399ngthread(void *arg)
3400{
3401 for (;;) {
3402 struct epoch_tracker et;
3403 node_p node;
3404
3405 /* Get node from the worklist. */
3406 NG_WORKLIST_LOCK();
3407 while ((node = STAILQ_FIRST(&ng_worklist)) == NULL)
3408 NG_WORKLIST_SLEEP();
3409 STAILQ_REMOVE_HEAD(&ng_worklist, nd_input_queue.q_work);
3410 NG_WORKLIST_UNLOCK();
3411 CURVNET_SET(node->nd_vnet);
3412 CTR3(KTR_NET, "%20s: node [%x] (%p) taken off worklist",
3413 __func__, node->nd_ID, node);
3414 /*
3415 * We have the node. We also take over the reference
3416 * that the list had on it.
3417 * Now process as much as you can, until it won't
3418 * let you have another item off the queue.
3419 * All this time, keep the reference
3420 * that lets us be sure that the node still exists.
3421 * Let the reference go at the last minute.
3422 */
3423 NET_EPOCH_ENTER(et);
3424 for (;;) {
3425 item_p item;
3426 int rw;
3427
3428 NG_QUEUE_LOCK(&node->nd_input_queue);
3429 item = ng_dequeue(node, &rw);
3430 if (item == NULL) {
3431 node->nd_input_queue.q_flags2 &= ~NGQ2_WORKQ;
3432 NG_QUEUE_UNLOCK(&node->nd_input_queue);
3433 break; /* go look for another node */
3434 } else {
3435 NG_QUEUE_UNLOCK(&node->nd_input_queue);
3436 NGI_GET_NODE(item, node); /* zaps stored node */
3437 ng_apply_item(node, item, rw);
3438 NG_NODE_UNREF(node);
3439 }
3440 }
3441 NET_EPOCH_EXIT(et);
3442 NG_NODE_UNREF(node);
3443 CURVNET_RESTORE();
3444 }
3445}
3446
3447/*
3448 * XXX

Callers

nothing calls this directly

Calls 2

ng_dequeueFunction · 0.70
ng_apply_itemFunction · 0.70

Tested by

no test coverage detected