本文整理汇总了C++中ThreadLocal::get方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadLocal::get方法的具体用法?C++ ThreadLocal::get怎么用?C++ ThreadLocal::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadLocal
的用法示例。
在下文中一共展示了ThreadLocal::get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void ThreadLocalTester::run() {
// Wait until finished is true
while (!isStopping()) {
Command command = this->command;
switch (Command(this->command)) {
case SETDATA:
data.set(setData);
// Reset to no command
this->command = NONE;
break;
case GETDATA:
getData = *data.get();
// Reset to no command
this->command = NONE;
break;
case NONE:
// Sleep for 30 ms
std::this_thread::sleep_for(std::chrono::milliseconds(30));
break;
}
}
}
示例2:
virtual RequestHandler *createRequestHandler() {
s_rpc_request_handler->setServerInfo(m_serverInfo);
if (s_rpc_request_handler->needReset() ||
s_rpc_request_handler->incRequest() > m_serverInfo->getMaxRequest()) {
s_rpc_request_handler.reset();
s_rpc_request_handler->setServerInfo(m_serverInfo);
s_rpc_request_handler->incRequest();
}
return s_rpc_request_handler.get();
}
示例3: testAccessors
void ThreadLocalTest::testAccessors()
{
ThreadLocal<TLTestStruct> ts;
ts->i = 100;
ts->s = "foo";
assert ((*ts).i == 100);
assert ((*ts).s == "foo");
assert (ts.get().i == 100);
assert (ts.get().s == "foo");
}
示例4:
// Tests that the threadlocal data is unique between threads
TEST(TestThreadLocal, MainThread) {
// Initialize ThreadLocal storage
ThreadLocal<int> data;
// Set value to 123
data.set(123);
// Confirm that it equals
ASSERT_EQ(*data.get(), 123);
}
示例5: operator
inline void operator()()
{
staticThinggy = new Thinggy;
staticThreadLocal.set(staticThinggy);
waiting = true;
gate.Set();
waiter.Wait();
waiting = false;
threadLocalHadValue = staticThreadLocal.get() != NULL;
gate.Set();
}
示例6: t
TEST(TestThreadLocal, Simple)
{
GlobalThreadLocal runnable;
thread t(runnable);
gate.Wait();
EXPECT_TRUE(runnable.waiting);
EXPECT_TRUE(staticThinggy != NULL);
EXPECT_TRUE(staticThreadLocal.get() == NULL);
waiter.Set();
gate.Wait();
EXPECT_TRUE(runnable.threadLocalHadValue);
EXPECT_TRUE(!destructorCalled);
delete staticThinggy;
EXPECT_TRUE(destructorCalled);
cleanup();
}
示例7: autoLock
BackgroundHangThread*
BackgroundHangThread::FindThread()
{
if (sTlsKey.initialized()) {
// Use TLS if available
return sTlsKey.get();
}
// If TLS is unavailable, we can search through the thread list
RefPtr<BackgroundHangManager> manager(BackgroundHangManager::sInstance);
MOZ_ASSERT(manager, "Creating BackgroundHangMonitor after shutdown");
PRThread* threadID = PR_GetCurrentThread();
// Lock thread list for traversal
MonitorAutoLock autoLock(manager->mLock);
for (BackgroundHangThread* thread = manager->mHangThreads.getFirst();
thread; thread = thread->getNext()) {
if (thread->mThreadID == threadID) {
return thread;
}
}
// Current thread is not initialized
return nullptr;
}
示例8: secureRandom
void Random::secureRandom(void* data, size_t size) {
static ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
bufferedRandomDevice->get(data, size);
}
示例9: get
int get() { return value.get(); }
示例10: increment
void increment() { value.set(value.get() + 1); }
示例11:
NestedDiagnosticContext& NestedDiagnosticContext::current()
{
static ThreadLocal<NestedDiagnosticContext> ndc;
return ndc.get();
}
示例12:
TEST(ThreadLocalStorage, NotSetReturnsNull) {
static ThreadLocal<int> number;
EXPECT_EQ(nullptr, number.get());
}
示例13:
TEST(ThreadLocal, Unthreaded)
{
EXPECT_EQ(sVar.get(), 0);
sVar = 10;
EXPECT_EQ(sVar.get(), 10);
}