Eliminate unnecessary SMARTLIST_DEL_CURRENT() invocations in channel.c, channeltls.c

This commit is contained in:
Andrea Shepard 2012-10-08 20:02:42 -07:00
parent bb92a2d7a8
commit 17356fe7fd
No known key found for this signature in database
GPG Key ID: 80BF498218A1E61B
2 changed files with 32 additions and 61 deletions

View File

@ -761,9 +761,6 @@ channel_free(channel_t *chan)
void void
channel_force_free(channel_t *chan) channel_force_free(channel_t *chan)
{ {
cell_queue_entry_t *tmp = NULL;
channel_t *tmpchan = NULL;
tor_assert(chan); tor_assert(chan);
/* Call a free method if there is one */ /* Call a free method if there is one */
@ -778,9 +775,7 @@ channel_force_free(channel_t *chan)
if (chan->u.listener.incoming_list) { if (chan->u.listener.incoming_list) {
SMARTLIST_FOREACH_BEGIN(chan->u.listener.incoming_list, SMARTLIST_FOREACH_BEGIN(chan->u.listener.incoming_list,
channel_t *, qchan) { channel_t *, qchan) {
tmpchan = qchan; channel_request_close(qchan);
SMARTLIST_DEL_CURRENT(chan->u.listener.incoming_list, qchan);
channel_request_close(tmpchan);
} SMARTLIST_FOREACH_END(qchan); } SMARTLIST_FOREACH_END(qchan);
smartlist_free(chan->u.listener.incoming_list); smartlist_free(chan->u.listener.incoming_list);
@ -794,8 +789,6 @@ channel_force_free(channel_t *chan)
if (chan->u.cell_chan.cell_queue) { if (chan->u.cell_chan.cell_queue) {
SMARTLIST_FOREACH_BEGIN(chan->u.cell_chan.cell_queue, SMARTLIST_FOREACH_BEGIN(chan->u.cell_chan.cell_queue,
cell_queue_entry_t *, q) { cell_queue_entry_t *, q) {
tmp = q;
SMARTLIST_DEL_CURRENT(chan->u.cell_chan.cell_queue, q);
tor_free(q); tor_free(q);
} SMARTLIST_FOREACH_END(q); } SMARTLIST_FOREACH_END(q);
@ -807,14 +800,12 @@ channel_force_free(channel_t *chan)
if (chan->u.cell_chan.outgoing_queue) { if (chan->u.cell_chan.outgoing_queue) {
SMARTLIST_FOREACH_BEGIN(chan->u.cell_chan.outgoing_queue, SMARTLIST_FOREACH_BEGIN(chan->u.cell_chan.outgoing_queue,
cell_queue_entry_t *, q) { cell_queue_entry_t *, q) {
tmp = q; if (q->type == CELL_QUEUE_PACKED) {
SMARTLIST_DEL_CURRENT(chan->u.cell_chan.outgoing_queue, q); if (q->u.packed.packed_cell) {
if (tmp->type == CELL_QUEUE_PACKED) { packed_cell_free(q->u.packed.packed_cell);
if (tmp->u.packed.packed_cell) {
packed_cell_free(tmp->u.packed.packed_cell);
} }
} }
tor_free(tmp); tor_free(q);
} SMARTLIST_FOREACH_END(q); } SMARTLIST_FOREACH_END(q);
smartlist_free(chan->u.cell_chan.outgoing_queue); smartlist_free(chan->u.cell_chan.outgoing_queue);
@ -2055,10 +2046,8 @@ channel_process_incoming(channel_t *listener)
/* Make sure this is set correctly */ /* Make sure this is set correctly */
channel_mark_incoming(chan); channel_mark_incoming(chan);
listener->u.listener.listener(listener, chan); listener->u.listener.listener(listener, chan);
SMARTLIST_DEL_CURRENT(listener->u.listener.incoming_list, chan);
} SMARTLIST_FOREACH_END(chan); } SMARTLIST_FOREACH_END(chan);
tor_assert(smartlist_len(listener->u.listener.incoming_list) == 0);
smartlist_free(listener->u.listener.incoming_list); smartlist_free(listener->u.listener.incoming_list);
listener->u.listener.incoming_list = NULL; listener->u.listener.incoming_list = NULL;
} }
@ -2484,53 +2473,44 @@ channel_run_cleanup(void)
void void
channel_free_all(void) channel_free_all(void)
{ {
channel_t *tmp = NULL;
log_debug(LD_CHANNEL, log_debug(LD_CHANNEL,
"Shutting down channels..."); "Shutting down channels...");
/* First, let's go for finished channels */ /* First, let's go for finished channels */
if (finished_channels) { if (finished_channels) {
SMARTLIST_FOREACH_BEGIN(finished_channels, channel_t *, curr) { SMARTLIST_FOREACH_BEGIN(finished_channels, channel_t *, curr) {
tmp = curr;
/* Remove it from the list */
SMARTLIST_DEL_CURRENT(finished_channels, curr);
/* Deregister and free it */ /* Deregister and free it */
tor_assert(tmp); tor_assert(curr);
log_debug(LD_CHANNEL, log_debug(LD_CHANNEL,
"Cleaning up finished channel %p (ID " U64_FORMAT ") " "Cleaning up finished channel %p (ID " U64_FORMAT ") "
"in state %s (%d)", "in state %s (%d)",
tmp, U64_PRINTF_ARG(tmp->global_identifier), curr, U64_PRINTF_ARG(curr->global_identifier),
channel_state_to_string(tmp->state), tmp->state); channel_state_to_string(curr->state), curr->state);
channel_unregister(tmp); channel_unregister(curr);
channel_free(tmp); channel_free(curr);
} SMARTLIST_FOREACH_END(curr); } SMARTLIST_FOREACH_END(curr);
smartlist_free(finished_channels); smartlist_free(finished_channels);
finished_channels = NULL; finished_channels = NULL;
tmp = NULL;
} }
/* Now the listeners */ /* Now the listeners */
if (listening_channels) { if (listening_channels) {
SMARTLIST_FOREACH_BEGIN(listening_channels, channel_t *, curr) { SMARTLIST_FOREACH_BEGIN(listening_channels, channel_t *, curr) {
tmp = curr;
/* Remove it from the list */
SMARTLIST_DEL_CURRENT(listening_channels, curr);
/* Close, deregister and free it */ /* Close, deregister and free it */
tor_assert(tmp); tor_assert(curr);
log_debug(LD_CHANNEL, log_debug(LD_CHANNEL,
"Cleaning up listening channel %p (ID " U64_FORMAT ") " "Cleaning up listening channel %p (ID " U64_FORMAT ") "
"in state %s (%d)", "in state %s (%d)",
tmp, U64_PRINTF_ARG(tmp->global_identifier), curr, U64_PRINTF_ARG(curr->global_identifier),
channel_state_to_string(tmp->state), tmp->state); channel_state_to_string(curr->state), curr->state);
/* /*
* We have to unregister first so we don't put it in finished_channels * We have to unregister first so we don't put it in finished_channels
* and allocate that again on close. * and allocate that again on close.
*/ */
channel_unregister(tmp); channel_unregister(curr);
channel_request_close(tmp); channel_request_close(curr);
channel_force_free(tmp); channel_force_free(curr);
} SMARTLIST_FOREACH_END(curr); } SMARTLIST_FOREACH_END(curr);
smartlist_free(listening_channels); smartlist_free(listening_channels);
@ -2540,23 +2520,20 @@ channel_free_all(void)
/* Now all active channels */ /* Now all active channels */
if (active_channels) { if (active_channels) {
SMARTLIST_FOREACH_BEGIN(active_channels, channel_t *, curr) { SMARTLIST_FOREACH_BEGIN(active_channels, channel_t *, curr) {
tmp = curr;
/* Remove it from the list */
SMARTLIST_DEL_CURRENT(active_channels, curr);
/* Close, deregister and free it */ /* Close, deregister and free it */
tor_assert(tmp); tor_assert(curr);
log_debug(LD_CHANNEL, log_debug(LD_CHANNEL,
"Cleaning up active channel %p (ID " U64_FORMAT ") " "Cleaning up active channel %p (ID " U64_FORMAT ") "
"in state %s (%d)", "in state %s (%d)",
tmp, U64_PRINTF_ARG(tmp->global_identifier), curr, U64_PRINTF_ARG(curr->global_identifier),
channel_state_to_string(tmp->state), tmp->state); channel_state_to_string(curr->state), curr->state);
/* /*
* We have to unregister first so we don't put it in finished_channels * We have to unregister first so we don't put it in finished_channels
* and allocate that again on close. * and allocate that again on close.
*/ */
channel_unregister(tmp); channel_unregister(curr);
channel_request_close(tmp); channel_request_close(curr);
channel_force_free(tmp); channel_force_free(curr);
} SMARTLIST_FOREACH_END(curr); } SMARTLIST_FOREACH_END(curr);
smartlist_free(active_channels); smartlist_free(active_channels);
@ -2566,23 +2543,20 @@ channel_free_all(void)
/* Now all channels, in case any are left over */ /* Now all channels, in case any are left over */
if (all_channels) { if (all_channels) {
SMARTLIST_FOREACH_BEGIN(all_channels, channel_t *, curr) { SMARTLIST_FOREACH_BEGIN(all_channels, channel_t *, curr) {
tmp = curr;
/* Remove it from the list */
SMARTLIST_DEL_CURRENT(all_channels, curr);
/* Close, deregister and free it */ /* Close, deregister and free it */
tor_assert(tmp); tor_assert(curr);
log_debug(LD_CHANNEL, log_debug(LD_CHANNEL,
"Cleaning up leftover channel %p (ID " U64_FORMAT ") " "Cleaning up leftover channel %p (ID " U64_FORMAT ") "
"in state %s (%d)", "in state %s (%d)",
tmp, U64_PRINTF_ARG(tmp->global_identifier), curr, U64_PRINTF_ARG(curr->global_identifier),
channel_state_to_string(tmp->state), tmp->state); channel_state_to_string(curr->state), curr->state);
channel_unregister(tmp); channel_unregister(curr);
if (!(tmp->state == CHANNEL_STATE_CLOSING || if (!(curr->state == CHANNEL_STATE_CLOSING ||
tmp->state == CHANNEL_STATE_CLOSED || curr->state == CHANNEL_STATE_CLOSED ||
tmp->state == CHANNEL_STATE_ERROR)) { curr->state == CHANNEL_STATE_ERROR)) {
channel_request_close(tmp); channel_request_close(curr);
} }
channel_force_free(tmp); channel_force_free(curr);
} SMARTLIST_FOREACH_END(curr); } SMARTLIST_FOREACH_END(curr);
smartlist_free(all_channels); smartlist_free(all_channels);

View File

@ -296,7 +296,6 @@ static void
channel_tls_close_method(channel_t *chan) channel_tls_close_method(channel_t *chan)
{ {
channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan); channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan);
channel_t *tmp = NULL;
tor_assert(tlschan); tor_assert(tlschan);
@ -317,9 +316,7 @@ channel_tls_close_method(channel_t *chan)
if (chan->u.listener.incoming_list) { if (chan->u.listener.incoming_list) {
SMARTLIST_FOREACH_BEGIN(chan->u.listener.incoming_list, SMARTLIST_FOREACH_BEGIN(chan->u.listener.incoming_list,
channel_t *, ichan) { channel_t *, ichan) {
tmp = ichan; channel_request_close(ichan);
SMARTLIST_DEL_CURRENT(chan->u.listener.incoming_list, ichan);
channel_request_close(tmp);
} SMARTLIST_FOREACH_END(ichan); } SMARTLIST_FOREACH_END(ichan);
smartlist_free(chan->u.listener.incoming_list); smartlist_free(chan->u.listener.incoming_list);