]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add a new function atleast2() to test masks for more than 1 bit
authorWilly Tarreau <w@1wt.eu>
Mon, 15 Oct 2018 07:33:41 +0000 (09:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 15 Oct 2018 11:25:06 +0000 (13:25 +0200)
For threads it's common to have to check if a mask contains more than
one bit set. Let's have this "atleast2()" function report this.

include/common/standard.h

index fabe97276bba2d8a8f25cdba6eb398f3a23832db..3e13f301c3bc003abe52a369c8ae6a78e71cdc0d 100644 (file)
@@ -801,6 +801,12 @@ static inline unsigned int my_popcountl(unsigned long a)
        return cnt;
 }
 
+/* returns non-zero if <a> has at least 2 bits set */
+static inline unsigned long atleast2(unsigned long a)
+{
+       return a & (a - 1);
+}
+
 /* Simple ffs implementation. It returns the position of the lowest bit set to
  * one. It is illegal to call it with a==0 (undefined result).
  */