]> err.no Git - varnish/commitdiff
Add trivial malloc backed storage backend.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 18 Apr 2006 07:34:24 +0000 (07:34 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 18 Apr 2006 07:34:24 +0000 (07:34 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@140 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/storage_malloc.c [new file with mode: 0644]

index 9380faf932052d33ce77c47a93c6a54cff536e86..29a35f4f571d12999f473420e4d80dcf1227405c 100644 (file)
@@ -17,6 +17,7 @@ varnishd_SOURCES = \
        cli_event.c \
        hash_simple_list.c \
        mgt_child.c \
+       storage_malloc.c \
        tcp.c \
        varnishd.c
 
index 58ed922adc694fb0c4de714be01d300888f70e50..f42ce40b4a66008183e962e71723b5465c35122f 100644 (file)
@@ -30,6 +30,28 @@ struct hash_slinger {
 
 extern struct hash_slinger hsl_slinger;
 
+/* Storage -----------------------------------------------------------*/
+
+struct storage {
+       TAILQ_ENTRY(storage)    list;
+       void                    *ptr;
+       unsigned                len;
+       void                    *priv;
+};
+
+typedef void storage_init_f(void);
+typedef struct storage *storage_alloc_f(unsigned size);
+typedef void storage_free_f(struct storage *);
+
+struct stevedore {
+       const char              *name;
+       storage_init_f          *init;
+       storage_alloc_f         *alloc;
+       storage_free_f          *free;
+};
+
+extern struct stevedore sma_stevedore;
+
 /* Prototypes etc ----------------------------------------------------*/
 
 
diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c
new file mode 100644 (file)
index 0000000..4baf37d
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * $Id$
+ *
+ * Storage method based on malloc(3)
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+#include <pthread.h>
+
+#include "vcl_lang.h"
+#include "cache.h"
+
+struct sma {
+       struct storage          s;
+};
+
+static void
+sma_init(void)
+{
+}
+
+static struct storage *
+sma_alloc(unsigned size)
+{
+       struct sma *sma;
+
+       sma = calloc(sizeof *sma, 1);
+       assert(sma != NULL);
+       sma->s.priv = sma;
+       sma->s.ptr = malloc(size);
+       assert(sma->s.ptr != NULL);
+       sma->s.len = size;
+       return (&sma->s);
+}
+
+static void
+sma_free(struct storage *s)
+{
+       struct sma *sma;
+
+       sma = s->priv;
+       free(sma->s.ptr);
+       free(sma);
+}
+
+struct stevedore sma_stevedore = {
+       "Malloc",
+       sma_init,
+       sma_alloc,
+       sma_free
+};