r4848 - in trunk/varnish-cache: include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Fri May 21 12:34:52 CEST 2010
Author: phk
Date: 2010-05-21 12:34:52 +0200 (Fri, 21 May 2010)
New Revision: 4848
Modified:
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/vsl.c
trunk/varnish-cache/lib/libvarnishapi/vsl.h
Log:
Add a supported iterator over shmlog allocations.
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-05-21 08:13:51 UTC (rev 4847)
+++ trunk/varnish-cache/include/varnishapi.h 2010-05-21 10:34:52 UTC (rev 4848)
@@ -65,4 +65,10 @@
void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type,
const char *ident, unsigned *lenp);
+struct shmalloc *vsl_iter0(struct VSL_data *vd);
+struct shmalloc *vsl_itern(struct VSL_data *vd, struct shmalloc **pp);
+
+#define VSL_FOREACH(var, vd) \
+ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var)))
+
#endif
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-05-21 08:13:51 UTC (rev 4847)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-05-21 10:34:52 UTC (rev 4848)
@@ -145,6 +145,8 @@
return (1);
}
vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
+
+ vd->alloc_seq = slh.alloc_seq;
return (0);
}
@@ -164,13 +166,41 @@
/*--------------------------------------------------------------------*/
+struct shmalloc *
+vsl_iter0(struct VSL_data *vd)
+{
+
+ CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+ if (vd->alloc_seq != vd->vsl_lh->alloc_seq)
+ return(NULL);
+ CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, SHMALLOC_MAGIC);
+ return (&vd->vsl_lh->head);
+}
+
+struct shmalloc *
+vsl_itern(struct VSL_data *vd, struct shmalloc **pp)
+{
+
+ CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+ if (vd->alloc_seq != vd->vsl_lh->alloc_seq)
+ return(NULL);
+ CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC);
+ *pp = SHA_NEXT(*pp);
+ if ((void*)*pp >= vd->vsl_end)
+ return (NULL);
+ CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC);
+ return (*pp);
+}
+
+/*--------------------------------------------------------------------*/
+
static struct shmalloc *
vsl_find_alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident)
{
struct shmalloc *sha;
assert (vd->vsl_lh != NULL);
- for(sha = &vd->vsl_lh->head; (void*)sha < vd->vsl_end; sha = SHA_NEXT(sha)) {
+ VSL_FOREACH(sha, vd) {
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->class, class))
continue;
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-05-21 08:13:51 UTC (rev 4847)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-05-21 10:34:52 UTC (rev 4848)
@@ -41,6 +41,7 @@
int vsl_fd;
struct shmloghead *vsl_lh;
void *vsl_end;
+ unsigned alloc_seq;
unsigned char *log_start;
unsigned char *log_end;
More information about the varnish-commit
mailing list