diff options
Diffstat (limited to 'database/engine/rrdenginelib.h')
-rw-r--r-- | database/engine/rrdenginelib.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/database/engine/rrdenginelib.h b/database/engine/rrdenginelib.h index 1184358f63..ebab93c8fe 100644 --- a/database/engine/rrdenginelib.h +++ b/database/engine/rrdenginelib.h @@ -36,6 +36,34 @@ typedef uintptr_t rrdeng_stats_t; #define rrd_stat_atomic_add(p, n) rrd_atomic_fetch_add(p, n) +/* returns -1 if it didn't find the first cleared bit, the position otherwise. Starts from LSB. */ +static inline int find_first_zero(unsigned x) +{ + return ffs((int)(~x)) - 1; +} + +/* Starts from LSB. */ +static inline uint8_t check_bit(unsigned x, size_t pos) +{ + return !!(x & (1 << pos)); +} + +/* Starts from LSB. val is 0 or 1 */ +static inline void modify_bit(unsigned *x, unsigned pos, uint8_t val) +{ + switch(val) { + case 0: + *x &= ~(1U << pos); + break; + case 1: + *x |= 1U << pos; + break; + default: + error("modify_bit() called with invalid argument."); + break; + } +} + #define RRDENG_PATH_MAX (4096) /* returns old *ptr value */ |