From 5f8fd27ace0d1f98c480fa7b2b6b293cbbcf921f Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 28 Feb 2013 15:23:09 +0100 Subject: [PATCH] Cluster: refactoring of clusterNode*Bit to use helper bitmap functions. --- src/cluster.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 905d943e..ff5cc3b9 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1328,31 +1328,47 @@ void clusterCron(void) { * Slots management * -------------------------------------------------------------------------- */ +/* Test bit 'pos' in a generic bitmap. Return 1 if the bit is zet, + * otherwise 0. */ +int bitmapTestBit(unsigned char *bitmap, int pos) { + off_t byte = pos/8; + int bit = pos&7; + return (bitmap[byte] & (1<slots[byte] & (1<slots[byte] |= 1<slots,slot); + bitmapSetBit(n->slots,slot); if (!old) n->numslots++; return old; } /* Clear the slot bit and return the old value. */ int clusterNodeClearSlotBit(clusterNode *n, int slot) { - off_t byte = slot/8; - int bit = slot&7; - int old = (n->slots[byte] & (1<slots[byte] &= ~(1<slots,slot); + bitmapClearBit(n->slots,slot); if (old) n->numslots--; return old; } /* Return the slot bit from the cluster node structure. */ int clusterNodeGetSlotBit(clusterNode *n, int slot) { - off_t byte = slot/8; - int bit = slot&7; - return (n->slots[byte] & (1<slots,slot); } /* Add the specified slot to the list of slots that node 'n' will