37 #include <boost/scope_exit.hpp> 55 boost::mutex::scoped_lock lock(
mutex_);
63 boost::mutex::scoped_lock lock(
mutex_);
71 boost::mutex::scoped_lock lock(
mutex_);
78 boost::mutex::scoped_lock lock(
mutex_);
85 boost::mutex::scoped_lock lock(
mutex_);
107 M_IDInfo::iterator it =
id_info_.find(removal_id);
110 IDInfoPtr id_info(boost::make_shared<IDInfo>());
111 id_info->id = removal_id;
112 id_info_.insert(std::make_pair(removal_id, id_info));
117 boost::mutex::scoped_lock lock(
mutex_);
127 if (callback->ready())
136 M_IDInfo::iterator it =
id_info_.find(
id);
153 M_IDInfo::iterator it =
id_info_.find(removal_id);
156 id_info = it->second;
166 if (
tls_->calling_in_this_thread == id_info->id)
168 id_info->calling_rw_mutex.unlock_shared();
172 boost::unique_lock<boost::shared_mutex> rw_lock(id_info->calling_rw_mutex, boost::defer_lock);
173 if (rw_lock.try_lock())
175 boost::mutex::scoped_lock lock(
mutex_);
176 D_CallbackInfo::iterator it =
callbacks_.begin();
194 boost::mutex::scoped_lock lock(
mutex_);
206 if (
tls_->calling_in_this_thread == id_info->id)
208 id_info->calling_rw_mutex.lock_shared();
215 D_CallbackInfo::iterator it =
tls_->callbacks.begin();
216 D_CallbackInfo::iterator end =
tls_->callbacks.end();
217 for (; it != end; ++it)
241 boost::mutex::scoped_lock lock(
mutex_);
248 boost::chrono::steady_clock::time_point wait_until =
249 boost::chrono::steady_clock::now() + boost::chrono::nanoseconds(timeout.
toNSec());
251 D_CallbackInfo::iterator it =
callbacks_.begin();
277 boost::cv_status wait_status = boost::cv_status::timeout;
280 wait_status =
condition_.wait_until(lock, wait_until);
293 if (wait_status == boost::cv_status::timeout)
312 boost::mutex::scoped_lock lock(
mutex_);
324 boost::mutex::scoped_lock lock(
mutex_);
368 boost::mutex::scoped_lock lock(
mutex_);
396 boost::shared_lock<boost::shared_mutex> rw_lock(id_info->calling_rw_mutex);
407 BOOST_SCOPE_EXIT(&tls, &last_calling)
413 if (info.marked_for_removal)
431 boost::mutex::scoped_lock lock(
mutex_);
CallResult
Possible results for the call() method.
boost::thread_specific_ptr< TLS > tls_
D_CallbackInfo::iterator cb_it
void disable()
Disable the queue, meaning any calls to addCallback() will have no effect.
virtual void addCallback(const CallbackInterfacePtr &callback, uint64_t removal_id=0)
Add a callback, with an optional owner id. The owner id can be used to remove a set of callbacks from...
void enable()
Enable the queue (queue is enabled by default)
ros::internal::condition_variable_monotonic condition_
CallOneResult callOne()
Pop a single callback off the front of the queue and invoke it. If the callback was not ready to be c...
D_CallbackInfo callbacks_
boost::shared_ptr< IDInfo > IDInfoPtr
CallbackQueue(bool enabled=true)
void callAvailable()
Invoke all callbacks currently in the queue. If a callback was not ready to be called, pushes it back onto the queue.
CallOneResult callOneCB(TLS *tls)
bool isEnabled()
Returns whether or not this queue is enabled.
boost::mutex id_info_mutex_
virtual void removeByID(uint64_t removal_id)
Remove all callbacks associated with an owner id.
Call not ready, try again later.
IDInfoPtr getIDInfo(uint64_t id)
uint64_t calling_in_this_thread
CallbackInterfacePtr callback
bool isEmpty()
returns whether or not the queue is empty
void clear()
Removes all callbacks from the queue. Does not wait for calls currently in progress to finish...