[tor-commits] [tor/master] Use TOR_SIMPLEQ for packed_cell_t

nickm at torproject.org nickm at torproject.org
Thu Jul 18 18:40:18 UTC 2013


commit 1047e7dcb05cbf4c98276d00c157cf0506b451d5
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Mar 22 14:25:34 2013 -0400

    Use TOR_SIMPLEQ for packed_cell_t
---
 src/or/circuitlist.c |    2 ++
 src/or/circuitmux.c  |    2 +-
 src/or/or.h          |    8 +++++---
 src/or/relay.c       |   36 +++++++++++++++---------------------
 src/or/relay.h       |    1 +
 5 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 5e51301..2a85b7d 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -682,6 +682,7 @@ init_circuit_base(circuit_t *circ)
 
   circ->package_window = circuit_initial_package_window();
   circ->deliver_window = CIRCWINDOW_START;
+  cell_queue_init(&circ->n_chan_cells);
 
   circuit_add(circ);
 }
@@ -727,6 +728,7 @@ or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
     circuit_set_p_circid_chan(circ, p_circ_id, p_chan);
 
   circ->remaining_relay_early_cells = MAX_RELAY_EARLY_CELLS_PER_CIRCUIT;
+  cell_queue_init(&circ->p_chan_cells);
 
   init_circuit_base(TO_CIRCUIT(circ));
 
diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index 0814163..77cb2f9 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -510,7 +510,7 @@ circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux, channel_t *chan)
 {
   packed_cell_t *cell;
   int n_bad = 0;
-  for (cell = cmux->destroy_cell_queue.head; cell; cell = cell->next) {
+  TOR_SIMPLEQ_FOREACH(cell, &cmux->destroy_cell_queue.head, next) {
     circid_t circid = 0;
     if (packed_cell_is_destroy(chan, cell, &circid)) {
       channel_mark_circid_usable(chan, circid);
diff --git a/src/or/or.h b/src/or/or.h
index b8c4279..06363fa 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -99,6 +99,7 @@
 #include "ht.h"
 #include "replaycache.h"
 #include "crypto_curve25519.h"
+#include "tor_queue.h"
 
 /* These signals are defined to help handle_control_signal work.
  */
@@ -1083,7 +1084,8 @@ typedef struct var_cell_t {
 
 /** A cell as packed for writing to the network. */
 typedef struct packed_cell_t {
-  struct packed_cell_t *next; /**< Next cell queued on this circuit. */
+  /** Next cell queued on this circuit. */
+  TOR_SIMPLEQ_ENTRY(packed_cell_t) next;
   char body[CELL_MAX_NETWORK_SIZE]; /**< Cell as packed for network. */
 } packed_cell_t;
 
@@ -1105,8 +1107,8 @@ typedef struct insertion_time_queue_t {
 /** A queue of cells on a circuit, waiting to be added to the
  * or_connection_t's outbuf. */
 typedef struct cell_queue_t {
-  packed_cell_t *head; /**< The first cell, or NULL if the queue is empty. */
-  packed_cell_t *tail; /**< The last cell, or NULL if the queue is empty. */
+  /** Linked list of packed_cell_t*/
+  TOR_SIMPLEQ_HEAD(cell_simpleq, packed_cell_t) head;
   int n; /**< The number of cells in the queue. */
   insertion_time_queue_t *insertion_times; /**< Insertion times of cells. */
 } cell_queue_t;
diff --git a/src/or/relay.c b/src/or/relay.c
index 7ec7e03..81132a1 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2129,7 +2129,6 @@ packed_cell_copy(const cell_t *cell, int wide_circ_ids)
 {
   packed_cell_t *c = packed_cell_new();
   cell_pack(c, cell, wide_circ_ids);
-  c->next = NULL;
   return c;
 }
 
@@ -2137,14 +2136,7 @@ packed_cell_copy(const cell_t *cell, int wide_circ_ids)
 void
 cell_queue_append(cell_queue_t *queue, packed_cell_t *cell)
 {
-  if (queue->tail) {
-    tor_assert(!queue->tail->next);
-    queue->tail->next = cell;
-  } else {
-    queue->head = cell;
-  }
-  queue->tail = cell;
-  cell->next = NULL;
+  TOR_SIMPLEQ_INSERT_TAIL(&queue->head, cell, next);
   ++queue->n;
 }
 
@@ -2187,18 +2179,24 @@ cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell,
   cell_queue_append(queue, copy);
 }
 
+/** Initialize <b>queue</b> as an empty cell queue. */
+void
+cell_queue_init(cell_queue_t *queue)
+{
+  memset(queue, 0, sizeof(cell_queue_t));
+  TOR_SIMPLEQ_INIT(&queue->head);
+}
+
 /** Remove and free every cell in <b>queue</b>. */
 void
 cell_queue_clear(cell_queue_t *queue)
 {
-  packed_cell_t *cell, *next;
-  cell = queue->head;
-  while (cell) {
-    next = cell->next;
+  packed_cell_t *cell;
+  while ((cell = TOR_SIMPLEQ_FIRST(&queue->head))) {
+    TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
     packed_cell_free_unchecked(cell);
-    cell = next;
   }
-  queue->head = queue->tail = NULL;
+  TOR_SIMPLEQ_INIT(&queue->head);
   queue->n = 0;
   if (queue->insertion_times) {
     while (queue->insertion_times->first) {
@@ -2215,14 +2213,10 @@ cell_queue_clear(cell_queue_t *queue)
 static INLINE packed_cell_t *
 cell_queue_pop(cell_queue_t *queue)
 {
-  packed_cell_t *cell = queue->head;
+  packed_cell_t *cell = TOR_SIMPLEQ_FIRST(&queue->head);
   if (!cell)
     return NULL;
-  queue->head = cell->next;
-  if (cell == queue->tail) {
-    tor_assert(!queue->head);
-    queue->tail = NULL;
-  }
+  TOR_SIMPLEQ_REMOVE_HEAD(&queue->head, next);
   --queue->n;
   return cell;
 }
diff --git a/src/or/relay.h b/src/or/relay.h
index 4be3194..59e107b 100644
--- a/src/or/relay.h
+++ b/src/or/relay.h
@@ -51,6 +51,7 @@ size_t packed_cell_mem_cost(void);
 /* For channeltls.c */
 void packed_cell_free(packed_cell_t *cell);
 
+void cell_queue_init(cell_queue_t *queue);
 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,





More information about the tor-commits mailing list