本文整理汇总了C++中ObjectPool::Wait方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectPool::Wait方法的具体用法?C++ ObjectPool::Wait怎么用?C++ ObjectPool::Wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPool
的用法示例。
在下文中一共展示了ObjectPool::Wait方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(ObjectPoolTest, MovableObjectPool) {
ObjectPool<int> to;
// Verify a move works correctly when an object has been checked out:
{
ObjectPool<int> from;
auto original = from.Wait();
to = std::move(from);
}
// Now verify that the pooled object returned home to the right place:
ASSERT_EQ(1UL, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}
示例2: pool
TEST_F(ObjectPoolTest, EmptyPoolIssuance) {
ObjectPool<int> pool;
// Create the thread which will hold the shared pointer for awhile:
AutoRequired<HoldsSharedPtrThenQuits> thread;
pool(thread->m_ptr);
std::weak_ptr<int> ptrWeak = thread->m_ptr;
ASSERT_FALSE(ptrWeak.expired()) << "Object pool failed to issue a shared pointer as expected";
// Verify properties now that we've zeroized the limit:
pool.SetOutstandingLimit(0);
EXPECT_ANY_THROW(pool.SetOutstandingLimit(1)) << "An attempt to alter a zeroized outstanding limit did not throw an exception as expected";
EXPECT_ANY_THROW(pool.Wait()) << "An attempt to obtain an element on an empty pool did not throw an exception as expected";
// Now see if we can delay for the thread to back out:
m_create->Initiate();
pool.Rundown();
// Verify that it got released as expected:
ASSERT_TRUE(ptrWeak.expired()) << "Not all shared pointers issued by an object pool expired in a timely fashion";
}
示例3: AutoCurrentContext
TEST_F(ObjectPoolTest, MovableObjectPoolAysnc) {
static const size_t sc_count = 10000;
ObjectPool<int> from;
{
// Issue a zillion objects from the from pool:
std::vector<std::shared_ptr<int>> objs;
for(size_t i = sc_count; i--;)
objs.push_back(from.Wait());
// Make a thread, let it hold these objects while we move its pool:
*AutoRequired<CoreThread>() += [objs] {};
}
// Kick off threads, then immediately and asynchronously move the pool:
AutoCurrentContext()->Initiate();
ObjectPool<int> to = std::move(from);
// Shutdown time:
AutoCurrentContext()->SignalShutdown(true);
// Verify that new pool got all of the objects:
ASSERT_EQ(sc_count, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}