[master] 8838884 Make the VSM_ITER macro available to all vsm users.

Poul-Henning Kamp phk at varnish-cache.org
Sat Mar 12 15:47:09 CET 2011


commit 8838884f34e50453318873960d975a1ade908ea1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Mar 12 14:46:54 2011 +0000

    Make the VSM_ITER macro available to all vsm users.

diff --git a/bin/varnishd/cache_shmlog.c b/bin/varnishd/cache_shmlog.c
index 2dc6256..94e9a6c 100644
--- a/bin/varnishd/cache_shmlog.c
+++ b/bin/varnishd/cache_shmlog.c
@@ -36,9 +36,9 @@ SVNID("$Id$")
 #include <unistd.h>
 #include <stdarg.h>
 
-#include "vsm.h"
 #include "cache.h"
 #include "vmb.h"
+#include "vsm.h"
 
 static pthread_mutex_t vsl_mtx;
 
diff --git a/bin/varnishd/common.h b/bin/varnishd/common.h
index bccac52..78d59c4 100644
--- a/bin/varnishd/common.h
+++ b/bin/varnishd/common.h
@@ -78,12 +78,6 @@ void *VSM_Alloc(unsigned size, const char *class, const char *type,
 void VSM_Free(const void *ptr);
 void VSM_Clean(void);
 
-
-struct vsm_chunk *vsm_iter_0(void);
-void vsm_iter_n(struct vsm_chunk **pp);
-
-#define VSM_ITER(vd) for ((vd) = vsm_iter_0(); (vd) != NULL; vsm_iter_n(&vd))
-
 /* These classes are opaque to other programs, so we define the here */
 #define VSM_CLASS_FREE	"Free"
 #define VSM_CLASS_COOL	"Cool"
diff --git a/bin/varnishd/mgt_shmem.c b/bin/varnishd/mgt_shmem.c
index 3af3e7b..e55bcc2 100644
--- a/bin/varnishd/mgt_shmem.c
+++ b/bin/varnishd/mgt_shmem.c
@@ -98,12 +98,12 @@ SVNID("$Id$")
 #include <sys/mman.h>
 #include <sys/stat.h>
 
-#include "vsm.h"
 #include "vsc.h"
 #include "vsl.h"
 #include "mgt.h"
 #include "heritage.h"
 #include "vmb.h"
+#include "vsm.h"
 
 #ifndef MAP_HASSEMAPHORE
 #define MAP_HASSEMAPHORE 0 /* XXX Linux */
diff --git a/bin/varnishd/vsm.c b/bin/varnishd/vsm.c
index 4d689ab..c5f6748 100644
--- a/bin/varnishd/vsm.c
+++ b/bin/varnishd/vsm.c
@@ -72,31 +72,6 @@ vsm_release(unsigned seq)
 
 /*--------------------------------------------------------------------*/
 
-struct vsm_chunk *
-vsm_iter_0(void)
-{
-
-	CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC);
-	CHECK_OBJ_NOTNULL(&vsm_head->head, VSM_CHUNK_MAGIC);
-	return (&vsm_head->head);
-}
-
-void
-vsm_iter_n(struct vsm_chunk **pp)
-{
-
-	CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC);
-	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
-	*pp = VSM_NEXT(*pp);
-	if (*pp >= vsm_end) {
-		*pp = NULL;
-		return;
-	}
-	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
-}
-
-/*--------------------------------------------------------------------*/
-
 static void
 vsm_cleanup(void)
 {
@@ -178,7 +153,7 @@ VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
 		if (size > sha->len)
 			continue;
 
-			/* Mark as inconsistent while we write string fields */
+		/* Mark as inconsistent while we write string fields */
 		seq = vsm_mark();
 
 		if (size + sizeof (*sha) < sha->len) {
diff --git a/include/vsm.h b/include/vsm.h
index 09d42c4..caaae06 100644
--- a/include/vsm.h
+++ b/include/vsm.h
@@ -78,4 +78,37 @@ struct vsm_head {
 	struct vsm_chunk	head;
 };
 
+/*
+ * You must include "miniobj.h" and have an assert function to be
+ * able to use the VSM_ITER() macro.
+ */
+#ifdef CHECK_OBJ_NOTNULL
+
+static inline struct vsm_chunk *
+vsm_iter_0(void)
+{
+
+	CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC);
+	CHECK_OBJ_NOTNULL(&vsm_head->head, VSM_CHUNK_MAGIC);
+	return (&vsm_head->head);
+}
+ 
+static inline void
+vsm_iter_n(struct vsm_chunk **pp)
+{
+
+	CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC);
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
+	*pp = VSM_NEXT(*pp);
+	if (*pp >= vsm_end) {
+		*pp = NULL;
+		return;
+	}
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
+}
+
+#define VSM_ITER(vd) for ((vd) = vsm_iter_0(); (vd) != NULL; vsm_iter_n(&vd))
+
+#endif /* CHECK_OBJ_NOTNULL */
+
 #endif



More information about the varnish-commit mailing list