gboolean nmp_netns_pop (NMPNetns *self) { NetnsInfo *info; int ns_types; g_return_val_if_fail (NMP_IS_NETNS (self), FALSE); _stack_ensure_init (); info = _stack_peek (); g_return_val_if_fail (info, FALSE); g_return_val_if_fail (info->netns == self, FALSE); if (info->count > 1) { info->count--; _LOGt (self, "pop#%u* (decrease count to %d)", _stack_size () - 1, info->count); return TRUE; } g_return_val_if_fail (info->count == 1, FALSE); /* cannot pop the original netns. */ g_return_val_if_fail (_stack_size () > 1, FALSE); _LOGD (self, "pop#%u", _stack_size () - 1); ns_types = info->ns_types; _stack_pop (); return _netns_switch_pop (self, ns_types); }
// -----[ _radix_tree_enum_has_next ]-------------------------------- static int _radix_tree_enum_has_next(void * ctx) { _enum_ctx_t * ectx= (_enum_ctx_t *) ctx; // Depth first search while ((ectx->data == NULL) && (ectx->tree_item != NULL)) { if (ectx->tree_item->data != NULL) ectx->data= ectx->tree_item->data; // Move to next item if (ectx->tree_item->left != NULL) { if (ectx->tree_item->right != NULL) _stack_push(ectx->stack, ectx->tree_item->right, ectx->key_len+1, ectx->key+(1 << (ectx->tree->key_len-ectx->key_len-1))); ectx->tree_item= ectx->tree_item->left; ectx->key_len++; } else if (ectx->tree_item->right != NULL) { ectx->tree_item= ectx->tree_item->right; ectx->key= ectx->key+(1 << (ectx->tree->key_len-ectx->key_len-1)); ectx->key_len++; } else { if (stack_depth(ectx->stack) > 0) _stack_pop(ectx->stack, &ectx->tree_item, &ectx->key_len, &ectx->key); else ectx->tree_item= NULL; } } return (ectx->data != NULL); }
/** * Call the 'fForEach' function for each non empty node. */ int radix_tree_for_each(gds_radix_tree_t * tree, FRadixTreeForEach fForEach, void * ctx) { gds_stack_t * stack= stack_create(tree->key_len); _radix_tree_item_t * tree_item; int result= 0; uint32_t key; uint8_t key_len; tree_item= tree->root; key= 0; key_len= 0; // Depth first search while (tree_item != NULL) { if (tree_item->data!= NULL) { result= fForEach(key, key_len, tree_item->data, ctx); if (result != 0) return result; } if (tree_item->left != NULL) { if (tree_item->right != NULL) _stack_push(stack, tree_item->right, key_len+1, key+(1 << (tree->key_len-key_len-1))); tree_item= tree_item->left; key_len++; } else if (tree_item->right != NULL) { tree_item= tree_item->right; key= key+(1 << (tree->key_len-key_len-1)); key_len++; } else { if (stack_depth(stack) > 0) _stack_pop(stack, &tree_item, &key_len, &key); else break; } } stack_destroy(&stack); return 0; }
int nano_fiber_stack_pop(struct nano_stack *stack, uint32_t *pData, int32_t timeout_in_ticks) { return _stack_pop(stack, pData, timeout_in_ticks); }