Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
5f8fd27a
Commit
5f8fd27a
authored
Feb 28, 2013
by
antirez
Browse files
Cluster: refactoring of clusterNode*Bit to use helper bitmap functions.
parent
d21d6b66
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
5f8fd27a
...
@@ -1328,31 +1328,47 @@ void clusterCron(void) {
...
@@ -1328,31 +1328,47 @@ void clusterCron(void) {
* Slots management
* 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<<bit)) != 0;
}
/* Set the bit at position 'pos' in a bitmap. */
void bitmapSetBit(unsigned char *bitmap, int pos) {
off_t byte = pos/8;
int bit = pos&7;
bitmap[byte] |= 1<<bit;
}
/* Clear the bit at position 'pos' in a bitmap. */
void bitmapClearBit(unsigned char *bitmap, int pos) {
off_t byte = pos/8;
int bit = pos&7;
bitmap[byte] &= ~(1<<bit);
}
/* Set the slot bit and return the old value. */
/* Set the slot bit and return the old value. */
int clusterNodeSetSlotBit(clusterNode *n, int slot) {
int clusterNodeSetSlotBit(clusterNode *n, int slot) {
off_t
byte
=
slot
/
8
;
int old = bitmapTestBit(n->slots,slot);
int
bit
=
slot
&
7
;
bitmapSetBit(n->slots,slot);
int
old
=
(
n
->
slots
[
byte
]
&
(
1
<<
bit
))
!=
0
;
n
->
slots
[
byte
]
|=
1
<<
bit
;
if (!old) n->numslots++;
if (!old) n->numslots++;
return old;
return old;
}
}
/* Clear the slot bit and return the old value. */
/* Clear the slot bit and return the old value. */
int clusterNodeClearSlotBit(clusterNode *n, int slot) {
int clusterNodeClearSlotBit(clusterNode *n, int slot) {
off_t
byte
=
slot
/
8
;
int old = bitmapTestBit(n->slots,slot);
int
bit
=
slot
&
7
;
bitmapClearBit(n->slots,slot);
int
old
=
(
n
->
slots
[
byte
]
&
(
1
<<
bit
))
!=
0
;
n
->
slots
[
byte
]
&=
~
(
1
<<
bit
);
if (old) n->numslots--;
if (old) n->numslots--;
return old;
return old;
}
}
/* Return the slot bit from the cluster node structure. */
/* Return the slot bit from the cluster node structure. */
int clusterNodeGetSlotBit(clusterNode *n, int slot) {
int clusterNodeGetSlotBit(clusterNode *n, int slot) {
off_t
byte
=
slot
/
8
;
return bitmapTestBit(n->slots,slot);
int
bit
=
slot
&
7
;
return
(
n
->
slots
[
byte
]
&
(
1
<<
bit
))
!=
0
;
}
}
/* Add the specified slot to the list of slots that node 'n' will
/* Add the specified slot to the list of slots that node 'n' will
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment