From 12374490cb4485e26c9e5ce132fd1c6328bb07ef Mon Sep 17 00:00:00 2001 From: Julian Oes <julian@oes.ch> Date: Mon, 20 May 2019 14:04:02 +0200 Subject: [PATCH] visibility.h: clean up includes, add comments This tries to make the visibility.h header clearer and better structured. We don't actually need the ifdef for lockstep enabled or disabled because that's now handled elsewhere. --- src/include/visibility.h | 71 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/include/visibility.h b/src/include/visibility.h index 4450c9495c..5de2682a8c 100644 --- a/src/include/visibility.h +++ b/src/include/visibility.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012-2018 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2019 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -59,68 +59,67 @@ # define __END_DECLS #endif + + + + /* exit() is used on NuttX to exit a task. However on Posix, it will exit the * whole application, so we prevent its use there. There are cases where it * still needs to be used, thus we remap system_exit to exit. */ #define system_exit exit - -#if defined(ENABLE_LOCKSTEP_SCHEDULER) - +#if !defined(__PX4_NUTTX) #include <stdlib.h> -#include <unistd.h> - -#define system_usleep usleep -#pragma GCC poison usleep -#define system_sleep sleep -#pragma GCC poison sleep - -#define system_clock_gettime clock_gettime -#define system_clock_settime clock_settime - -#include <pthread.h> -#define system_pthread_cond_timedwait pthread_cond_timedwait -// We can't poison pthread_cond_timedwait because it seems to be used in the -// <string> include. - #ifdef __cplusplus #include <cstdlib> #endif +/* We should include cstdlib or stdlib.h but this doesn't + * compile because many C++ files include stdlib.h and would + * need to get changed. */ #pragma GCC poison exit +#endif // !defined(__PX4_NUTTX) -#include <stdlib.h> -#ifdef __cplusplus -#include <cstdlib> -#endif - -// We don't poison usleep and sleep on NuttX because it is used in dependencies -// like uavcan and we don't need to fake time on the real system. -#include <unistd.h> +/* For SITL lockstep we fake the clock, sleeping, and timedwaits + * Therefore, we prefix these syscalls with system_. */ #include <time.h> +#define system_clock_gettime clock_gettime +#define system_clock_settime clock_settime +/* We can't poison clock_settime/clock_gettime because they are + * used in DriverFramework. */ -#else // defined(ENABLE_LOCKSTEP_SCHEDULER) +#if !defined(__PX4_NUTTX) +#include <pthread.h> +// We can't include this for NuttX otherwise we get conflicts for read/write +// symbols in cannode. +#endif // !defined(__PX4_NUTTX) +#define system_pthread_cond_timedwait pthread_cond_timedwait +/* We can't poison pthread_cond_timedwait because it seems to be used in the + * <string> include. */ -#include <stdlib.h> -#include <unistd.h> +/* We don't poison usleep and sleep because it is used in dependencies + * like uavcan and DriverFramework. */ +#if !defined(__PX4_NUTTX) +#include <unistd.h> +// We can't include this for NuttX otherwise we get conflicts for read/write +// symbols in cannode. +#endif // !defined(__PX4_NUTTX) #define system_usleep usleep #define system_sleep sleep -#define system_clock_gettime clock_gettime -#define system_clock_settime clock_settime -#define system_pthread_cond_timedwait pthread_cond_timedwait - -#endif -#if defined(__PX4_NUTTX) /* On NuttX we call clearenv() so we cannot use getenv() and others (see * px4_task_spawn_cmd() in px4_nuttx_tasks.c). * We need to include the headers declaring getenv() before the pragma, * otherwise it will trigger a poison error. */ +#if defined(__PX4_NUTTX) #include <stdlib.h> #ifdef __cplusplus #include <cstdlib> #endif +/* We should include cstdlib or stdlib.h but this doesn't + * compile because many C++ files include stdlib.h and would + * need to get changed. */ #pragma GCC poison getenv setenv putenv #endif // defined(__PX4_NUTTX) -- GitLab