[6.2] 4921b0084 add a facility to test WS_ReserveSize()
Martin Blix Grydeland
martin at varnish-software.com
Tue Feb 4 10:03:08 UTC 2020
commit 4921b008487555e2a32d542309e81eefc7870b42
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Nov 26 13:21:37 2019 +0100
add a facility to test WS_ReserveSize()
(cherry picked from commit ed3b095c0414af453493580a654f63a02d22e0e8)
diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc
index e1644fffc..907d8720b 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 ee9d23fa0..a2342c110 100644
--- a/lib/libvmod_vtc/vmod_vtc.c
+++ b/lib/libvmod_vtc/vmod_vtc.c
@@ -169,6 +169,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