*/
typedef uint32 CHashPtr;
#define InvalidCHashPtr ((uint32) -2)
+#define CHashPtrIsInvalid(x) ((x) >= InvalidCHashPtr)
#define CHashPtrIsMarked(x) ((x) & 1)
#define CHashPtrGetOffset(x) ((x) >> 1)
#define CHashPtrMark(x) ((x) | 1)
(AssertMacro((offset) < (table)->arena_limit), \
(CHashNode *) ((table)->arena + (table)->arena_stride * (offset)))
#define CHashTableGetNode(table, ptr) \
- (AssertMacro((ptr) != InvalidCHashPtr), \
+ (AssertMacro(!CHashPtrIsInvalid(ptr)), \
CHashTableGetRaw((table), CHashPtrGetOffset((ptr))))
/*
* If we've reached the end of the bucket chain, stop; otherwise,
* figure out the actual address of the next item.
*/
- if (target == InvalidCHashPtr)
+ if (CHashPtrIsInvalid(target))
{
res->found = false;
break;
/* Try to pop a buffer from a freelist using compare-and-swap. */
b = &table->freelist[f_current];
new = *b;
- if (new != InvalidCHashPtr)
+ if (!CHashPtrIsInvalid(new))
{
CHashNode *n = CHashTableGetNode(table, new);
table->gc_next = (table->gc_next + 1) % table->ngarbage;
b = &table->garbage[table->gc_next];
garbage = *b;
- if (garbage != InvalidCHashPtr &&
+ if (!CHashPtrIsInvalid(garbage) &&
__sync_bool_compare_and_swap(b, garbage, InvalidCHashPtr))
{
uint64 chash_bucket;
fhead = n->un.gcnext;
/* Put any remaining elements back on the free list. */
- if (fhead != InvalidCHashPtr)
+ if (!CHashPtrIsInvalid(fhead))
{
CHashPtr fcurrent;
CHashPtr fnext;
{
n = CHashTableGetNode(table, fcurrent);
fnext = n->un.gcnext;
- if (fnext == InvalidCHashPtr)
+ if (CHashPtrIsInvalid(fnext))
break;
fcurrent = fnext;
}
* If we've reached the end of the bucket chain, stop; otherwise,
* figure out the actual address of the next item.
*/
- if (target == InvalidCHashPtr)
+ if (CHashPtrIsInvalid(target))
break;
target_node = CHashTableGetNode(table, target);