diff options
author | Craig Tiller <ctiller@google.com> | 2016-10-10 14:09:18 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-10-10 14:09:18 -0700 |
commit | d3ee0d5c76626849756e1bff9ffb23de30706c7e (patch) | |
tree | 48df91ac67c51dc36cf2dfce2860bd6c0b515b81 /src/core/lib | |
parent | 686d7a7b7f22b08043414aa7651f89af06f176b8 (diff) |
Better readability
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/iomgr/combiner.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/core/lib/iomgr/combiner.c b/src/core/lib/iomgr/combiner.c index 24ffe41d99..60ee14eb23 100644 --- a/src/core/lib/iomgr/combiner.c +++ b/src/core/lib/iomgr/combiner.c @@ -266,28 +266,34 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx *exec_ctx) { gpr_atm_full_fetch_add(&lock->state, -STATE_ELEM_COUNT_LOW_BIT); GRPC_COMBINER_TRACE( gpr_log(GPR_DEBUG, "C:%p finish old_state=%" PRIdPTR, lock, old_state)); +// Define a macro to ease readability of the following switch statement. +#define OLD_STATE_WAS(orphaned, elem_count) \ + (((orphaned) ? 0 : STATE_UNORPHANED) | \ + ((elem_count)*STATE_ELEM_COUNT_LOW_BIT)) + // Depending on what the previous state was, we need to perform different + // actions. switch (old_state) { default: // we have multiple queued work items: just continue executing them break; - case STATE_UNORPHANED | (2 * STATE_ELEM_COUNT_LOW_BIT): - case 0 | (2 * STATE_ELEM_COUNT_LOW_BIT): + case OLD_STATE_WAS(false, 2): + case OLD_STATE_WAS(true, 2): // we're down to one queued item: if it's the final list we should do that if (!grpc_closure_list_empty(lock->final_list)) { lock->time_to_execute_final_list = true; } break; - case STATE_UNORPHANED | STATE_ELEM_COUNT_LOW_BIT: + case OLD_STATE_WAS(false, 1): // had one count, one unorphaned --> unlocked unorphaned GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; - case 0 | STATE_ELEM_COUNT_LOW_BIT: + case OLD_STATE_WAS(true, 1): // and one count, one orphaned --> unlocked and orphaned really_destroy(exec_ctx, lock); GPR_TIMER_END("combiner.continue_exec_ctx", 0); return true; - case STATE_UNORPHANED: - case 0: + case OLD_STATE_WAS(false, 0): + case OLD_STATE_WAS(true, 0): // these values are illegal - representing an already unlocked or // deleted lock GPR_TIMER_END("combiner.continue_exec_ctx", 0); |