Skip to content

Commit

Permalink
visibility.h: clean up includes, add comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
julianoes authored and dagar committed May 20, 2019
1 parent 8453792 commit 1237449
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions src/include/visibility.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 1237449

Please sign in to comment.