Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
framework: forward time calls to PX4 if PX4 build
Browse files Browse the repository at this point in the history
This adds some ifdefs to make sure that pthread_cond_timedwait is used
from the PX4 platform code if this happens to be a PX4 build.
  • Loading branch information
julianoes authored and bkueng committed Oct 5, 2018
1 parent 9f456ac commit 2ccbba4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion framework/src/DriverFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************/
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include "DriverFramework.hpp"
Expand Down
10 changes: 9 additions & 1 deletion framework/src/SyncObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
#include "DriverFramework.hpp"
#include "SyncObj.hpp"

#if defined(__PX4_POSIX) || defined(__PX4_QURT)
#include <px4_time.h>
#define df_pthread_cond_timedwait px4_pthread_cond_timedwait
#else
#include <pthread.h>
#define df_pthread_cond_timedwait pthread_cond_timedwait
#endif

#define DEBUG(FMT, ...)
//#define DEBUG(FMT, ...) printf(FMT, __VA_ARGS__)

Expand Down Expand Up @@ -88,7 +96,7 @@ int SyncObj::waitOnSignal(unsigned long timeout_us)
if (timeout_us) {
struct timespec ts {};
ret = absoluteTimeInFuture(timeout_us, ts);
ret = ret ? ret : pthread_cond_timedwait(&m_new_data_cond, &m_lock, &ts);
ret = ret ? ret : df_pthread_cond_timedwait(&m_new_data_cond, &m_lock, &ts);

} else {
ret = pthread_cond_wait(&m_new_data_cond, &m_lock);
Expand Down
8 changes: 8 additions & 0 deletions framework/src/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#endif
#include <time.h>

#if defined(__PX4_POSIX) || defined(__PX4__QURT)
#include <px4_time.h>
#endif

#if defined(__DF_APPLE_LEGACY)
#include <sys/time.h>
static int clock_gettime(int clk_id, struct timespec *t)
Expand Down Expand Up @@ -68,9 +72,13 @@ int DriverFramework::absoluteTime(struct timespec &ts)
#if defined(__DF_NUTTX) || defined(__DF_APPLE_LEGACY)
// CLOCK_MONOTONIC not available on NuttX or OSX
return clock_gettime(0, &ts);
#else
#if defined(__PX4_POSIX) || defined(__PX4__QURT)
return px4_clock_gettime(CLOCK_MONOTONIC, &ts);
#else
return clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
#endif
}

int DriverFramework::absoluteTimeInFuture(uint64_t time_us, struct timespec &ts)
Expand Down

0 comments on commit 2ccbba4

Please sign in to comment.