2022-09-06 14:04:13 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_
|
|
|
|
|
|
|
|
#define CPU_SETSIZE 1024
|
|
|
|
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
typedef struct cpu_set_t {
|
|
|
|
uint64_t __bits[16];
|
|
|
|
} cpu_set_t;
|
|
|
|
|
|
|
|
int sched_getcpu(void);
|
|
|
|
int sched_getaffinity(int, size_t, cpu_set_t *);
|
|
|
|
int sched_setaffinity(int, size_t, const cpu_set_t *);
|
|
|
|
|
|
|
|
#define CPU_SET(i, s) ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
|
|
|
|
#define CPU_CLR(i, s) ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
|
|
|
|
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))
|
|
|
|
void CPU_ZERO(cpu_set_t *);
|
|
|
|
int CPU_COUNT(cpu_set_t *);
|
|
|
|
int CPU_EQUAL(cpu_set_t *, cpu_set_t *);
|
|
|
|
void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *);
|
|
|
|
void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *);
|
|
|
|
void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *);
|
|
|
|
|
2023-11-18 16:08:15 +00:00
|
|
|
#define CPU_ALLOC_SIZE(n) \
|
|
|
|
((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))
|
|
|
|
#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
|
|
|
|
#define CPU_FREE(set) free(set)
|
|
|
|
#define CPU_ZERO_S(size, set) memset(set, 0, size)
|
|
|
|
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
|
|
|
|
#define _CPU_S(i, size, set, op) \
|
|
|
|
((i) / 8U >= (size) ? 0 \
|
|
|
|
: (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
|
|
|
|
1UL << ((i) % (8 * sizeof(long))))))
|
|
|
|
#define CPU_SET_S(i, size, set) _CPU_S(i, size, set, |=)
|
|
|
|
#define CPU_CLR_S(i, size, set) _CPU_S(i, size, set, &= ~)
|
|
|
|
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)
|
|
|
|
|
2022-09-06 14:04:13 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_ */
|