[MAJOR] switched buffers to mempools v2

This commit is contained in:
Willy Tarreau 2007-05-13 19:56:02 +02:00
parent c6ca1a02aa
commit 7341d94c5d
6 changed files with 27 additions and 10 deletions

View File

@ -22,11 +22,19 @@
#ifndef _PROTO_BUFFERS_H
#define _PROTO_BUFFERS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <common/config.h>
#include <common/memory.h>
#include <types/buffers.h>
extern struct pool_head *pool2_buffer;
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_buffer();
/* Initializes all fields in the buffer. The ->rlim field is initialized last
* so that the compiler can optimize it away if changed immediately after the
* call to this function.

View File

@ -73,9 +73,6 @@ struct buffer {
char data[BUFSIZE];
};
#define sizeof_buffer sizeof(struct buffer)
extern void **pool_buffer;
#endif /* _TYPES_BUFFERS_H */

View File

@ -15,9 +15,19 @@
#include <string.h>
#include <common/config.h>
#include <common/memory.h>
#include <proto/buffers.h>
void **pool_buffer = NULL;
struct pool_head *pool2_buffer;
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
int init_buffer()
{
pool2_buffer = create_pool("buffer", sizeof(struct buffer), MEM_F_SHARED);
return pool2_buffer != NULL;
}
/* writes <len> bytes from message <msg> to buffer <buf>. Returns 0 in case of
* success, or the number of bytes available otherwise.

View File

@ -347,7 +347,7 @@ int event_accept(int fd) {
write(1, trash, len);
}
if ((s->req = pool_alloc(buffer)) == NULL) { /* no memory */
if ((s->req = pool_alloc2(pool2_buffer)) == NULL) { /* no memory */
if (txn->hdr_idx.v != NULL)
pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
if (txn->rsp.cap != NULL)
@ -369,8 +369,8 @@ int event_accept(int fd) {
s->req->wto = s->be->srvtimeout;
s->req->cto = s->be->srvtimeout;
if ((s->rep = pool_alloc(buffer)) == NULL) { /* no memory */
pool_free(buffer, s->req);
if ((s->rep = pool_alloc2(pool2_buffer)) == NULL) { /* no memory */
pool_free2(pool2_buffer, s->req);
if (txn->hdr_idx.v != NULL)
pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
if (txn->rsp.cap != NULL)

View File

@ -374,6 +374,7 @@ void init(int argc, char **argv)
localtime((time_t *)&now.tv_sec);
start_date = now;
init_buffer();
init_task();
init_session();
init_proto_http();
@ -661,7 +662,7 @@ void deinit(void)
if (fdtab) free(fdtab);
pool_destroy2(pool2_session);
pool_destroy(pool_buffer);
pool_destroy2(pool2_buffer);
pool_destroy(pool_requri);
pool_destroy2(pool2_task);
pool_destroy(pool_capture);

View File

@ -21,6 +21,7 @@
#include <types/proxy.h>
#include <types/server.h>
#include <proto/buffers.h>
#include <proto/hdr_idx.h>
#include <proto/session.h>
#include <proto/queue.h>
@ -38,9 +39,9 @@ void session_free(struct session *s)
if (s->pend_pos)
pendconn_free(s->pend_pos);
if (s->req)
pool_free(buffer, s->req);
pool_free2(pool2_buffer, s->req);
if (s->rep)
pool_free(buffer, s->rep);
pool_free2(pool2_buffer, s->rep);
if (txn->hdr_idx.v != NULL)
pool_free_to(s->fe->hdr_idx_pool, txn->hdr_idx.v);