haiku/headers/compatibility/gnu/sched.h
Augustin Cavalier 90dca2bc8e headers: Change most remaining include guards to _DEFAULT_SOURCE.
We automatically enable _DEFAULT_SOURCE if _GNU_SOURCE is defined.
Rather than having even more optional methods undefined unless
_GNU_SOURCE manually is, just change all remaining guarts to
use _DEFAULT_SOURCE instead.

Fixes #19095.

Change-Id: I5c7baf40b7fb37913e24279589fc1ae706448a45
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8330
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-09-19 16:43:31 +00:00

67 lines
1.4 KiB
C

/*
* Copyright 2023 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _GNU_SCHED_H_
#define _GNU_SCHED_H_
#include_next <sched.h>
#include <features.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef _DEFAULT_SOURCE
#ifndef CPU_SETSIZE
#define CPU_SETSIZE 1024
#endif
typedef __haiku_uint32 cpuset_mask;
#ifndef _howmany
#define _howmany(x, y) (((x) + ((y) - 1)) / (y))
#endif
#define NCPUSETBITS (sizeof(cpuset_mask) * 8) /* bits per mask */
typedef struct _cpuset {
cpuset_mask bits[_howmany(CPU_SETSIZE, NCPUSETBITS)];
} cpuset_t;
#define _CPUSET_BITSINDEX(cpu) ((cpu) / NCPUSETBITS)
#define _CPUSET_BIT(cpu) (1L << ((cpu) % NCPUSETBITS))
/* FD_ZERO uses memset */
#include <string.h>
#define CPUSET_ZERO(set) memset((set), 0, sizeof(cpuset_t))
#define CPUSET_SET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] |= _CPUSET_BIT(cpu))
#define CPUSET_CLR(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] &= ~_CPUSET_BIT(cpu))
#define CPUSET_ISSET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] & _CPUSET_BIT(cpu))
#define CPUSET_COPY(source, target) (*(target) = *(source))
#ifdef __cplusplus
extern "C" {
#endif
extern int sched_getcpu(void);
extern int sched_setaffinity(pid_t id, size_t cpusetsize, const cpuset_t* mask);
extern int sched_getaffinity(pid_t id, size_t cpusetsize, cpuset_t* mask);
#ifdef __cplusplus
}
#endif
#endif
#endif /* _GNU_SCHED_H_ */