Commit a9dbba29 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add trivial malloc backed storage backend.



git-svn-id: http://www.varnish-cache.org/svn/trunk@140 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e1a3a141
......@@ -17,6 +17,7 @@ varnishd_SOURCES = \
cli_event.c \
hash_simple_list.c \
mgt_child.c \
storage_malloc.c \
tcp.c \
varnishd.c
......
......@@ -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 ----------------------------------------------------*/
......
/*
* $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
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment