36 #include <gtest/gtest.h>
41 #include <boost/atomic.hpp>
42 #include <boost/shared_ptr.hpp>
43 #include <boost/bind/bind.hpp>
44 #include <boost/thread.hpp>
45 #include <boost/function.hpp>
58 boost::mutex::scoped_lock lock(mutex);
85 EXPECT_EQ(cb->count, 1U);
90 EXPECT_EQ(cb->count, 2U);
93 EXPECT_EQ(cb->count, 2U);
96 EXPECT_EQ(cb->count, 2U);
103 for (uint32_t i = 0; i < 1000; ++i)
110 EXPECT_EQ(cb->count, 1000U);
117 for (uint32_t i = 0; i < 1000; ++i)
122 for (uint32_t i = 0; i < 1000; ++i)
125 EXPECT_EQ(cb->count, i + 1);
139 EXPECT_EQ(cb1->count, 0U);
140 EXPECT_EQ(cb2->count, 1U);
156 queue->removeByID(
id);
183 EXPECT_EQ(cb1->count, 1U);
184 EXPECT_EQ(cb2->count, 1U);
211 const uint64_t owner_id = 1;
212 const uint64_t unrelated_id = 2;
238 cb1->mutex_.unlock();
249 EXPECT_EQ(cb1->count, 1U);
250 EXPECT_EQ(cb2->count, 1U);
251 EXPECT_EQ(cb3->count, 0U);
253 cb1->mutex_.unlock();
262 , use_available(use_available)
273 queue->callAvailable();
300 EXPECT_EQ(cb->count, 3U);
312 EXPECT_EQ(cb->count, 3U);
324 EXPECT_EQ(cb->count, 3U);
336 EXPECT_EQ(cb->count, 3U);
342 boost::thread_group tg;
345 for (uint32_t i = 0; i < 10; ++i)
347 tg.create_thread(boost::bind(
threadFunc, &queue, boost::ref(done)));
374 EXPECT_EQ(cb->count, i);
390 EXPECT_EQ(cb->count, i);
455 boost::thread_group tg;
458 for (uint32_t i = 0; i < 2; ++i)
460 tg.create_thread(boost::bind(
callOneThread, &queue, boost::ref(done)));
476 : id(0), queue(_queue) {
477 condition_sync.store(
true);
478 condition_one.store(
false);
479 condition_stop.store(
false);
495 : condition_object(_condition_object), id(_id)
500 condition_object->condition_one.store(
false);
510 while(!condition_stop.load())
512 if(condition_sync.load() && queue->isEmpty())
514 condition_one.store(
true);
516 queue->addCallback(boost::make_shared<RaceConditionCallback>(
this, &
id),
id);
518 boost::this_thread::sleep(boost::posix_time::microseconds(1));
528 for(
unsigned int i = 0; i < 1000000; ++i)
547 int main(
int argc,
char** argv)
549 testing::InitGoogleTest(&argc, argv);
550 return RUN_ALL_TESTS();