cpu-set-sched.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: LGPL-2.1
  2. // Definitions taken from glibc for use with older systems, same licensing.
  3. #ifndef _CPU_SET_SCHED_PERF_H
  4. #define _CPU_SET_SCHED_PERF_H
  5. #include <features.h>
  6. #include <sched.h>
  7. #ifndef CPU_EQUAL
  8. #ifndef __CPU_EQUAL_S
  9. #if __GNUC_PREREQ (2, 91)
  10. # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
  11. (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
  12. #else
  13. # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
  14. (__extension__ \
  15. ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
  16. const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
  17. size_t __imax = (setsize) / sizeof (__cpu_mask); \
  18. size_t __i; \
  19. for (__i = 0; __i < __imax; ++__i) \
  20. if (__arr1[__i] != __arr2[__i]) \
  21. break; \
  22. __i == __imax; }))
  23. #endif
  24. #endif // __CPU_EQUAL_S
  25. #define CPU_EQUAL(cpusetp1, cpusetp2) \
  26. __CPU_EQUAL_S (sizeof (cpu_set_t), cpusetp1, cpusetp2)
  27. #endif // CPU_EQUAL
  28. #ifndef CPU_OR
  29. #ifndef __CPU_OP_S
  30. #define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
  31. (__extension__ \
  32. ({ cpu_set_t *__dest = (destset); \
  33. const __cpu_mask *__arr1 = (srcset1)->__bits; \
  34. const __cpu_mask *__arr2 = (srcset2)->__bits; \
  35. size_t __imax = (setsize) / sizeof (__cpu_mask); \
  36. size_t __i; \
  37. for (__i = 0; __i < __imax; ++__i) \
  38. ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
  39. __dest; }))
  40. #endif // __CPU_OP_S
  41. #define CPU_OR(destset, srcset1, srcset2) \
  42. __CPU_OP_S (sizeof (cpu_set_t), destset, srcset1, srcset2, |)
  43. #endif // CPU_OR
  44. #endif // _CPU_SET_SCHED_PERF_H