diff --git a/core/include/arch/thread_arch.h b/core/include/arch/thread_arch.h index 10507a073..264d9f5ba 100644 --- a/core/include/arch/thread_arch.h +++ b/core/include/arch/thread_arch.h @@ -19,7 +19,7 @@ #ifndef THREAD_ARCH_H #define THREAD_ARCH_H -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/core/include/clist.h b/core/include/clist.h index b5442f746..8ab57e034 100644 --- a/core/include/clist.h +++ b/core/include/clist.h @@ -19,7 +19,7 @@ #ifndef CLIST_H #define CLIST_H -#include "kernel_macros.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/core/include/attributes.h b/core/include/kernel_defines.h similarity index 56% rename from core/include/attributes.h rename to core/include/kernel_defines.h index 1de1cd231..7b19d138f 100644 --- a/core/include/attributes.h +++ b/core/include/kernel_defines.h @@ -11,13 +11,13 @@ * @{ * * @file - * @brief Compiler attributes/pragmas configuration + * @brief Common macros and compiler attributes/pragmas configuration * * @author René Kijewski */ -#ifndef ATTRIBUTES_H_ -#define ATTRIBUTES_H_ +#ifndef KERNEL_DEFINES_H_ +#define KERNEL_DEFINES_H_ #include @@ -25,6 +25,38 @@ extern "C" { #endif +/** + * @def container_of(PTR, TYPE, MEMBER) + * @brief Returns the container of a pointer to a member. + * @details For a struct `TYPE` with a member `MEMBER`, + * given a pointer `PTR` to `TYPE::MEMBER` this function returns a pointer + * to the instance of `TYPE`. + * @details E.g. for `struct my_struct_t { ...; something_t n; ... } my_struct;`, + * `&my_struct == container_of(&my_struct.n, struct my_struct_t, n)`. + * @param[in] PTR pointer to a member + * @param[in] TYPE a type name (a struct or union), container of PTR + * @param[in] MEMBER name of the member of TYPE which PTR points to + * @return Pointer to the container of PTR. + */ +#if __STDC_VERSION__ >= 201112L +# define container_of(PTR, TYPE, MEMBER) \ + (_Generic((PTR), \ + const __typeof__ (((TYPE *) 0)->MEMBER) *: \ + ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))), \ + __typeof__ (((TYPE *) 0)->MEMBER) *: \ + ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) \ + )) +#elif defined __GNUC__ +# define container_of(PTR, TYPE, MEMBER) \ + (__extension__ ({ \ + __extension__ const __typeof__ (((TYPE *) 0)->MEMBER) *__m____ = (PTR); \ + ((TYPE *) ((char *) __m____ - offsetof(TYPE, MEMBER))); \ + })) +#else +# define container_of(PTR, TYPE, MEMBER) \ + ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) +#endif + /** * @def NORETURN * @brief The *NORETURN* keyword tells the compiler to assume that the function @@ -86,5 +118,5 @@ } #endif -#endif /* ATTRIBUTES_H_ */ +#endif /* KERNEL_DEFINES_H_ */ /** @} */ diff --git a/core/include/kernel_macros.h b/core/include/kernel_macros.h deleted file mode 100644 index b04c331e1..000000000 --- a/core/include/kernel_macros.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup core_util - * @{ - * - * @file - * @brief common macros - * - * @author René Kijewski - */ - -#ifndef KERNEL_MACROS_H -#define KERNEL_MACROS_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @def container_of(PTR, TYPE, MEMBER) - * @brief Returns the container of a pointer to a member. - * @details For a struct `TYPE` with a member `MEMBER`, - * given a pointer `PTR` to `TYPE::MEMBER` this function returns a pointer - * to the instance of `TYPE`. - * @details E.g. for `struct my_struct_t { ...; something_t n; ... } my_struct;`, - * `&my_struct == container_of(&my_struct.n, struct my_struct_t, n)`. - * @param[in] PTR pointer to a member - * @param[in] TYPE a type name (a struct or union), container of PTR - * @param[in] MEMBER name of the member of TYPE which PTR points to - * @return Pointer to the container of PTR. - */ -#if __STDC_VERSION__ >= 201112L -# define container_of(PTR, TYPE, MEMBER) \ - (_Generic((PTR), \ - const __typeof__ (((TYPE *) 0)->MEMBER) *: \ - ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))), \ - __typeof__ (((TYPE *) 0)->MEMBER) *: \ - ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) \ - )) -#elif defined __GNUC__ -# define container_of(PTR, TYPE, MEMBER) \ - (__extension__ ({ \ - __extension__ const __typeof__ (((TYPE *) 0)->MEMBER) *__m____ = (PTR); \ - ((TYPE *) ((char *) __m____ - offsetof(TYPE, MEMBER))); \ - })) -#else -# define container_of(PTR, TYPE, MEMBER) \ - ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* KERNEL_MACROS_H */ -/** - * @} - */ diff --git a/core/include/panic.h b/core/include/panic.h index aa3658fa6..d0f6050ca 100644 --- a/core/include/panic.h +++ b/core/include/panic.h @@ -22,7 +22,7 @@ #ifndef PANIC_H #define PANIC_H -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/core/include/sched.h b/core/include/sched.h index cf7a30104..d3582bf9b 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -81,9 +81,8 @@ #define SCHEDULER_H #include -#include "attributes.h" +#include "kernel_defines.h" #include "bitarithm.h" -#include "attributes.h" #include "kernel_types.h" #include "native_sched.h" #include "clist.h" diff --git a/core/panic.c b/core/panic.c index 86dc50283..4a998cabf 100644 --- a/core/panic.c +++ b/core/panic.c @@ -25,7 +25,7 @@ #include #include "assert.h" -#include "attributes.h" +#include "kernel_defines.h" #include "cpu.h" #include "irq.h" #include "lpm.h" diff --git a/cpu/x86/include/cpu.h b/cpu/x86/include/cpu.h index b6adf77ff..5c8119a34 100644 --- a/cpu/x86/include/cpu.h +++ b/cpu/x86/include/cpu.h @@ -29,7 +29,7 @@ #ifndef CPU_X86_CPU_H_ #define CPU_X86_CPU_H_ -#include "attributes.h" +#include "kernel_defines.h" #include "irq.h" #include "ucontext.h" #include "cpu_conf.h" diff --git a/cpu/x86/include/x86_reboot.h b/cpu/x86/include/x86_reboot.h index 824e9a6af..e39981f2d 100644 --- a/cpu/x86/include/x86_reboot.h +++ b/cpu/x86/include/x86_reboot.h @@ -29,7 +29,7 @@ #define CPU__X86__REBOOT__H__ #include -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/cpu/x86/x86_glue.c b/cpu/x86/x86_glue.c index cb835c9b9..b7cc3dc42 100644 --- a/cpu/x86/x86_glue.c +++ b/cpu/x86/x86_glue.c @@ -28,7 +28,7 @@ * @} */ -#include "attributes.h" +#include "kernel_defines.h" #include "cpu.h" #include "sched.h" #include "x86_uart.h" diff --git a/cpu/x86/x86_interrupts.c b/cpu/x86/x86_interrupts.c index 87e789f3e..ae3aaa5ce 100644 --- a/cpu/x86/x86_interrupts.c +++ b/cpu/x86/x86_interrupts.c @@ -28,20 +28,21 @@ * @} */ +#include +#include + +#include "kernel_defines.h" +#include "cpu.h" +#include "sched.h" +#include "thread.h" +#include "ucontext.h" + #include "x86_interrupts.h" #include "x86_memory.h" #include "x86_ports.h" #include "x86_registers.h" #include "x86_threading.h" -#include -#include -#include -#include -#include - -#include -#include #define ASM_FUN_ATTRIBUTES \ __attribute__((noinline)) \ diff --git a/sys/include/net/gnrc/ipv6/netif.h b/sys/include/net/gnrc/ipv6/netif.h index 637a563dd..d336d5334 100644 --- a/sys/include/net/gnrc/ipv6/netif.h +++ b/sys/include/net/gnrc/ipv6/netif.h @@ -25,7 +25,7 @@ #include #include -#include "kernel_macros.h" +#include "kernel_defines.h" #include "kernel_types.h" #include "mutex.h" #include "net/ipv6.h" diff --git a/sys/include/shell.h b/sys/include/shell.h index 301dd46d6..5b953ac6a 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -22,7 +22,7 @@ #include -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/sys/include/tm.h b/sys/include/tm.h index 29c950a2c..e8e9cc6db 100644 --- a/sys/include/tm.h +++ b/sys/include/tm.h @@ -21,7 +21,7 @@ #include #include -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/sys/posix/pthread/include/pthread_threading.h b/sys/posix/pthread/include/pthread_threading.h index 060ee90e1..101fe0d80 100644 --- a/sys/posix/pthread/include/pthread_threading.h +++ b/sys/posix/pthread/include/pthread_threading.h @@ -17,7 +17,7 @@ #ifndef __SYS__POSIX__PTHREAD_THREADING__H #define __SYS__POSIX__PTHREAD_THREADING__H -#include "attributes.h" +#include "kernel_defines.h" #ifdef __cplusplus extern "C" { diff --git a/tests/unittests/tests-ubjson/tests-ubjson.h b/tests/unittests/tests-ubjson/tests-ubjson.h index 4aca04edd..fb190f4a8 100644 --- a/tests/unittests/tests-ubjson/tests-ubjson.h +++ b/tests/unittests/tests-ubjson/tests-ubjson.h @@ -30,7 +30,7 @@ #define TESTS_UBJSON_H_ #include "embUnit.h" -#include "kernel_macros.h" +#include "kernel_defines.h" #include "ubjson.h"