Skip to content

Drop usage of Boost Thread for the macosx target and remove ORO_OS_USE_BOOST_THREAD #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: toolchain-2.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions config/check_depend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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)
Expand All @@ -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}")

Expand Down
14 changes: 0 additions & 14 deletions rtt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
90 changes: 0 additions & 90 deletions rtt/os/Condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/thread/condition.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#endif

namespace RTT
{ namespace os {
Expand All @@ -59,7 +53,6 @@ namespace RTT
*/
class RTT_API Condition
{
#ifndef ORO_OS_USE_BOOST_THREAD
protected:
rt_cond_t c;
public:
Expand Down Expand Up @@ -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<class Predicate>
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 <rtt/rtt-config.h> 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

};
}}

Expand Down
116 changes: 0 additions & 116 deletions rtt/os/Mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,13 @@
#define OS_MUTEX_HPP

#include "fosi.h"
#include "../rtt-config.h"
#include "rtt-os-fwd.hpp"
#include "CAS.hpp"
#include "Semaphore.hpp"
#include "Time.hpp"

#include <cassert>

#ifdef ORO_OS_USE_BOOST_THREAD
// BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG is defined in rtt-config.h
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#endif

namespace RTT
{ namespace os {

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

};

/**
Expand All @@ -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:
Expand Down Expand Up @@ -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
};

/**
Expand Down
16 changes: 8 additions & 8 deletions rtt/os/gnulinux/fosi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rtt/os/macosx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading