diff --git a/config/check_depend.cmake b/config/check_depend.cmake index 3fb780ec6..4dd941f5a 100644 --- a/config/check_depend.cmake +++ b/config/check_depend.cmake @@ -54,7 +54,7 @@ OPTION(ORO_NO_EMIT_CORBA_IOR "Do not emit CORBA IORs if name service not used" O # Look for boost We look up all components in one place because this macro does # not support multiple invocations in some CMake versions. -find_package(Boost 1.38 COMPONENTS filesystem system unit_test_framework thread serialization) +find_package(Boost 1.38 COMPONENTS filesystem system unit_test_framework serialization) # Look for boost if ( PLUGINS_ENABLE ) @@ -191,7 +191,6 @@ if(OROCOS_TARGET STREQUAL "gnulinux") set(OROPKG_OS_GNULINUX TRUE CACHE INTERNAL "This variable is exported to the rtt-config.h file to expose our target choice to the code." FORCE) set(OS_HAS_TLSF TRUE) - find_package(Boost 1.36 COMPONENTS thread ) find_package(Pthread REQUIRED) include(CheckLibraryExists) @@ -213,26 +212,18 @@ if(OROCOS_TARGET STREQUAL "macosx") set(OROPKG_OS_MACOSX TRUE CACHE INTERNAL "This variable is exported to the rtt-config.h file to expose our target choice to the code." FORCE) set(OS_HAS_TLSF TRUE) - if (NOT Boost_THREAD_FOUND) - message(SEND_ERROR "Boost thread library not found but required on macosx.") - endif () - - list(APPEND OROCOS-RTT_INCLUDE_DIRS ${Boost_THREAD_INCLUDE_DIRS} ${Boost_SYSTEM_INCLUDE_DIRS} ) - - SELECT_ONE_LIBRARY("Boost_THREAD_LIBRARY" BOOST_THREAD_LIB) - LIST(APPEND OROCOS-RTT_USER_LINK_LIBS ${BOOST_THREAD_LIB}) + find_package(Pthread REQUIRED) - SELECT_ONE_LIBRARY("Boost_SYSTEM_LIBRARY" BOOST_SYSTEM_LIB) - LIST(APPEND OROCOS-RTT_USER_LINK_LIBS ${BOOST_SYSTEM_LIB}) + include(CheckLibraryExists) + check_library_exists(pthread "pthread_setname_np" "" ORO_HAVE_PTHREAD_SETNAME_NP) - message( "Forcing ORO_OS_USE_BOOST_THREAD to ON") - set( ORO_OS_USE_BOOST_THREAD ON CACHE BOOL "Forced enable use of Boost.thread on macosx." FORCE) + add_definitions( -Wall ) # Force OFF on mqueue transport on macosx message("Forcing ENABLE_MQ to OFF for macsox") set(ENABLE_MQ OFF CACHE BOOL "This option is forced to OFF by the build system on macosx platform." FORCE) - # see also src/CMakeLists.txt as it adds the boost_thread library to OROCOS_RTT_LIBRARIES + list(APPEND OROCOS-RTT_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIRS}) list(APPEND OROCOS-RTT_LIBRARIES ${PTHREAD_LIBRARIES} dl) list(APPEND OROCOS-RTT_DEFINITIONS "OROCOS_TARGET=${OROCOS_TARGET}") diff --git a/rtt/CMakeLists.txt b/rtt/CMakeLists.txt index 41a393c57..3ea62adc3 100644 --- a/rtt/CMakeLists.txt +++ b/rtt/CMakeLists.txt @@ -14,20 +14,6 @@ OPTION(OS_AGNOSTIC "Do not use asm/system.h and asm/atomic.h global system heade OPTION(OS_HAVE_IOSTREAM "Use C++ iostream library." ON) OPTION(OS_HAVE_STREAMS "Use C++ streams library." ON) OPTION(OS_HAVE_MAIN "Provide main() function in rtt library, which sets up the OS. The user implements ORO_main()." ON) -OPTION(ORO_OS_USE_BOOST_THREAD "Use the Boost.Thread library. Currently only the mutex implementation is used." OFF) - -if (ORO_OS_USE_BOOST_THREAD) - # Look for boost threads - find_package(Boost 1.36 COMPONENTS thread date_time REQUIRED) - - if (NOT Boost_THREAD_FOUND) - message(SEND_ERROR "ORO_OS_USE_BOOST_THREAD turned on, but Boost thread library is not installed or wrong version.") - endif() - - SELECT_ONE_LIBRARY("Boost_THREAD_LIBRARY" BOOST_THREAD_LIB) - list(APPEND OROCOS-RTT_LIBRARIES ${BOOST_THREAD_LIB} ${Boost_DATE_TIME_LIBRARY}) - -endif() SET(OS_MAX_CONC_ACCESS 8 CACHE STRING "The maximum number of threads that will access a lock-free resource at exactly the same time. The Default (8) is very conservative. Your application may have more threads than this number.") SET(OS_MAX_THREADS ${OS_MAX_CONC_ACCESS}) diff --git a/rtt/os/Condition.hpp b/rtt/os/Condition.hpp index da21c8b4f..01a0906b1 100644 --- a/rtt/os/Condition.hpp +++ b/rtt/os/Condition.hpp @@ -40,14 +40,8 @@ #define OS_CONDITION_HPP #include "fosi.h" -#include "../rtt-config.h" #include "Time.hpp" #include "Mutex.hpp" -#ifdef ORO_OS_USE_BOOST_THREAD -// BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG is defined in rtt-config.h -#include -#include -#endif namespace RTT { namespace os { @@ -59,7 +53,6 @@ namespace RTT */ class RTT_API Condition { -#ifndef ORO_OS_USE_BOOST_THREAD protected: rt_cond_t c; public: @@ -132,89 +125,6 @@ namespace RTT return true; return false; } -#else - protected: - boost::condition_variable_any c; - public: - /** - * Initialize a Condition. - */ - Condition() - { - } - - /** - * Destroy a Condition. - * If the Condition is still locked, the RTOS - * will not be asked to clean up its resources. - */ - ~Condition() - { - } - - /** - * Wait forever until a condition occurs - * @param m The mutex you hold locked when calling this function. - * @return false if the waiting failed. This can only - * be caused by the OS aborting the waiting. - */ - bool wait (Mutex& m) - { - c.wait(m.m); - return true; - } - - /** - * Wait forever until a condition occurs - * @param m The mutex you hold locked when calling this function. - * @param p A function object returning a boolean - * @return \a false if the waiting failed. This can only - * be caused by the OS aborting the waiting. Returns - * \a true when p() has been true. - */ - template - bool wait (Mutex& m, Predicate& p) - { - c.wait(m.m, p); - return true; - } - /** - * Wake all threads that are blocking in wait() or wait_until(). - */ - void broadcast() - { - c.notify_all(); - } - - /** - * Wait for this condition, but don't wait longer for it - * than the specified absolute time. - * - * @param m The mutex you hold locked when calling this function. - * @param abs_time The absolute time to wait until before the condition happens. - * Use rtos_get_time_ns() to get the current time and Seconds_to_nsecs to add a - * certain amount to the result. - * @return true when the condition occured, false in case the timeout - * happened. - */ - bool wait_until(Mutex& m, nsecs abs_time) - { - // abs_time is since epoch, so set p_time to epoch, then add our abs_time. - boost::posix_time::ptime p_time = boost::posix_time::from_time_t(0); - - // If the line below fails to compile, #define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG globally - // or #include before any of your include headers. - boost::posix_time::nanosec abs_p_time = boost::posix_time::nanoseconds(abs_time); - - // wakeup time = epoch date + time since epoch - p_time = p_time + abs_p_time; - return c.timed_wait(m, p_time, &Condition::retfalse ); - } - private: - static bool retfalse() { return false; } - -#endif - }; }} diff --git a/rtt/os/Mutex.hpp b/rtt/os/Mutex.hpp index 0820d481f..42fb12c12 100644 --- a/rtt/os/Mutex.hpp +++ b/rtt/os/Mutex.hpp @@ -40,7 +40,6 @@ #define OS_MUTEX_HPP #include "fosi.h" -#include "../rtt-config.h" #include "rtt-os-fwd.hpp" #include "CAS.hpp" #include "Semaphore.hpp" @@ -48,14 +47,6 @@ #include -#ifdef ORO_OS_USE_BOOST_THREAD -// BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG is defined in rtt-config.h -#include -#include -#include -#include -#endif - namespace RTT { namespace os { @@ -92,7 +83,6 @@ namespace RTT class RTT_API Mutex : public MutexInterface { friend class Condition; -#ifndef ORO_OS_USE_BOOST_THREAD protected: rt_mutex_t m; public: @@ -152,59 +142,6 @@ namespace RTT return true; return false; } -#else - protected: - boost::timed_mutex m; - public: - /** - * Initialize a Mutex. - */ - Mutex() - { - } - - /** - * Destroy a Mutex. - * If the Mutex is still locked, the RTOS - * will not be asked to clean up its resources. - */ - virtual ~Mutex() - { - } - - virtual void lock () - { - m.lock(); - } - - virtual void unlock() - { - m.unlock(); - } - - /** - * Try to lock this mutex - * - * @return true when the locking succeeded, false otherwise - */ - virtual bool trylock() - { - return m.try_lock(); - } - - /** - * Lock this mutex, but don't wait longer for the lock - * than the specified timeout. - * - * @param s The maximum time to wait before aqcuiring the lock. - * @return true when the locking succeeded, false otherwise - */ - virtual bool timedlock(Seconds s) - { - return m.timed_lock( boost::posix_time::microseconds(Seconds_to_nsecs(s)/1000) ); - } -#endif - }; /** @@ -217,7 +154,6 @@ namespace RTT */ class RTT_API MutexRecursive : public MutexInterface { -#ifndef ORO_OS_USE_BOOST_THREAD protected: rt_rec_mutex_t recm; public: @@ -277,58 +213,6 @@ namespace RTT return true; return false; } -#else - protected: - boost::recursive_timed_mutex recm; - public: - /** - * Initialize a recursive Mutex. - */ - MutexRecursive() - { - } - - /** - * Destroy a MutexRecursive. - * If the MutexRecursive is still locked, the RTOS - * will not be asked to clean up its resources. - */ - virtual ~MutexRecursive() - { - } - - void lock () - { - recm.lock(); - } - - virtual void unlock() - { - recm.unlock(); - } - - /** - * Try to lock this mutex - * - * @return true when the locking succeeded, false otherwise - */ - virtual bool trylock() - { - return recm.try_lock(); - } - - /** - * Lock this mutex, but don't wait longer for the lock - * than the specified timeout. - * - * @param s The maximum time to wait before aqcuiring the lock. - * @return true when the locking succeeded, false otherwise - */ - virtual bool timedlock(Seconds s) - { - return recm.timed_lock( boost::posix_time::microseconds( Seconds_to_nsecs(s)/1000 ) ); - } -#endif }; /** diff --git a/rtt/os/gnulinux/fosi.h b/rtt/os/gnulinux/fosi.h index 5c856c875..5355dd15f 100644 --- a/rtt/os/gnulinux/fosi.h +++ b/rtt/os/gnulinux/fosi.h @@ -304,14 +304,6 @@ extern "C" return pthread_mutex_unlock(m); } - static inline void rtos_enable_rt_warning(void) - { - } - - static inline void rtos_disable_rt_warning(void) - { - } - typedef pthread_cond_t rt_cond_t; static inline int rtos_cond_init(rt_cond_t *cond) @@ -354,6 +346,14 @@ extern "C" return pthread_cond_broadcast(cond); } + static inline void rtos_enable_rt_warning(void) + { + } + + static inline void rtos_disable_rt_warning(void) + { + } + #define rtos_printf printf #ifdef __cplusplus diff --git a/rtt/os/macosx/CMakeLists.txt b/rtt/os/macosx/CMakeLists.txt index a1dbb2b4f..5b6497b6a 100644 --- a/rtt/os/macosx/CMakeLists.txt +++ b/rtt/os/macosx/CMakeLists.txt @@ -4,4 +4,4 @@ IF (OROCOS_TARGET STREQUAL "macosx") GLOBAL_ADD_INCLUDE( rtt/os/macosx ${HPPS}) GLOBAL_ADD_SRC( ${CPPS}) -ENDIF (OROCOS_TARGET STREQUAL "macosx") +ENDIF (OROCOS_TARGET STREQUAL "macosx") \ No newline at end of file diff --git a/rtt/os/macosx/fosi.h b/rtt/os/macosx/fosi.h index 4592986fb..265a955c8 100644 --- a/rtt/os/macosx/fosi.h +++ b/rtt/os/macosx/fosi.h @@ -37,8 +37,6 @@ #ifndef __FOSI_H #define __FOSI_H -#define _DARWIN_C_SOURCE - #define HAVE_FOSI_API #ifdef __cplusplus @@ -46,6 +44,9 @@ extern "C" { #endif +#ifndef _DARWIN_C_SOURCE +#define _DARWIN_C_SOURCE +#endif #include #include @@ -53,13 +54,30 @@ extern "C" #include #include +#include +#include #include #include #include + // Time Related +#include +#include +#include + +#ifndef RTT_VERIFY +#if defined(NDEBUG) +# define RTT_VERIFY(expr) ((void)(expr)) +#else +# define RTT_VERIFY(expr) assert(expr) +#endif +#endif + typedef long long NANO_TIME; typedef long long TICK_TIME; + typedef struct timespec TIME_SPEC; + static const TICK_TIME InfiniteTicks = LLONG_MAX; static const NANO_TIME InfiniteNSecs = LLONG_MAX; @@ -87,15 +105,6 @@ extern "C" #define ORO_SCHED_RT SCHED_FIFO /** Posix FIFO scheduler */ #define ORO_SCHED_OTHER SCHED_OTHER /** Posix normal scheduler */ - /* - * Time Related stuff - */ -#include -#include -#include - - typedef struct timespec TIME_SPEC; - #ifndef CLOCK_REALTIME /* fake clock_gettime for systems like darwin */ #define CLOCK_REALTIME 0 @@ -139,7 +148,7 @@ extern "C" * This function should return ticks, * but we use ticks == nsecs in userspace */ - static inline NANO_TIME rtos_get_time_ticks() + static inline NANO_TIME rtos_get_time_ticks(void) { return rtos_get_time_ns(); } @@ -257,24 +266,314 @@ extern "C" /* return -1; */ /* } */ - // Mutex functions - support only those needed by TLSF - // opaque type - typedef struct rt_mutex_impl_t rt_mutex_impl_t; - // type created by tlsf.c (must work in C, not C++ code) - typedef rt_mutex_impl_t* rt_mutex_t; - int rtos_mutex_init(rt_mutex_t* m); - int rtos_mutex_destroy(rt_mutex_t* m); - int rtos_mutex_lock( rt_mutex_t* m); - int rtos_mutex_unlock( rt_mutex_t* m); + // Mutex functions + + + // Note: Apple's implementation of pthread_mutex_t does not have pthread_mutex_timedlock. + // Workaround: Pair the mutex with a condition variable that is signaled whenever the mutex is unlocked. + // This is also how boost::timed_mutex is implemented for the case BOOST_THREAD_USES_PTHREAD_TIMEDLOCK is + // not defined (cf. https://github.com/boostorg/thread/blob/boost-1.62.0/include/boost/thread/pthread/mutex.hpp#L181). + typedef struct { + pthread_mutex_t m; + pthread_cond_t cond; + bool is_locked; + } rt_mutex_t; + typedef struct { + pthread_mutex_t m; + pthread_cond_t cond; + bool is_locked; + pthread_t owner; + unsigned count; + } rt_rec_mutex_t; + + #define _RTOS_INTERNAL_MUTEX_LOCK \ + RTT_VERIFY(!(ret = pthread_mutex_lock((&(m->m))))); \ + if (ret != 0) return ret + + #define _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN \ + RTT_VERIFY(!pthread_mutex_unlock(&(m->m))); \ + return + + static inline int rtos_mutex_init(rt_mutex_t* m) + { + pthread_mutexattr_t attr; + int ret = 0; + + RTT_VERIFY(!(pthread_mutexattr_init(&attr))); + if (ret != 0) return ret; + + // The mutex only protects the internal flags, so no use to enable priority inheritance. + // A thread waiting on the condition variable in pthread_cond_wait would not inherit the + // priority of the thread that holds the mutex. + + // initialize mutex + RTT_VERIFY(!(ret = pthread_mutex_init(&(m->m), &attr))); + if (ret != 0) { + RTT_VERIFY(!pthread_mutexattr_destroy(&attr)); + return ret; + } + pthread_mutexattr_destroy(&attr); + + // initialize condition variable (for rtos_mutex_lock_until) + RTT_VERIFY(!(ret = pthread_cond_init(&(m->cond), NULL))); + if (ret != 0) { + RTT_VERIFY(!pthread_mutex_destroy(&(m->m))); + return ret; + } + + m->is_locked = false; + return ret; + } - static inline void rtos_enable_rt_warning() + static inline int rtos_mutex_destroy(rt_mutex_t* m ) { + RTT_VERIFY(!pthread_cond_destroy(&(m->cond))); + int ret = 0; + RTT_VERIFY(!(ret = pthread_mutex_destroy(&(m->m)))); + return ret; } - static inline void rtos_disable_rt_warning() + static inline int rtos_mutex_rec_init(rt_rec_mutex_t* m) { + m->count = 0; + return rtos_mutex_init((rt_mutex_t *) m); } + static inline int rtos_mutex_rec_destroy(rt_rec_mutex_t* m ) + { + return rtos_mutex_destroy((rt_mutex_t *) m); + } + + static inline int rtos_mutex_lock( rt_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + while (m->is_locked) { + RTT_VERIFY(!(ret = pthread_cond_wait(&(m->cond), &(m->m)))); + if (ret) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + } + + m->is_locked = true; + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_rec_lock( rt_rec_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + if (m->is_locked && pthread_equal(m->owner, pthread_self())) { + ++(m->count); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + while (m->is_locked) { + RTT_VERIFY(!(ret = pthread_cond_wait(&(m->cond), &(m->m)))); + if (ret) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + } + + m->is_locked = true; + RTT_VERIFY(m->count == 0); + ++(m->count); + m->owner = pthread_self(); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_lock_until( rt_mutex_t* m, NANO_TIME abs_time) + { + TIME_SPEC arg_time = ticks2timespec( abs_time ); + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + while (m->is_locked) + { + ret = pthread_cond_timedwait(&(m->cond), &(m->m), &arg_time); + if (ret == ETIMEDOUT) { + break; + } + RTT_VERIFY(!ret); + } + + if (m->is_locked) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ETIMEDOUT; + } + + m->is_locked = true; + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_rec_lock_until( rt_rec_mutex_t* m, NANO_TIME abs_time) + { + TIME_SPEC arg_time = ticks2timespec( abs_time ); + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + if (m->is_locked && pthread_equal(m->owner, pthread_self())) { + ++(m->count); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + while (m->is_locked) + { + ret = pthread_cond_timedwait(&(m->cond), &(m->m), &arg_time); + if (ret == ETIMEDOUT) { + break; + } + RTT_VERIFY(!ret); + } + + if (m->is_locked) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ETIMEDOUT; + } + + m->is_locked = true; + RTT_VERIFY(m->count == 0); + ++(m->count); + m->owner = pthread_self(); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_trylock( rt_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + if (m->is_locked) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN EBUSY; + } + + m->is_locked = true; + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_rec_trylock( rt_rec_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + if (m->is_locked && !pthread_equal(m->owner, pthread_self())) { + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN EBUSY; + } + + m->is_locked = true; + ++(m->count); + m->owner = pthread_self(); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_unlock( rt_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + m->is_locked = false; + + RTT_VERIFY(!pthread_cond_signal(&(m->cond))); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + static inline int rtos_mutex_rec_unlock( rt_rec_mutex_t* m) + { + int ret = 0; + _RTOS_INTERNAL_MUTEX_LOCK; + + if (--(m->count) == 0) { + m->is_locked = false; + } + + RTT_VERIFY(!pthread_cond_signal(&(m->cond))); + _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN ret; + } + + #undef _RTOS_INTERNAL_MUTEX_LOCK + #undef _RTOS_INTERNAL_MUTEX_UNLOCK_AND_RETURN + + typedef pthread_cond_t rt_cond_t; + + static inline int rtos_cond_init(rt_cond_t *cond) + { + int ret = 0; + RTT_VERIFY(!(ret = pthread_cond_init(cond, NULL))); + return ret; + } + + static inline int rtos_cond_destroy(rt_cond_t *cond) + { + int ret = 0; + RTT_VERIFY(!(ret = pthread_cond_destroy(cond))); + return ret; + } + + static inline int rtos_cond_wait(rt_cond_t *cond, rt_mutex_t *mutex) + { + int ret = 0; + RTT_VERIFY(!(ret = pthread_mutex_lock((&(mutex->m))))); + if (ret != 0) return ret; + + if (!mutex->is_locked) { + RTT_VERIFY(!(ret = pthread_mutex_unlock((&(mutex->m))))); + return EINVAL; + } + + mutex->is_locked = false; + RTT_VERIFY(!pthread_cond_signal(&(mutex->cond))); + + RTT_VERIFY(!(ret = pthread_cond_wait(cond, &(mutex->m)))); + + mutex->is_locked = true; + + RTT_VERIFY(!pthread_mutex_unlock(&(mutex->m))); + return ret; + } + + static inline int rtos_cond_timedwait(rt_cond_t *cond, rt_mutex_t *mutex, NANO_TIME abs_time) + { + int ret = 0; + RTT_VERIFY(!(ret = pthread_mutex_lock((&(mutex->m))))); + if (ret != 0) return ret; + + if (!mutex->is_locked) { + RTT_VERIFY(!(ret = pthread_mutex_unlock((&(mutex->m))))); + return EINVAL; + } + + mutex->is_locked = false; + RTT_VERIFY(!pthread_cond_signal(&(mutex->cond))); + + TIME_SPEC arg_time = ticks2timespec( abs_time ); + ret = pthread_cond_timedwait(cond, &(mutex->m), &arg_time); + + mutex->is_locked = true; + + if (ret == ETIMEDOUT) { + RTT_VERIFY(!pthread_mutex_unlock(&(mutex->m))); + return ret; + } + RTT_VERIFY(!ret); + + RTT_VERIFY(!pthread_mutex_unlock(&(mutex->m))); + return ret; + } + + static inline int rtos_cond_broadcast(rt_cond_t *cond) + { + int ret = 0; + RTT_VERIFY(!(ret = pthread_cond_broadcast(cond))); + return ret; + } + + static inline void rtos_enable_rt_warning(void) + { + } + + static inline void rtos_disable_rt_warning(void) + { + } #define rtos_printf printf diff --git a/rtt/os/macosx/fosi_internal.cpp b/rtt/os/macosx/fosi_internal.cpp index 05b0078ce..06f7fe73e 100644 --- a/rtt/os/macosx/fosi_internal.cpp +++ b/rtt/os/macosx/fosi_internal.cpp @@ -289,42 +289,4 @@ namespace RTT } } -// opaque type to hide C object from C code -typedef struct rt_mutex_impl_t -{ - RTT::os::Mutex mutex; -}; - -int rtos_mutex_init(rt_mutex_t* m) -{ - assert(m); - *m = new rt_mutex_impl_t; // non-realtime - return (0 != (*m)); -} - -int rtos_mutex_destroy(rt_mutex_t* m ) -{ - assert(m); - assert(*m); - delete (*m); // non-realtime - (*m) = 0; - return 0; -} - -int rtos_mutex_lock( rt_mutex_t* m) -{ - assert(m); - assert(*m); - (*m)->mutex.lock(); - return 0; -} - -int rtos_mutex_unlock( rt_mutex_t* m) -{ - assert(m); - assert(*m); - (*m)->mutex.unlock(); - return 0; -} - #undef INTERNAL_QUAL diff --git a/rtt/os/targets/target-config.h.in b/rtt/os/targets/target-config.h.in index a4066c349..da54a6810 100644 --- a/rtt/os/targets/target-config.h.in +++ b/rtt/os/targets/target-config.h.in @@ -74,14 +74,6 @@ #cmakedefine ORO_HAVE_LIBUUID #cmakedefine ORO_OS_USE_BOOST_THREAD -#ifdef ORO_OS_USE_BOOST_THREAD -# ifndef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -# define BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -# endif -# ifndef BOOST_THREAD_DONT_USE_CHRONO -# define BOOST_THREAD_DONT_USE_CHRONO -# endif -#endif #cmakedefine CONFIG_FORCE_UP diff --git a/rtt/os/tlsf/target.h b/rtt/os/tlsf/target.h index 782f704b7..ae1397c35 100644 --- a/rtt/os/tlsf/target.h +++ b/rtt/os/tlsf/target.h @@ -41,10 +41,22 @@ #include "../fosi.h" -#define TLSF_MLOCK_T rt_mutex_t -#define TLSF_CREATE_LOCK(l) rtos_mutex_init (l) -#define TLSF_DESTROY_LOCK(l) rtos_mutex_destroy(l) -#define TLSF_ACQUIRE_LOCK(l) rtos_mutex_lock(l) -#define TLSF_RELEASE_LOCK(l) rtos_mutex_unlock(l) +#if defined(OROPKG_OS_MACOSX) +// Use pthread directly for TLSF. +// The macosx implementation of rt_mutex_t has some overhead to support +// timed locking. +# define TLSF_MLOCK_T pthread_mutex_t +# define TLSF_CREATE_LOCK(l) pthread_mutex_init(l, NULL) +# define TLSF_DESTROY_LOCK(l) pthread_mutex_destroy(l) +# define TLSF_ACQUIRE_LOCK(l) pthread_mutex_lock(l) +# define TLSF_RELEASE_LOCK(l) pthread_mutex_unlock(l) + +#else +# define TLSF_MLOCK_T rt_mutex_t +# define TLSF_CREATE_LOCK(l) rtos_mutex_init (l) +# define TLSF_DESTROY_LOCK(l) rtos_mutex_destroy(l) +# define TLSF_ACQUIRE_LOCK(l) rtos_mutex_lock(l) +# define TLSF_RELEASE_LOCK(l) rtos_mutex_unlock(l) +#endif #endif diff --git a/rtt/os/tlsf/tlsf.c b/rtt/os/tlsf/tlsf.c index 687fe717a..e522e5c2e 100644 --- a/rtt/os/tlsf/tlsf.c +++ b/rtt/os/tlsf/tlsf.c @@ -528,7 +528,7 @@ size_t init_memory_pool(size_t mem_pool_size, void *mem_pool) TLSF_CREATE_LOCK(&tlsf->lock); ib = process_area(GET_NEXT_BLOCK - (mem_pool, ROUNDUP_SIZE(sizeof(tlsf_t))), ROUNDDOWN_SIZE(mem_pool_size - sizeof(tlsf_t))); + (mem_pool, ROUNDUP_SIZE(sizeof(tlsf_t))), ROUNDDOWN_SIZE(mem_pool_size - ROUNDUP_SIZE(sizeof(tlsf_t)))); b = GET_NEXT_BLOCK(ib->ptr.buffer, ib->size & BLOCK_SIZE); free_ex(b->ptr.buffer, tlsf); tlsf->area_head = TYPE_PUN(area_info_t, u8_t, ib->ptr.buffer);