From: phk Date: Tue, 18 Apr 2006 07:34:24 +0000 (+0000) Subject: Add trivial malloc backed storage backend. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e9718883e8ae22445ca2cd6e493923533c5ec4f;p=varnish Add trivial malloc backed storage backend. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@140 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 9380faf9..29a35f4f 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -17,6 +17,7 @@ varnishd_SOURCES = \ cli_event.c \ hash_simple_list.c \ mgt_child.c \ + storage_malloc.c \ tcp.c \ varnishd.c diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 58ed922a..f42ce40b 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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 index 00000000..4baf37dc --- /dev/null +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * Storage method based on malloc(3) + */ + +#include +#include +#include +#include + +#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 +};