r1631 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Tue Jul 3 21:32:21 CEST 2007
Author: phk
Date: 2007-07-03 21:32:21 +0200 (Tue, 03 Jul 2007)
New Revision: 1631
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_backend.c
Log:
Add functions for allocating and freeing bereq structures.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 14:19:40 UTC (rev 1630)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 19:32:21 UTC (rev 1631)
@@ -184,6 +184,14 @@
/* Backend Connection ------------------------------------------------*/
+struct bereq {
+ unsigned magic;
+#define BEREQ_MAGIC 0x3b6d250c
+ TAILQ_ENTRY(bereq) list;
+ struct ws ws[1];
+ struct http http[1];
+};
+
struct vbe_conn {
unsigned magic;
#define VBE_CONN_MAGIC 0x0c5e6592
@@ -362,6 +370,8 @@
struct vbe_conn *VBE_GetFd(struct sess *sp);
void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc, int already);
void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc);
+struct bereq *vbe_new_bereq(void);
+void vbe_free_bereq(struct bereq *bereq);
/* cache_ban.c */
void BAN_Init(void);
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 14:19:40 UTC (rev 1630)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 19:32:21 UTC (rev 1631)
@@ -59,6 +59,7 @@
/* A backend IP */
static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head);
+static TAILQ_HEAD(,bereq) bereq_head = TAILQ_HEAD_INITIALIZER(bereq_head);
static MTX vbemtx;
@@ -76,6 +77,43 @@
/*--------------------------------------------------------------------*/
+struct bereq *
+vbe_new_bereq(void)
+{
+ struct bereq *bereq;
+ volatile unsigned space;
+
+ LOCK(&vbemtx);
+ bereq = TAILQ_FIRST(&bereq_head);
+ if (bereq != NULL)
+ TAILQ_REMOVE(&bereq_head, bereq, list);
+ UNLOCK(&vbemtx);
+ if (bereq == NULL) {
+ space = params->mem_workspace;
+ bereq = calloc(sizeof *bereq + space, 1);
+ if (bereq == NULL)
+ return (NULL);
+ bereq->magic = BEREQ_MAGIC;
+ WS_Init(bereq->ws, bereq + 1, space);
+ }
+ WS_Reset(bereq->ws);
+ return (bereq);
+}
+
+/*--------------------------------------------------------------------*/
+/* XXX: no backpressure on pool size */
+
+void
+vbe_free_bereq(struct bereq *bereq)
+{
+
+ LOCK(&vbemtx);
+ TAILQ_INSERT_HEAD(&bereq_head, bereq, list);
+ UNLOCK(&vbemtx);
+}
+
+/*--------------------------------------------------------------------*/
+
static struct vbe_conn *
vbe_new_conn(void)
{
More information about the varnish-commit
mailing list