Skip to content

Commit

Permalink
roscpp: implementet ros#1608 without ABI/API breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Wecht committed Apr 2, 2019
1 parent a809051 commit c28d0fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 36 deletions.
15 changes: 15 additions & 0 deletions clients/roscpp/include/ros/callback_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
#ifndef ROSCPP_CALLBACK_QUEUE_H
#define ROSCPP_CALLBACK_QUEUE_H

// check if we might need to include our own backported version boost::condition_variable
// in order to use CLOCK_MONOTONIC for the condition variable
// the include order here is important!
#ifdef BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC
#include <boost/version.hpp>
#if BOOST_VERSION < 106100
// use backported version of boost condition variable, see https://svn.boost.org/trac/boost/ticket/6377
#include "boost_161_condition_variable.h"
#else // Boost version is 1.61 or greater and has the steady clock fixes
#include <boost/thread/condition_variable.hpp>
#endif
#else // !BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC
#include <boost/thread/condition_variable.hpp>
#endif // BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC

#include "ros/callback_queue_interface.h"
#include "ros/time.h"
#include "common.h"
Expand Down
17 changes: 0 additions & 17 deletions clients/roscpp/include/ros/callback_queue_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@
#ifndef ROSCPP_CALLBACK_QUEUE_INTERFACE_H
#define ROSCPP_CALLBACK_QUEUE_INTERFACE_H

// check if we might need to include our own backported version boost::condition_variable
// in order to use CLOCK_MONOTONIC for the condition variable
// the include order here is important!
#ifdef BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC
#include <boost/version.hpp>
#if BOOST_VERSION < 106100
// use backported version of boost condition variable, see https://svn.boost.org/trac/boost/ticket/6377
#include "boost_161_condition_variable.h"
#else // Boost version is 1.61 or greater and has the steady clock fixes
#include <boost/thread/condition_variable.hpp>
#endif
#else // !BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC
#include <boost/thread/condition_variable.hpp>
#endif // BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC

#include <boost/shared_ptr.hpp>
#include "common.h"
#include "ros/types.h"
Expand Down Expand Up @@ -85,8 +70,6 @@ class ROSCPP_DECL CallbackInterface
* before call() actually takes place.
*/
virtual bool ready() { return true; }

virtual void setNotifyWhenReady(boost::condition_variable *condition) {};
};
typedef boost::shared_ptr<CallbackInterface> CallbackInterfacePtr;

Expand Down
9 changes: 0 additions & 9 deletions clients/roscpp/include/ros/subscription_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#ifndef ROSCPP_SUBSCRIPTION_QUEUE_H
#define ROSCPP_SUBSCRIPTION_QUEUE_H

// Make sure we use CLOCK_MONOTONIC for the condition variable wait_for if not Apple.
#ifndef __APPLE__
#define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC
#endif

#include "forwards.h"
#include "common.h"
#include "ros/message_event.h"
Expand Down Expand Up @@ -79,8 +74,6 @@ class ROSCPP_DECL SubscriptionQueue : public CallbackInterface, public boost::en

virtual CallbackInterface::CallResult call();
virtual bool ready();
virtual void setNotifyWhenReady(boost::condition_variable* condition);

bool full();

private:
Expand All @@ -94,8 +87,6 @@ class ROSCPP_DECL SubscriptionQueue : public CallbackInterface, public boost::en
uint32_t queue_size_;
bool allow_concurrent_callbacks_;

boost::condition_variable* notify_when_ready_condition_;

boost::recursive_mutex callback_mutex_;
};

Expand Down
3 changes: 1 addition & 2 deletions clients/roscpp/src/libros/callback_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ void CallbackQueue::addCallback(const CallbackInterfacePtr& callback, uint64_t r

if (callback->ready())
condition_.notify_one();
else
callback->setNotifyWhenReady(&condition_);
}

CallbackQueue::IDInfoPtr CallbackQueue::getIDInfo(uint64_t id)
Expand Down Expand Up @@ -414,6 +412,7 @@ CallbackQueue::CallOneResult CallbackQueue::callOneCB(TLS* tls)
{
tls->cb_it = tls->callbacks.erase(tls->cb_it);
result = cb->call();
condition_.notify_one();
}
}

Expand Down
8 changes: 0 additions & 8 deletions clients/roscpp/src/libros/subscription_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ SubscriptionQueue::SubscriptionQueue(const std::string& topic, int32_t queue_siz
, full_(false)
, queue_size_(0)
, allow_concurrent_callbacks_(allow_concurrent_callbacks)
, notify_when_ready_condition_(NULL)
{}

SubscriptionQueue::~SubscriptionQueue()
Expand Down Expand Up @@ -165,9 +164,6 @@ CallbackInterface::CallResult SubscriptionQueue::call()
i.helper->call(params);
}

if (notify_when_ready_condition_)
notify_when_ready_condition_->notify_one();

return CallbackInterface::Success;
}

Expand All @@ -191,9 +187,5 @@ bool SubscriptionQueue::fullNoLock()
return (size_ > 0) && (queue_size_ >= (uint32_t)size_);
}

void SubscriptionQueue::setNotifyWhenReady(boost::condition_variable* condition) {
notify_when_ready_condition_ = condition;
}

}

0 comments on commit c28d0fc

Please sign in to comment.