Refactor error latching

parent b2d66c4c
......@@ -325,6 +325,18 @@ tree_free(struct vdp_ctx *vdx, struct node *node)
node_free(&node);
}
void
tree_latch_error(struct bytes_tree *tree, int retval)
{
CHECK_OBJ_NOTNULL(tree, BYTES_TREE_MAGIC);
AN(retval);
Lck_Lock(&tree->tree_lock);
if (tree->retval == 0)
tree->retval = retval;
Lck_Unlock(&tree->tree_lock);
}
/* ============================================================
* node insert / state transitions
*/
......
......@@ -251,6 +251,7 @@ void set_closed(struct bytes_tree *, struct node *);
void tree_prune(struct vdp_ctx *, struct node *);
void tree_free(struct vdp_ctx *, struct node *);
void tree_latch_error(struct bytes_tree *tree, int retval);
//--------------
......
......@@ -322,7 +322,7 @@ vped_include(struct req *preq, const char *src, const char *host,
VSLb(req->vsl, SLT_Error,
"Cannot allocate workspace for parallel ESI data");
req_fini(&req, wrk);
tree->retval = -1;
tree_latch_error(tree, -1);
return (-1);
}
......@@ -539,11 +539,7 @@ pesi_buf_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
VSLdbg(vdx, "bytes_add: exit after transient alloc "
"failure");
Lck_Lock(&tree->tree_lock);
if (tree->retval == 0)
tree->retval = -1;
Lck_Unlock(&tree->tree_lock);
tree_latch_error(tree, -1);
node_free(&node);
return (tree->retval);
......@@ -1009,13 +1005,9 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
node_insert(tree, child);
child = NULL;
}
else if (! incl_cont && tree->retval == 0) {
Lck_Lock(&tree->tree_lock);
if (tree->retval == 0)
tree->retval = -1;
Lck_Unlock(&tree->tree_lock);
node_free(&child);
} else
else if (incl_cont == 0)
tree_latch_error(tree, -1);
if (child != NULL)
node_free(&child);
AZ(child);
......@@ -1106,8 +1098,8 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
break;
}
}
if (retval != 0 && tree->retval == 0)
tree->retval = retval;
if (retval != 0)
tree_latch_error(tree, retval);
return (tree->retval);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment