sched.h 899 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _ASM_GENERIC_BITOPS_SCHED_H_
  2. #define _ASM_GENERIC_BITOPS_SCHED_H_
  3. #include <linux/compiler.h> /* unlikely() */
  4. #include <asm/types.h>
  5. /*
  6. * Every architecture must define this function. It's the fastest
  7. * way of searching a 140-bit bitmap where the first 100 bits are
  8. * unlikely to be set. It's guaranteed that at least one of the 140
  9. * bits is cleared.
  10. */
  11. static inline int sched_find_first_bit(const unsigned long *b)
  12. {
  13. #if BITS_PER_LONG == 64
  14. if (unlikely(b[0]))
  15. return __ffs(b[0]);
  16. if (unlikely(b[1]))
  17. return __ffs(b[1]) + 64;
  18. return __ffs(b[2]) + 128;
  19. #elif BITS_PER_LONG == 32
  20. if (unlikely(b[0]))
  21. return __ffs(b[0]);
  22. if (unlikely(b[1]))
  23. return __ffs(b[1]) + 32;
  24. if (unlikely(b[2]))
  25. return __ffs(b[2]) + 64;
  26. if (b[3])
  27. return __ffs(b[3]) + 96;
  28. return __ffs(b[4]) + 128;
  29. #else
  30. #error BITS_PER_LONG not defined
  31. #endif
  32. }
  33. #endif /* _ASM_GENERIC_BITOPS_SCHED_H_ */