[master] ed3b095c0 add a facility to test WS_ReserveSize()
Nils Goroll
nils.goroll at uplex.de
Tue Nov 26 12:44:06 UTC 2019
commit ed3b095c0414af453493580a654f63a02d22e0e8
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Nov 26 13:21:37 2019 +0100
add a facility to test WS_ReserveSize()
diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc
index 51154f366..4f15d0d07 100644
--- a/lib/libvmod_vtc/vmod.vcc
+++ b/lib/libvmod_vtc/vmod.vcc
@@ -96,6 +96,14 @@ as much as needed to leave that many bytes free. The actual allocation size
may be higher to comply with memory alignment requirements of the CPU
architecture. A failed allocation fails the transaction.
+$Function BYTES workspace_reserve(ENUM { client, backend, session, thread },
+ INT size)
+
+Attempt to reserve *size* bytes and release the reservation right
+away. Return the size of the reservation.
+
+See `vtc.workspace_alloc`_ for semantics of the *size* argument.
+
$Function INT workspace_free(ENUM { client, backend, session, thread })
Find how much unallocated space there is left in a workspace.
diff --git a/lib/libvmod_vtc/vmod_vtc.c b/lib/libvmod_vtc/vmod_vtc.c
index f7e58db5c..e52c40d5a 100644
--- a/lib/libvmod_vtc/vmod_vtc.c
+++ b/lib/libvmod_vtc/vmod_vtc.c
@@ -167,6 +167,34 @@ vmod_workspace_alloc(VRT_CTX, VCL_ENUM which, VCL_INT size)
memset(p, '\0', size);
}
+VCL_BYTES v_matchproto_(td_vtc_workspace_reserve)
+vmod_workspace_reserve(VRT_CTX, VCL_ENUM which, VCL_INT size)
+{
+ struct ws *ws;
+ unsigned r;
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ ws = vtc_ws_find(ctx, which);
+ if (ws == NULL)
+ return (0);
+ WS_Assert(ws);
+
+ if (size < 0) {
+ size += WS_ReserveAll(ws);
+ WS_Release(ws, 0);
+ }
+ if (size <= 0) {
+ VRT_fail(ctx, "Attempted negative WS reservation");
+ return (0);
+ }
+ r = WS_ReserveSize(ws, size);
+ if (r == 0)
+ return (0);
+ WS_Release(ws, 0);
+ return (1);
+}
+
VCL_INT v_matchproto_(td_vtc_workspace_free)
vmod_workspace_free(VRT_CTX, VCL_ENUM which)
{
More information about the varnish-commit
mailing list