ck_bitmap: Drop _mpmc suffix and add union operation.

The _mpmc suffix is not useful. I see little benefit to specializing
the bitmap to begin with.
ck_pring
Samy Al Bahra 11 years ago
parent 1c8040968f
commit 190b204059

@ -80,11 +80,14 @@
#define CK_BITMAP_NEXT(a, b, c) \ #define CK_BITMAP_NEXT(a, b, c) \
ck_bitmap_next(&(a)->bitmap, (b), (c)) ck_bitmap_next(&(a)->bitmap, (b), (c))
#define CK_BITMAP_SET_MPMC(a, b) \ #define CK_BITMAP_SET(a, b) \
ck_bitmap_set_mpmc(&(a)->bitmap, (b)) ck_bitmap_set(&(a)->bitmap, (b))
#define CK_BITMAP_RESET_MPMC(a, b) \ #define CK_BITMAP_UNION(a, b) \
ck_bitmap_reset_mpmc(&(a)->bitmap, (b)) ck_bitmap_union(&(a)->bitmap, &(b)->bitmap)
#define CK_BITMAP_RESET(a, b) \
ck_bitmap_reset(&(a)->bitmap, (b))
#define CK_BITMAP_CLEAR(a) \ #define CK_BITMAP_CLEAR(a) \
ck_bitmap_clear(&(a)->bitmap) ck_bitmap_clear(&(a)->bitmap)
@ -137,7 +140,7 @@ ck_bitmap_size(unsigned int n_bits)
* Sets the bit at the offset specified in the second argument. * Sets the bit at the offset specified in the second argument.
*/ */
CK_CC_INLINE static void CK_CC_INLINE static void
ck_bitmap_set_mpmc(struct ck_bitmap *bitmap, unsigned int n) ck_bitmap_set(struct ck_bitmap *bitmap, unsigned int n)
{ {
CK_BITMAP_WORD mask = 0x1ULL << (n & CK_BITMAP_MASK); CK_BITMAP_WORD mask = 0x1ULL << (n & CK_BITMAP_MASK);
@ -145,11 +148,31 @@ ck_bitmap_set_mpmc(struct ck_bitmap *bitmap, unsigned int n)
return; return;
} }
/*
* Combines bits from second bitmap into the first bitmap. This is not a
* linearized operation with respect to the complete bitmap.
*/
CK_CC_INLINE static void
ck_bitmap_union(struct ck_bitmap *dst, struct ck_bitmap *src)
{
unsigned int n;
unsigned int n_buckets = dst->n_bits;
if (src->n_bits < dst->n_bits)
n_buckets = src->n_bits;
n_buckets /= sizeof(CK_BITMAP_WORD);
for (n = 0; n < n_buckets; n++)
CK_BITMAP_OR(&dst->map[n], src->map[n]);
return;
}
/* /*
* Resets the bit at the offset specified in the second argument. * Resets the bit at the offset specified in the second argument.
*/ */
CK_CC_INLINE static void CK_CC_INLINE static void
ck_bitmap_reset_mpmc(struct ck_bitmap *bitmap, unsigned int n) ck_bitmap_reset(struct ck_bitmap *bitmap, unsigned int n)
{ {
CK_BITMAP_WORD mask = ~(0x1ULL << (n & CK_BITMAP_MASK)); CK_BITMAP_WORD mask = ~(0x1ULL << (n & CK_BITMAP_MASK));

@ -73,6 +73,11 @@ static void
test(ck_bitmap_t *bits, unsigned int n_length, bool initial) test(ck_bitmap_t *bits, unsigned int n_length, bool initial)
{ {
unsigned int i; unsigned int i;
CK_BITMAP_INSTANCE(8) u;
CK_BITMAP_INIT(&u, 8, false);
CK_BITMAP_SET(&u, 1);
CK_BITMAP_SET(&u, 4);
for (i = 0; i < n_length; i++) { for (i = 0; i < n_length; i++) {
if (ck_bitmap_test(bits, i) == !initial) { if (ck_bitmap_test(bits, i) == !initial) {
@ -82,16 +87,16 @@ test(ck_bitmap_t *bits, unsigned int n_length, bool initial)
} }
for (i = 0; i < n_length; i++) { for (i = 0; i < n_length; i++) {
ck_bitmap_set_mpmc(bits, i); ck_bitmap_set(bits, i);
if (ck_bitmap_test(bits, i) == false) { if (ck_bitmap_test(bits, i) == false) {
ck_error("[1] ERROR: Expected bit to be set: %u\n", i); ck_error("[1] ERROR: Expected bit to be set: %u\n", i);
} }
ck_bitmap_reset_mpmc(bits, i); ck_bitmap_reset(bits, i);
if (ck_bitmap_test(bits, i) == true) { if (ck_bitmap_test(bits, i) == true) {
ck_error("[2] ERROR: Expected bit to be cleared: %u\n", i); ck_error("[2] ERROR: Expected bit to be cleared: %u\n", i);
} }
ck_bitmap_set_mpmc(bits, i); ck_bitmap_set(bits, i);
if (ck_bitmap_test(bits, i) == false) { if (ck_bitmap_test(bits, i) == false) {
ck_error("[3] ERROR: Expected bit to be set: %u\n", i); ck_error("[3] ERROR: Expected bit to be set: %u\n", i);
} }
@ -113,6 +118,12 @@ test(ck_bitmap_t *bits, unsigned int n_length, bool initial)
} }
} }
ck_bitmap_union(bits, CK_BITMAP(&u));
if (ck_bitmap_test(bits, 1) == false ||
ck_bitmap_test(bits, 4) == false) {
ck_error("ERROR: Expected union semantics.\n");
}
return; return;
} }
@ -156,15 +167,16 @@ main(int argc, char *argv[])
ck_error("ERROR: Expected bit to be reset.\n"); ck_error("ERROR: Expected bit to be reset.\n");
} }
CK_BITMAP_SET_MPMC(&sb, 1); CK_BITMAP_SET(&sb, 1);
if (CK_BITMAP_TEST(&sb, 1) == false) { if (CK_BITMAP_TEST(&sb, 1) == false) {
ck_error("ERROR: Expected bit to be set.\n"); ck_error("ERROR: Expected bit to be set.\n");
} }
CK_BITMAP_RESET_MPMC(&sb, 1); CK_BITMAP_RESET(&sb, 1);
if (CK_BITMAP_TEST(&sb, 1) == true) { if (CK_BITMAP_TEST(&sb, 1) == true) {
ck_error("ERROR: Expected bit to be reset.\n"); ck_error("ERROR: Expected bit to be reset.\n");
} }
return 0; return 0;
} }

Loading…
Cancel
Save