diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 2f607ea2ac5..34e6c6cd54f 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -49,28 +49,26 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32, "parts of buffer state space need to equal 32"); -/* refcount related definitions */ -#define BUF_REFCOUNT_ONE 1 -#define BUF_REFCOUNT_MASK \ - ((1U << BUF_REFCOUNT_BITS) - 1) +#define BUF_REFCOUNT_SHIFT 0 +#define BUF_USAGECOUNT_SHIFT (BUF_REFCOUNT_SHIFT + BUF_REFCOUNT_BITS) +#define BUF_FLAG_SHIFT (BUF_USAGECOUNT_SHIFT + BUF_USAGECOUNT_BITS) + +/* mask generator */ +#define MASK(bits) ((1U << (bits)) - 1) +/* refcount related definitions */ +#define BUF_REFCOUNT_ONE 1U +#define BUF_REFCOUNT_MASK (MASK(BUF_REFCOUNT_BITS) << BUF_REFCOUNT_SHIFT) /* usage count related definitions */ -#define BUF_USAGECOUNT_SHIFT \ - BUF_REFCOUNT_BITS -#define BUF_USAGECOUNT_MASK \ - (((1U << BUF_USAGECOUNT_BITS) - 1) << (BUF_USAGECOUNT_SHIFT)) -#define BUF_USAGECOUNT_ONE \ - (1U << BUF_REFCOUNT_BITS) +#define BUF_USAGECOUNT_ONE (1U << BUF_USAGECOUNT_SHIFT) +#define BUF_USAGECOUNT_MASK (MASK(BUF_USAGECOUNT_BITS) << BUF_USAGECOUNT_SHIFT) /* flags related definitions */ -#define BUF_FLAG_SHIFT \ - (BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS) -#define BUF_FLAG_MASK \ - (((1U << BUF_FLAG_BITS) - 1) << BUF_FLAG_SHIFT) +#define BUF_FLAG_MASK (MASK(BUF_FLAG_BITS) << BUF_FLAG_SHIFT) /* Get refcount and usagecount from buffer state */ #define BUF_STATE_GET_REFCOUNT(state) \ - ((state) & BUF_REFCOUNT_MASK) + (((state) & BUF_REFCOUNT_MASK) >> BUF_REFCOUNT_SHIFT) #define BUF_STATE_GET_USAGECOUNT(state) \ (((state) & BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) @@ -81,8 +79,7 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32, * entry associated with the buffer's tag. */ -#define BUF_DEFINE_FLAG(flagno) \ - (1U << (BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + (flagno))) +#define BUF_DEFINE_FLAG(flagno) (1U << (BUF_FLAG_SHIFT + (flagno))) /* buffer header is locked */ #define BM_LOCKED BUF_DEFINE_FLAG( 0)