lib: remove librte_ prefix from directory names
[dpdk.git] / lib / eal / windows / include / sched.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #ifndef _SCHED_H_
6 #define _SCHED_H_
7
8 /**
9  * This file is added to support the common code in eal_common_thread.c
10  * as Microsoft libc does not contain sched.h. This may be removed
11  * in future releases.
12  */
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #ifndef CPU_SETSIZE
18 #define CPU_SETSIZE RTE_MAX_LCORE
19 #endif
20
21 #define _BITS_PER_SET (sizeof(long long) * 8)
22 #define _BIT_SET_MASK (_BITS_PER_SET - 1)
23
24 #define _NUM_SETS(b) (((b) + _BIT_SET_MASK) / _BITS_PER_SET)
25 #define _WHICH_SET(b) ((b) / _BITS_PER_SET)
26 #define _WHICH_BIT(b) ((b) & (_BITS_PER_SET - 1))
27
28 typedef struct _rte_cpuset_s {
29         long long _bits[_NUM_SETS(CPU_SETSIZE)];
30 } rte_cpuset_t;
31 #define RTE_HAS_CPUSET
32
33 #define CPU_SET(b, s) ((s)->_bits[_WHICH_SET(b)] |= (1LL << _WHICH_BIT(b)))
34
35 #define CPU_ZERO(s)                                                     \
36         do {                                                            \
37                 unsigned int _i;                                        \
38                                                                         \
39                 for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++)         \
40                         (s)->_bits[_i] = 0LL;                           \
41         } while (0)
42
43 #define CPU_ISSET(b, s) (((s)->_bits[_WHICH_SET(b)] & \
44         (1LL << _WHICH_BIT(b))) != 0LL)
45
46 static inline int
47 count_cpu(rte_cpuset_t *s)
48 {
49         unsigned int _i;
50         int count = 0;
51
52         for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++)
53                 if (CPU_ISSET(_i, s) != 0LL)
54                         count++;
55         return count;
56 }
57 #define CPU_COUNT(s) count_cpu(s)
58
59 #define CPU_AND(dst, src1, src2) \
60 do { \
61         unsigned int _i; \
62         \
63         for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++) \
64                 (dst)->_bits[_i] = (src1)->_bits[_i] & (src2)->_bits[_i]; \
65 } while (0)
66
67 #define CPU_OR(dst, src1, src2) \
68 do { \
69         unsigned int _i; \
70         \
71         for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++) \
72                 (dst)->_bits[_i] = (src1)->_bits[_i] | (src2)->_bits[_i]; \
73 } while (0)
74
75 #define CPU_FILL(s) \
76 do { \
77         unsigned int _i; \
78         for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++) \
79                 (s)->_bits[_i] = -1LL; \
80 } while (0)
81
82 #define CPU_NOT(dst, src) \
83 do { \
84         unsigned int _i; \
85         for (_i = 0; _i < _NUM_SETS(CPU_SETSIZE); _i++) \
86                 (dst)->_bits[_i] = (src)->_bits[_i] ^ -1LL; \
87 } while (0)
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* _SCHED_H_ */