Fix possible use-after-free on client disconnect
[fio.git] / lib / ffz.h
CommitLineData
064c636d
JA
1#ifndef FIO_FFZ_H
2#define FIO_FFZ_H
3
0ce8b119 4static inline int __ffs(unsigned long word)
064c636d 5{
09174445 6 int r = 0;
064c636d 7
0ce8b119
JA
8#if BITS_PER_LONG == 64
9 if ((word & 0xffffffff) == 0) {
10 r += 32;
11 word >>= 32;
12 }
13#endif
064c636d
JA
14 if (!(word & 0xffff)) {
15 word >>= 16;
16 r += 16;
17 }
18 if (!(word & 0xff)) {
19 word >>= 8;
20 r += 8;
21 }
22 if (!(word & 0xf)) {
23 word >>= 4;
24 r += 4;
25 }
26 if (!(word & 3)) {
27 word >>= 2;
28 r += 2;
29 }
30 if (!(word & 1)) {
31 word >>= 1;
32 r += 1;
33 }
34
35 return r;
36}
37
0ce8b119 38static inline int ffz(unsigned long bitmask)
064c636d 39{
09174445 40 return __ffs(~bitmask);
064c636d
JA
41}
42
43#endif