r137 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Tue Apr 11 10:28:20 CEST 2006
Author: phk
Date: 2006-04-11 10:28:20 +0200 (Tue, 11 Apr 2006)
New Revision: 137
Added:
trunk/varnish-cache/bin/varnishd/hash_simple_list.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_main.c
trunk/varnish-cache/bin/varnishd/cache_shmlog.c
trunk/varnish-cache/bin/varnishd/cache_vcl.c
trunk/varnish-cache/bin/varnishd/cli_event.c
trunk/varnish-cache/bin/varnishd/cli_event.h
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt.h
trunk/varnish-cache/bin/varnishd/tcp.c
Log:
Beginnings of the object lookup stuff: A simple list based
implementation to get things moving.
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-04-06 10:01:09 UTC (rev 136)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-04-11 08:28:20 UTC (rev 137)
@@ -15,6 +15,7 @@
cache_shmlog.c \
cache_vcl.c \
cli_event.c \
+ hash_simple_list.c \
mgt_child.c \
tcp.c \
varnishd.c
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-04-06 10:01:09 UTC (rev 136)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-04-11 08:28:20 UTC (rev 137)
@@ -15,6 +15,28 @@
struct worker;
#endif
+/* Hashing -----------------------------------------------------------*/
+struct object { /* XXX: this goes elsewhere in due time */
+ unsigned char hash[16];
+ unsigned refcnt;
+};
+
+typedef void hash_init_f(void);
+typedef struct object *hash_lookup_f(unsigned char *key, struct object *nobj);
+typedef void hash_purge_f(struct object *obj);
+
+struct hash_slinger {
+ const char *name;
+ hash_init_f *init;
+ hash_lookup_f *lookup;
+ hash_purge_f *purge;
+};
+
+extern struct hash_slinger hsl_slinger;
+
+/* Prototypes etc ----------------------------------------------------*/
+
+
/* cache_acceptor.c */
void *vca_main(void *arg);
void vca_retire_session(struct sess *sp);
Property changes on: trunk/varnish-cache/bin/varnishd/cache_main.c
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/cache_vcl.c
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/cli_event.c
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/cli_event.h
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/varnish-cache/bin/varnishd/hash_simple_list.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2006-04-06 10:01:09 UTC (rev 136)
+++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2006-04-11 08:28:20 UTC (rev 137)
@@ -0,0 +1,89 @@
+/*
+ * $Id$
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/queue.h>
+
+#include <libvarnish.h>
+#include <vcl_lang.h>
+#include <cache.h>
+
+struct hsl_entry {
+ TAILQ_ENTRY(hsl_entry) list;
+ struct object *obj;
+};
+
+static TAILQ_HEAD(, hsl_entry) hsl_head = TAILQ_HEAD_INITIALIZER(hsl_head);
+static pthread_mutex_t hsl_mutex;
+
+static void
+hsl_init(void)
+{
+
+ AZ(pthread_mutex_init(&hsl_mutex, NULL));
+}
+
+static struct object *
+hsl_lookup(unsigned char *key, struct object *nobj)
+{
+ struct hsl_entry *he, *he2;
+ int i;
+
+ AZ(pthread_mutex_lock(&hsl_mutex));
+ TAILQ_FOREACH(he, &hsl_head, list) {
+ i = memcmp(key, he->obj->hash, sizeof he->obj->hash);
+ if (i == 0) {
+ he->obj->refcnt++;
+ nobj = he->obj;
+ AZ(pthread_mutex_unlock(&hsl_mutex));
+ return (nobj);
+ }
+ if (i < 0)
+ continue;
+ if (nobj == NULL) {
+ AZ(pthread_mutex_unlock(&hsl_mutex));
+ return (NULL);
+ }
+ break;
+ }
+ he2 = calloc(sizeof *he2, 1);
+ assert(he2 != NULL);
+ he2->obj = nobj;
+ nobj->refcnt++;
+ if (he != NULL)
+ TAILQ_INSERT_BEFORE(he, he2, list);
+ else
+ TAILQ_INSERT_TAIL(&hsl_head, he2, list);
+ AZ(pthread_mutex_unlock(&hsl_mutex));
+ return (nobj);
+}
+
+static void
+hsl_purge(struct object *obj)
+{
+ struct hsl_entry *he;
+
+ assert(obj->refcnt > 0);
+ AZ(pthread_mutex_lock(&hsl_mutex));
+ TAILQ_FOREACH(he, &hsl_head, list) {
+ if (he->obj == obj) {
+ TAILQ_REMOVE(&hsl_head, he, list);
+ AZ(pthread_mutex_unlock(&hsl_mutex));
+ free(he);
+ return;
+ }
+ }
+ assert(he != NULL);
+}
+
+struct hash_slinger hsl_slinger = {
+ "simple_list",
+ hsl_init,
+ hsl_lookup,
+ hsl_purge
+};
Property changes on: trunk/varnish-cache/bin/varnishd/heritage.h
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/mgt.h
___________________________________________________________________
Name: svn:keywords
+ Id
Property changes on: trunk/varnish-cache/bin/varnishd/tcp.c
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the varnish-commit
mailing list