36 #include <gtest/gtest.h> 41 #include <boost/atomic.hpp> 42 #include <boost/shared_ptr.hpp> 43 #include <boost/bind.hpp> 44 #include <boost/thread.hpp> 45 #include <boost/function.hpp> 58 boost::mutex::scoped_lock lock(mutex);
76 EXPECT_EQ(cb->count, 1U);
81 EXPECT_EQ(cb->count, 2U);
84 EXPECT_EQ(cb->count, 2U);
87 EXPECT_EQ(cb->count, 2U);
94 for (uint32_t i = 0; i < 1000; ++i)
101 EXPECT_EQ(cb->count, 1000U);
108 for (uint32_t i = 0; i < 1000; ++i)
113 for (uint32_t i = 0; i < 1000; ++i)
116 EXPECT_EQ(cb->count, i + 1);
130 EXPECT_EQ(cb1->count, 0U);
131 EXPECT_EQ(cb2->count, 1U);
147 queue->removeByID(
id);
174 EXPECT_EQ(cb1->count, 1U);
175 EXPECT_EQ(cb2->count, 1U);
184 , use_available(use_available)
195 queue->callAvailable();
222 EXPECT_EQ(cb->count, 3U);
234 EXPECT_EQ(cb->count, 3U);
246 EXPECT_EQ(cb->count, 3U);
258 EXPECT_EQ(cb->count, 3U);
272 boost::thread_group tg;
275 for (uint32_t i = 0; i < 10; ++i)
277 tg.create_thread(boost::bind(
threadFunc, &queue, boost::ref(done)));
304 EXPECT_EQ(cb->count, i);
320 EXPECT_EQ(cb->count, i);
381 recursiveTimerQueue = &queue;
382 TimerRecursionCallbackPtr cb(boost::make_shared<TimerRecursionCallback>(&queue));
385 boost::thread_group tg;
388 for (uint32_t i = 0; i < 2; ++i)
390 tg.create_thread(boost::bind(
callOneThread, &queue, boost::ref(done)));
406 : id(0), queue(_queue) {
407 condition_sync.store(
true);
408 condition_one.store(
false);
409 condition_stop.store(
false);
425 : condition_object(_condition_object), id(_id)
430 condition_object->condition_one.store(
false);
440 while(!condition_stop.load())
442 if(condition_sync.load() && queue->isEmpty())
444 condition_one.store(
true);
446 queue->addCallback(boost::make_shared<RaceConditionCallback>(
this, &
id),
id);
448 boost::this_thread::sleep(boost::posix_time::microseconds(1));
458 for(
unsigned int i = 0; i < 1000000; ++i)
477 int main(
int argc,
char** argv)
479 testing::InitGoogleTest(&argc, argv);
480 return RUN_ALL_TESTS();
boost::shared_ptr< TimerRecursionCallback > TimerRecursionCallbackPtr
int main(int argc, char **argv)
virtual CallResult call()
virtual void addCallback(const CallbackInterfacePtr &callback, uint64_t removal_id=0)
void dummyTimer(const ros::TimerEvent &)
boost::shared_ptr< CountingCallback > CountingCallbackPtr
size_t runThreadedTest(const CountingCallbackPtr &cb, const boost::function< void(CallbackQueue *, bool &)> &threadFunc)
virtual CallResult call()
ConditionObject(CallbackQueue *_queue)
virtual CallResult call()
boost::atomic< bool > condition_stop
virtual CallResult call()
RecursiveCallback(CallbackQueue *queue, bool use_available)
boost::shared_ptr< RecursiveCallback > RecursiveCallbackPtr
bool add(test_roscpp::TestStringString::Request &, test_roscpp::TestStringString::Response &)
boost::atomic< bool > condition_one
CallbackQueueInterface * recursiveTimerQueue
ConditionObject * condition_object
CallbackQueueInterface * queue
void threadFunc(boost::barrier *b)
void callAvailableThread(CallbackQueue *queue, bool &done)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
virtual void removeByID(uint64_t removal_id)
TEST(CallbackQueue, singleCallback)
void recursiveTimer(const ros::TimerEvent &)
void callOneThread(CallbackQueue *queue, bool &done)
#define ROS_INFO_STREAM(args)
boost::shared_ptr< SelfRemovingCallback > SelfRemovingCallbackPtr
SelfRemovingCallback(CallbackQueue *queue, uint64_t id)
virtual CallResult call()
TimerRecursionCallback(CallbackQueueInterface *_queue)
boost::atomic< bool > condition_sync
RaceConditionCallback(ConditionObject *_condition_object, unsigned long *_id)