Skip to content

Commit 75e88ca

Browse files
committed
SQUASHME: ocstash differences to dridis proposal
This is basically a diff to bf84027 and bf84027 combined
1 parent a5266b2 commit 75e88ca

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

bin/varnishd/cache/cache_req.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,22 @@
4747
#include "vtim.h"
4848

4949
/*--------------------------------------------------------------------
50-
* TODO: describe.
50+
* Facility to keep obcore references until the end of the task across restarts
5151
*/
5252

5353
struct ocstash {
54-
unsigned l;
55-
unsigned n;
54+
unsigned magic;
55+
#define OCSTASH_MAGIC 0x242031b5
56+
uint16_t l;
57+
uint16_t n;
5658
struct objcore * ocs[] v_counted_by_(l);
5759
};
5860

5961
static void
6062
ocstash_push(struct ocstash *stash, struct objcore **ocp)
6163
{
6264

63-
AN(stash);
65+
CHECK_OBJ_NOTNULL(stash, OCSTASH_MAGIC);
6466
assert(stash->n < stash->l);
6567
TAKE_OBJ_NOTNULL(stash->ocs[stash->n], ocp, OBJCORE_MAGIC);
6668
stash->n++;
@@ -69,10 +71,11 @@ ocstash_push(struct ocstash *stash, struct objcore **ocp)
6971
static void
7072
ocstash_clear(struct worker *wrk, struct ocstash *stash)
7173
{
72-
unsigned u;
74+
uint16_t u;
7375

7476
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
75-
AN(stash);
77+
CHECK_OBJ_NOTNULL(stash, OCSTASH_MAGIC);
78+
assert(stash->n <= stash->l);
7679
for (u = 0; u < stash->n; u++)
7780
(void)HSH_DerefObjCore(wrk, &stash->ocs[u], HSH_RUSH_POLICY);
7881
for (; u < stash->l; u++)
@@ -172,7 +175,7 @@ Req_New(struct sess *sp)
172175
{
173176
struct pool *pp;
174177
struct req *req;
175-
uint16_t nhttp;
178+
uint16_t l, nhttp;
176179
unsigned sz, hl;
177180
char *p, *e;
178181

@@ -232,10 +235,12 @@ Req_New(struct sess *sp)
232235
p = (void*)PRNDUP(p + sizeof(*req->top));
233236

234237
req->max_restarts = cache_param->max_restarts;
235-
sz = SIZEOF_FLEX_OBJ(req->stash, ocs, req->max_restarts + 1);
238+
assert(req->max_restarts + 1 <= UINT16_MAX);
239+
l = req->max_restarts + 1;
240+
sz = SIZEOF_FLEX_OBJ(req->stash, ocs, l);
236241
req->stash = (void*)p;
237-
ZERO_OBJ(req->stash, sz);
238-
req->stash->l = req->max_restarts + 1;
242+
req->stash->magic = OCSTASH_MAGIC;
243+
req->stash->l = l;
239244
p += sz;
240245
p = (void*)PRNDUP(p);
241246

0 commit comments

Comments
 (0)