summaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-04-11 00:30:29 +0000
committerNick Mathewson <nickm@torproject.org>2007-04-11 00:30:29 +0000
commit28de06b8e654800bb1221467d6c8cbbf8d19987d (patch)
treea597073932f1ae8407acce3898d103821571723f /src/or/relay.c
parent6ba0b0e9f46cedfa83813f1faf63ab4a24456e4d (diff)
downloadtor-28de06b8e654800bb1221467d6c8cbbf8d19987d.tar.gz
tor-28de06b8e654800bb1221467d6c8cbbf8d19987d.zip
r12337@catbus: nickm | 2007-04-10 17:55:26 -0400
Add support for using memory pools to allocate queued cell; pass --disable-cell-pool to configure to disable this. svn:r9939
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index 4cc0635314..4fd6648116 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -13,6 +13,7 @@ const char relay_c_id[] =
**/
#include "or.h"
+#include "../common/mempool.h"
static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
crypt_path_t **layer_hint, char *recognized);
@@ -1477,18 +1478,67 @@ circuit_consider_sending_sendme(circuit_t *circ, crypt_path_t *layer_hint)
#define assert_active_circuits_ok_paranoid(conn)
#endif
+#ifdef ENABLE_CELL_POOL
+static mp_pool_t *cell_pool;
+/* DOCDOC */
+void
+init_cell_pool(void)
+{
+ tor_assert(!cell_pool);
+ cell_pool = mp_pool_new(sizeof(packed_cell_t), 64);
+}
+
+/* DOCDOC */
+void
+free_cell_pool(void)
+{
+ tor_assert(cell_pool);
+ mp_pool_destroy(cell_pool);
+ cell_pool = NULL;
+}
+
/** Release storage held by <b>cell</b> */
static INLINE void
packed_cell_free(packed_cell_t *cell)
{
+ mp_pool_release(cell);
+}
+
+/* DOCDOC */
+static INLINE packed_cell_t*
+packed_cell_alloc(void)
+{
+ return mp_pool_get(cell_pool);
+}
+#else
+void
+init_cell_pool(void)
+{
+}
+
+void
+free_cell_pool(void)
+{
+}
+
+static INLINE void
+packed_cell_free(packed_cell_t *cell)
+{
tor_free(cell);
}
+static INLINE packed_cell_t *
+packed_cell_alloc(void)
+{
+ return tor_malloc(sizeof(packed_cell_t));
+}
+#endif
+
/** Allocate a new copy of packed <b>cell</b>. */
static INLINE packed_cell_t *
packed_cell_copy(const cell_t *cell)
{
- packed_cell_t *c = tor_malloc(sizeof(packed_cell_t));
+ packed_cell_t *c = packed_cell_alloc();
cell_pack(c, cell);
c->next = NULL;
return c;