aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/main.c4
-rw-r--r--src/or/or.h3
-rw-r--r--src/or/relay.c52
3 files changed, 58 insertions, 1 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 77d8db1e3..9a063fb09 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1229,6 +1229,9 @@ do_main_loop(void)
}
}
+ /* DOCDOC */
+ init_cell_pool();
+
/* Set up our buckets */
connection_bucket_init();
stats_prev_global_read_bucket = global_read_bucket;
@@ -1665,6 +1668,7 @@ tor_free_all(int postfork)
config_free_all();
router_free_all();
}
+ free_cell_pool();
tor_tls_free_all();
/* stuff in main.c */
smartlist_free(closeable_connection_lst);
diff --git a/src/or/or.h b/src/or/or.h
index cca9c96e0..048e6793c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2667,6 +2667,9 @@ extern uint64_t stats_n_data_bytes_packaged;
extern uint64_t stats_n_data_cells_received;
extern uint64_t stats_n_data_bytes_received;
+void init_cell_pool(void);
+void free_cell_pool(void);
+
void cell_queue_clear(cell_queue_t *queue);
void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
void cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell);
diff --git a/src/or/relay.c b/src/or/relay.c
index 4cc063531..4fd664811 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;