[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Eliminate #ifdef ENABLE_MEMPOOLS in packed_cell_new/free()
commit 170e0df7417e78f7b689f3189e7a0b5b8dfd2722
Author: Andrea Shepard <andrea@xxxxxxxxxxxxxx>
Date: Wed May 21 10:53:25 2014 -0700
Eliminate #ifdef ENABLE_MEMPOOLS in packed_cell_new/free()
---
src/or/relay.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/or/relay.c b/src/or/relay.c
index e593f87..5c430a6 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2268,6 +2268,22 @@ clean_cell_pool(void)
mp_pool_clean(cell_pool, 0, 1);
}
+#define relay_alloc_cell() \
+ mp_pool_get(cell_pool)
+#define relay_free_cell(cell) \
+ mp_pool_release(cell)
+
+#define RELAY_CELL_MEM_COST (sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD)
+
+#else /* !ENABLE_MEMPOOLS case */
+
+#define relay_alloc_cell() \
+ tor_malloc_zero(sizeof(packed_cell_t))
+#define relay_free_cell(cell) \
+ tor_free(cell)
+
+#define RELAY_CELL_MEM_COST (sizeof(packed_cell_t))
+
#endif /* ENABLE_MEMPOOLS */
/** Release storage held by <b>cell</b>. */
@@ -2275,11 +2291,7 @@ static INLINE void
packed_cell_free_unchecked(packed_cell_t *cell)
{
--total_cells_allocated;
-#ifdef ENABLE_MEMPOOLS
- mp_pool_release(cell);
-#else
- tor_free(cell);
-#endif /* ENABLE_MEMPOOLS */
+ relay_free_cell(cell);
}
/** Allocate and return a new packed_cell_t. */
@@ -2287,11 +2299,7 @@ STATIC packed_cell_t *
packed_cell_new(void)
{
++total_cells_allocated;
-#ifdef ENABLE_MEMPOOLS
- return mp_pool_get(cell_pool);
-#else
- return tor_malloc(sizeof(packed_cell_t));
-#endif
+ return relay_alloc_cell();
}
/** Return a packed cell used outside by channel_t lower layer */
@@ -2402,11 +2410,7 @@ cell_queue_pop(cell_queue_t *queue)
size_t
packed_cell_mem_cost(void)
{
-#ifdef ENABLE_MEMPOOLS
- return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD;
-#else
- return sizeof(packed_cell_t);
-#endif /* ENABLE_MEMPOOLS */
+ return RELAY_CELL_MEM_COST;
}
/** DOCDOC */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits