[newlib-cygwin] FreeBSD compatibility for RTEMS <sys/cpuset.h>
Jeff Johnston
jjohnstn@sourceware.org
Thu May 25 16:53:00 GMT 2017
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0b915d6be0acdbdb23ce35f12289f4d7ee4c0eb6
commit 0b915d6be0acdbdb23ce35f12289f4d7ee4c0eb6
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date: Mon May 22 07:39:55 2017 +0200
FreeBSD compatibility for RTEMS <sys/cpuset.h>
Make the RTEMS <sys/cpuset.h> compatible with the latest FreeBSD
version.
Fix the CPU_COPY() parameter order, see also:
https://devel.rtems.org/ticket/3023
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Diff:
---
newlib/libc/sys/rtems/include/sys/_bitset.h | 58 +++++++
newlib/libc/sys/rtems/include/sys/_cpuset.h | 47 ++++++
newlib/libc/sys/rtems/include/sys/bitset.h | 241 ++++++++++++++++++++++++++++
newlib/libc/sys/rtems/include/sys/cpuset.h | 194 +++++++---------------
4 files changed, 402 insertions(+), 138 deletions(-)
diff --git a/newlib/libc/sys/rtems/include/sys/_bitset.h b/newlib/libc/sys/rtems/include/sys/_bitset.h
new file mode 100644
index 0000000..8d8a4c2
--- /dev/null
+++ b/newlib/libc/sys/rtems/include/sys/_bitset.h
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008 Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/_bitset.h 299184 2016-05-06 16:41:23Z royger $
+ */
+
+#ifndef _SYS__BITSET_H_
+#define _SYS__BITSET_H_
+
+/*
+ * Macros addressing word and bit within it, tuned to make compiler
+ * optimize cases when SETSIZE fits into single machine word.
+ */
+#define _BITSET_BITS (sizeof(long) * 8)
+
+#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
+
+#define __bitset_words(_s) (__howmany(_s, _BITSET_BITS))
+
+#define BITSET_DEFINE(t, _s) \
+struct t { \
+ long __bits[__bitset_words((_s))]; \
+}
+
+/*
+ * Helper to declare a bitset without it's size being a constant.
+ *
+ * Sadly we cannot declare a bitset struct with '__bits[]', because it's
+ * the only member of the struct and the compiler complains.
+ */
+#define BITSET_DEFINE_VAR(t) BITSET_DEFINE(t, 1)
+
+#endif /* !_SYS__BITSET_H_ */
diff --git a/newlib/libc/sys/rtems/include/sys/_cpuset.h b/newlib/libc/sys/rtems/include/sys/_cpuset.h
new file mode 100644
index 0000000..dc4e61f
--- /dev/null
+++ b/newlib/libc/sys/rtems/include/sys/_cpuset.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008 Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/_cpuset.h 299122 2016-05-05 15:43:26Z jhb $
+ */
+
+#ifndef _SYS__CPUSET_H_
+#define _SYS__CPUSET_H_
+
+#include <sys/_bitset.h>
+#include <machine/param.h>
+
+#define CPU_MAXSIZE 256
+
+#ifndef CPU_SETSIZE
+#define CPU_SETSIZE MAXCPU
+#endif
+
+BITSET_DEFINE(_cpuset, CPU_SETSIZE);
+typedef struct _cpuset cpuset_t;
+
+#endif /* !_SYS__CPUSET_H_ */
diff --git a/newlib/libc/sys/rtems/include/sys/bitset.h b/newlib/libc/sys/rtems/include/sys/bitset.h
new file mode 100644
index 0000000..ac01b80
--- /dev/null
+++ b/newlib/libc/sys/rtems/include/sys/bitset.h
@@ -0,0 +1,241 @@
+/*-
+ * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008 Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: head/sys/sys/bitset.h 299184 2016-05-06 16:41:23Z royger $
+ */
+
+#ifndef _SYS_BITSET_H_
+#define _SYS_BITSET_H_
+
+#include <sys/_types.h>
+#include <machine/_bitcount.h>
+
+#define __bitset_mask(_s, n) \
+ (1L << ((__bitset_words((_s)) == 1) ? \
+ (__size_t)(n) : ((n) % _BITSET_BITS)))
+
+#define __bitset_word(_s, n) \
+ ((__bitset_words((_s)) == 1) ? 0 : ((n) / _BITSET_BITS))
+
+#define BIT_CLR(_s, n, p) \
+ ((p)->__bits[__bitset_word(_s, n)] &= ~__bitset_mask((_s), (n)))
+
+#define BIT_COPY(_s, f, t) (void)(*(t) = *(f))
+
+#define BIT_ISSET(_s, n, p) \
+ ((((p)->__bits[__bitset_word(_s, n)] & __bitset_mask((_s), (n))) != 0))
+
+#define BIT_SET(_s, n, p) \
+ ((p)->__bits[__bitset_word(_s, n)] |= __bitset_mask((_s), (n)))
+
+#define BIT_ZERO(_s, p) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (p)->__bits[__i] = 0L; \
+} while (0)
+
+#define BIT_FILL(_s, p) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (p)->__bits[__i] = -1L; \
+} while (0)
+
+#define BIT_SETOF(_s, n, p) do { \
+ BIT_ZERO(_s, p); \
+ (p)->__bits[__bitset_word(_s, n)] = __bitset_mask((_s), (n)); \
+} while (0)
+
+/* Is p empty. */
+#define BIT_EMPTY(_s, p) __extension__ ({ \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ if ((p)->__bits[__i]) \
+ break; \
+ __i == __bitset_words((_s)); \
+})
+
+/* Is p full set. */
+#define BIT_ISFULLSET(_s, p) __extension__ ({ \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ if ((p)->__bits[__i] != (long)-1) \
+ break; \
+ __i == __bitset_words((_s)); \
+})
+
+/* Is c a subset of p. */
+#define BIT_SUBSET(_s, p, c) __extension__ ({ \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ if (((c)->__bits[__i] & \
+ (p)->__bits[__i]) != \
+ (c)->__bits[__i]) \
+ break; \
+ __i == __bitset_words((_s)); \
+})
+
+/* Are there any common bits between b & c? */
+#define BIT_OVERLAP(_s, p, c) __extension__ ({ \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ if (((c)->__bits[__i] & \
+ (p)->__bits[__i]) != 0) \
+ break; \
+ __i != __bitset_words((_s)); \
+})
+
+/* Compare two sets, returns 0 if equal 1 otherwise. */
+#define BIT_CMP(_s, p, c) __extension__ ({ \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ if (((c)->__bits[__i] != \
+ (p)->__bits[__i])) \
+ break; \
+ __i != __bitset_words((_s)); \
+})
+
+#define BIT_OR(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] |= (s)->__bits[__i]; \
+} while (0)
+
+#define BIT_OR2(_s, d, s1, s2) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\
+} while (0)
+
+#define BIT_AND(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] &= (s)->__bits[__i]; \
+} while (0)
+
+#define BIT_AND2(_s, d, s1, s2) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] = (s1)->__bits[__i] & (s2)->__bits[__i];\
+} while (0)
+
+#define BIT_NAND(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] &= ~(s)->__bits[__i]; \
+} while (0)
+
+#define BIT_NAND2(_s, d, s1, s2) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] = (s1)->__bits[__i] & ~(s2)->__bits[__i];\
+} while (0)
+
+#define BIT_XOR(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] ^= (s)->__bits[__i]; \
+} while (0)
+
+#define BIT_XOR2(_s, d, s1, s2) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ (d)->__bits[__i] = (s1)->__bits[__i] ^ (s2)->__bits[__i];\
+} while (0)
+
+#define BIT_CLR_ATOMIC(_s, n, p) \
+ atomic_clear_long(&(p)->__bits[__bitset_word(_s, n)], \
+ __bitset_mask((_s), n))
+
+#define BIT_SET_ATOMIC(_s, n, p) \
+ atomic_set_long(&(p)->__bits[__bitset_word(_s, n)], \
+ __bitset_mask((_s), n))
+
+#define BIT_SET_ATOMIC_ACQ(_s, n, p) \
+ atomic_set_acq_long(&(p)->__bits[__bitset_word(_s, n)], \
+ __bitset_mask((_s), n))
+
+/* Convenience functions catering special cases. */
+#define BIT_AND_ATOMIC(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ atomic_clear_long(&(d)->__bits[__i], \
+ ~(s)->__bits[__i]); \
+} while (0)
+
+#define BIT_OR_ATOMIC(_s, d, s) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ atomic_set_long(&(d)->__bits[__i], \
+ (s)->__bits[__i]); \
+} while (0)
+
+#define BIT_COPY_STORE_REL(_s, f, t) do { \
+ __size_t __i; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ atomic_store_rel_long(&(t)->__bits[__i], \
+ (f)->__bits[__i]); \
+} while (0)
+
+#define BIT_FFS(_s, p) __extension__ ({ \
+ __size_t __i; \
+ int __bit; \
+ \
+ __bit = 0; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) { \
+ if ((p)->__bits[__i] != 0) { \
+ __bit = ffsl((p)->__bits[__i]); \
+ __bit += __i * _BITSET_BITS; \
+ break; \
+ } \
+ } \
+ __bit; \
+})
+
+#define BIT_COUNT(_s, p) __extension__ ({ \
+ __size_t __i; \
+ int __count; \
+ \
+ __count = 0; \
+ for (__i = 0; __i < __bitset_words((_s)); __i++) \
+ __count += __bitcountl((p)->__bits[__i]); \
+ __count; \
+})
+
+#define BITSET_T_INITIALIZER(x) \
+ { .__bits = { x } }
+
+#define BITSET_FSET(n) \
+ [ 0 ... ((n) - 1) ] = (-1L)
+
+/*
+ * Dynamically allocate a bitset.
+ */
+#define BITSET_ALLOC(_s, mt, mf) \
+ malloc(__bitset_words(_s) * sizeof(long), mt, (mf))
+
+#endif /* !_SYS_BITSET_H_ */
diff --git a/newlib/libc/sys/rtems/include/sys/cpuset.h b/newlib/libc/sys/rtems/include/sys/cpuset.h
index 8fae475..1e09b02 100644
--- a/newlib/libc/sys/rtems/include/sys/cpuset.h
+++ b/newlib/libc/sys/rtems/include/sys/cpuset.h
@@ -1,4 +1,10 @@
-/*
+/*-
+ * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
+ * All rights reserved.
+ *
+ * Copyright (c) 2008 Nokia Corporation
+ * All rights reserved.
+ *
* Copyright (c) 2013 On-Line Applications Research Corporation.
* All rights reserved.
*
@@ -11,7 +17,8 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
@@ -27,73 +34,53 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
-
-/*
- * This file implements an API compatible with static portion of
- * the GNU/Linux cpu_set_t macros but is independently implemented.
- * The GNU/Linux manual page and the FreeBSD cpuset_t implementation
- * were used as reference material.
*
- * Not implemented:
- * + Linux CPU_XXX_S
- * + FreeBSD CPU_SUBSET
- * + FreeBSD CPU_OVERLAP
+ * $FreeBSD: head/sys/sys/cpuset.h 317756 2017-05-03 18:41:08Z cem $
*/
-
#ifndef _SYS_CPUSET_H_
-#define _SYS_CPUSET_H_
+#define _SYS_CPUSET_H_
#include <sys/cdefs.h>
+#include <sys/_cpuset.h>
+#include <sys/bitset.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+#define _NCPUBITS _BITSET_BITS
+#define _NCPUWORDS __bitset_words(CPU_SETSIZE)
-/* RTEMS supports a maximum of 32 CPU cores */
-#ifndef CPU_SETSIZE
-#define CPU_SETSIZE 32
-#endif
+#define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS)
-/* word in the cpu set */
-typedef __uint32_t cpu_set_word_t;
+#define CPU_SETOF(n, p) BIT_SETOF(_cpu_set_bits(setsize), n, p)
+#define CPU_ISFULLSET(p) BIT_ISFULLSET(_cpu_set_bits(setsize), p)
+#define CPU_SUBSET(p, c) BIT_SUBSET(_cpu_set_bits(setsize), p, c)
+#define CPU_OVERLAP(p, c) BIT_OVERLAP(_cpu_set_bits(setsize), p, c)
+#define CPU_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(_cpu_set_bits(setsize), n, p)
+#define CPU_SET_ATOMIC(n, p) BIT_SET_ATOMIC(_cpu_set_bits(setsize), n, p)
+#define CPU_SET_ATOMIC_ACQ(n, p) BIT_SET_ATOMIC_ACQ(_cpu_set_bits(setsize), n, p)
+#define CPU_AND_ATOMIC(n, p) BIT_AND_ATOMIC(_cpu_set_bits(setsize), n, p)
+#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(_cpu_set_bits(setsize), d, s)
+#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(_cpu_set_bits(setsize), f, t)
+#define CPU_FFS(p) BIT_FFS(_cpu_set_bits(setsize), p)
+#define CPUSET_FSET BITSET_FSET(_NCPUWORDS)
+#define CPUSET_T_INITIALIZER BITSET_T_INITIALIZER
-/* Number of bits per cpu_set_t element */
-#define _NCPUBITS (sizeof(cpu_set_word_t) * 8)
+typedef cpuset_t cpu_set_t;
-/* Number of words in the cpu_set_t array */
-#define _NCPUWORDS (((CPU_SETSIZE)+((_NCPUBITS)-1))/(_NCPUBITS))
+#define _cpu_set_bits(_setsize) (8 * (_setsize))
-/* Define the cpu set structure */
-typedef struct _cpuset {
- cpu_set_word_t __bits[_NCPUWORDS];
-} cpu_set_t;
+#define CPU_ALLOC_SIZE(_num_cpus) (sizeof(long) * __bitset_words(_num_cpus))
-/* determine the mask for a particular cpu within the element */
-static __inline cpu_set_word_t __cpuset_mask(int cpu)
-{
- return (cpu_set_word_t)1 << ((size_t)cpu % _NCPUBITS);
-}
-
-/* determine the index for this cpu within the cpu set array */
-static __inline size_t __cpuset_index(int cpu)
-{
- return (size_t)cpu / _NCPUBITS;
-}
-
-#define CPU_ALLOC_SIZE(_num_cpus) \
- (sizeof(cpu_set_word_t) * (((_num_cpus) + _NCPUBITS - 1) / _NCPUBITS))
+__BEGIN_DECLS
cpu_set_t *__cpuset_alloc(int num_cpus);
+void __cpuset_free(cpu_set_t *set);
+
static __inline cpu_set_t *CPU_ALLOC(int num_cpus)
{
return __cpuset_alloc(num_cpus);
}
-void __cpuset_free(cpu_set_t *set);
-
static __inline void CPU_FREE(cpu_set_t *set)
{
__cpuset_free(set);
@@ -101,12 +88,7 @@ static __inline void CPU_FREE(cpu_set_t *set)
static __inline void CPU_ZERO_S(size_t setsize, cpu_set_t *set)
{
- cpu_set_word_t *w = &set->__bits[0];
- size_t n = setsize / sizeof(*w);
- size_t i;
-
- for (i = 0; i < n; ++i)
- w[i] = 0;
+ BIT_ZERO(_cpu_set_bits(setsize), set);
}
static __inline void CPU_ZERO(cpu_set_t *set)
@@ -116,12 +98,7 @@ static __inline void CPU_ZERO(cpu_set_t *set)
static __inline void CPU_FILL_S(size_t setsize, cpu_set_t *set)
{
- cpu_set_word_t *w = &set->__bits[0];
- size_t n = setsize / sizeof(*w);
- size_t i;
-
- for (i = 0; i < n; ++i)
- w[i] = ~(cpu_set_word_t)0;
+ BIT_FILL(_cpu_set_bits(setsize), set);
}
static __inline void CPU_FILL(cpu_set_t *set)
@@ -131,9 +108,7 @@ static __inline void CPU_FILL(cpu_set_t *set)
static __inline void CPU_SET_S(int cpu, size_t setsize, cpu_set_t *set)
{
- cpu_set_word_t *w = &set->__bits[0];
-
- w[__cpuset_index(cpu)] |= __cpuset_mask(cpu);
+ BIT_SET(_cpu_set_bits(setsize), cpu, set);
}
static __inline void CPU_SET(int cpu, cpu_set_t *set)
@@ -143,9 +118,7 @@ static __inline void CPU_SET(int cpu, cpu_set_t *set)
static __inline void CPU_CLR_S(int cpu, size_t setsize, cpu_set_t *set)
{
- cpu_set_word_t *w = &set->__bits[0];
-
- w[__cpuset_index(cpu)] &= ~__cpuset_mask(cpu);
+ BIT_CLR(_cpu_set_bits(setsize), cpu, set);
}
static __inline void CPU_CLR(int cpu, cpu_set_t *set)
@@ -155,9 +128,7 @@ static __inline void CPU_CLR(int cpu, cpu_set_t *set)
static __inline int CPU_ISSET_S(int cpu, size_t setsize, const cpu_set_t *set)
{
- const cpu_set_word_t *w = &set->__bits[0];
-
- return ((w[__cpuset_index(cpu)] & __cpuset_mask(cpu)) != 0);
+ return BIT_ISSET(_cpu_set_bits(setsize), cpu, set);
}
static __inline int CPU_ISSET(int cpu, const cpu_set_t *set)
@@ -165,23 +136,15 @@ static __inline int CPU_ISSET(int cpu, const cpu_set_t *set)
return CPU_ISSET_S(cpu, sizeof(*set), set);
}
-/* copy src set to dest set */
-static __inline void CPU_COPY( cpu_set_t *dest, const cpu_set_t *src )
+static __inline void CPU_COPY(const cpu_set_t *src, cpu_set_t *dest)
{
- *dest = *src;
+ BIT_COPY(_cpu_set_bits(setsize), src, dest);
}
static __inline void CPU_AND_S(size_t setsize, cpu_set_t *destset,
const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
- cpu_set_word_t *wdest = &destset->__bits[0];
- const cpu_set_word_t *wsrc1 = &srcset1->__bits[0];
- const cpu_set_word_t *wsrc2 = &srcset2->__bits[0];
- size_t n = setsize / sizeof(*wdest);
- size_t i;
-
- for (i = 0; i < n; ++i)
- wdest[i] = wsrc1[i] & wsrc2[i];
+ BIT_AND2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}
static __inline void CPU_AND(cpu_set_t *destset, const cpu_set_t *srcset1,
@@ -193,14 +156,7 @@ static __inline void CPU_AND(cpu_set_t *destset, const cpu_set_t *srcset1,
static __inline void CPU_OR_S(size_t setsize, cpu_set_t *destset,
const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
- cpu_set_word_t *wdest = &destset->__bits[0];
- const cpu_set_word_t *wsrc1 = &srcset1->__bits[0];
- const cpu_set_word_t *wsrc2 = &srcset2->__bits[0];
- size_t n = setsize / sizeof(*wdest);
- size_t i;
-
- for (i = 0; i < n; ++i)
- wdest[i] = wsrc1[i] | wsrc2[i];
+ BIT_OR2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}
static __inline void CPU_OR(cpu_set_t *destset, const cpu_set_t *srcset1,
@@ -212,14 +168,7 @@ static __inline void CPU_OR(cpu_set_t *destset, const cpu_set_t *srcset1,
static __inline void CPU_XOR_S(size_t setsize, cpu_set_t *destset,
const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
- cpu_set_word_t *wdest = &destset->__bits[0];
- const cpu_set_word_t *wsrc1 = &srcset1->__bits[0];
- const cpu_set_word_t *wsrc2 = &srcset2->__bits[0];
- size_t n = setsize / sizeof(*wdest);
- size_t i;
-
- for (i = 0; i < n; ++i)
- wdest[i] = wsrc1[i] ^ wsrc2[i];
+ BIT_XOR2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}
static __inline void CPU_XOR(cpu_set_t *destset, const cpu_set_t *srcset1,
@@ -231,14 +180,7 @@ static __inline void CPU_XOR(cpu_set_t *destset, const cpu_set_t *srcset1,
static __inline void CPU_NAND_S(size_t setsize, cpu_set_t *destset,
const cpu_set_t *srcset1, const cpu_set_t *srcset2)
{
- cpu_set_word_t *wdest = &destset->__bits[0];
- const cpu_set_word_t *wsrc1 = &srcset1->__bits[0];
- const cpu_set_word_t *wsrc2 = &srcset2->__bits[0];
- size_t n = setsize / sizeof(*wdest);
- size_t i;
-
- for (i = 0; i < n; ++i)
- wdest[i] = ~(wsrc1[i] & wsrc2[i]);
+ BIT_NAND2(_cpu_set_bits(setsize), destset, srcset1, srcset2);
}
static __inline void CPU_NAND(cpu_set_t *destset, const cpu_set_t *srcset1,
@@ -249,17 +191,7 @@ static __inline void CPU_NAND(cpu_set_t *destset, const cpu_set_t *srcset1,
static __inline int CPU_COUNT_S(size_t setsize, const cpu_set_t *set)
{
- int count = 0;
- const cpu_set_word_t *w = &set->__bits[0];
- size_t n = setsize / sizeof(*w);
- size_t i;
- int cpu;
-
- for (i = 0; i < n; ++i)
- for (cpu = 0; cpu < (int)_NCPUBITS; ++cpu)
- count += (w[i] & __cpuset_mask(cpu)) != 0;
-
- return count;
+ return BIT_COUNT(_cpu_set_bits(setsize), set);
}
static __inline int CPU_COUNT(const cpu_set_t *set)
@@ -270,16 +202,7 @@ static __inline int CPU_COUNT(const cpu_set_t *set)
static __inline int CPU_EQUAL_S(size_t setsize, const cpu_set_t *set1,
const cpu_set_t *set2)
{
- const cpu_set_word_t *w1 = &set1->__bits[0];
- const cpu_set_word_t *w2 = &set2->__bits[0];
- size_t n = setsize / sizeof(*w1);
- size_t i;
-
- for (i = 0; i < n; ++i)
- if (w1[i] != w2[i])
- return 0;
-
- return 1;
+ return BIT_CMP(_cpu_set_bits(setsize), set1, set2);
}
static __inline int CPU_EQUAL(const cpu_set_t *set1, const cpu_set_t *set2)
@@ -287,25 +210,20 @@ static __inline int CPU_EQUAL(const cpu_set_t *set1, const cpu_set_t *set2)
return CPU_EQUAL_S(sizeof(*set1), set1, set2);
}
-/* return 1 if the sets set1 and set2 are equal, otherwise return 0 */
-static __inline int CPU_CMP( const cpu_set_t *set1, const cpu_set_t *set2 )
+static __inline int CPU_CMP(const cpu_set_t *set1, const cpu_set_t *set2)
{
return CPU_EQUAL(set1, set2);
}
-/* return 1 if the set is empty, otherwise return 0 */
-static __inline int CPU_EMPTY( const cpu_set_t *set )
+static __inline int CPU_EMPTY(const cpu_set_t *set)
{
- size_t i;
-
- for (i=0; i < _NCPUWORDS; i++)
- if (set->__bits[i] != 0 )
- return 0;
- return 1;
+ return BIT_EMPTY(_cpu_set_bits(sizeof(*set)), set);
}
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+__END_DECLS
+#ifdef _KERNEL
+/* Header file provided outside of Newlib */
+#include <machine/_kernel_cpuset.h>
#endif
+#endif /* !_SYS_CPUSET_H_ */
More information about the Newlib-cvs
mailing list