本文整理汇总了C++中ThreadLocal类的典型用法代码示例。如果您正苦于以下问题:C++ ThreadLocal类的具体用法?C++ ThreadLocal怎么用?C++ ThreadLocal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadLocal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MOZ_ASSERT
// static
uint64_t
IDBRequest::NextSerialNumber()
{
BackgroundChildImpl::ThreadLocal* threadLocal =
BackgroundChildImpl::GetThreadLocalForCurrentThread();
MOZ_ASSERT(threadLocal);
ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
MOZ_ASSERT(idbThreadLocal);
return idbThreadLocal->NextRequestSN();
}
示例2: operator
inline void operator()()
{
staticThinggy = new Thinggy;
staticThreadLocal.set(staticThinggy);
waiting = true;
gate.Set();
waiter.Wait();
waiting = false;
threadLocalHadValue = staticThreadLocal.get() != NULL;
gate.Set();
}
示例3: MOZ_ASSERT
// static
IDBTransaction*
IDBTransaction::GetCurrent()
{
using namespace mozilla::ipc;
MOZ_ASSERT(BackgroundChild::GetForCurrentThread());
BackgroundChildImpl::ThreadLocal* threadLocal =
BackgroundChildImpl::GetThreadLocalForCurrentThread();
MOZ_ASSERT(threadLocal);
ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
MOZ_ASSERT(idbThreadLocal);
return idbThreadLocal->GetCurrentTransaction();
}
示例4: TouchIdleConn
void ArdbServer::TouchIdleConn(Channel* ch)
{
static ThreadLocal<IdleConnManager> kLocalIdleConns;
uint64 now = get_current_epoch_millis();
IdleConn conn;
conn.conn_id = ch->GetID();
conn.ts = now;
IdleConnManager& m = kLocalIdleConns.GetValue();
if (m.timer_id == -1)
{
m.serv = &(ch->GetService());
m.maxIdleTime = m_cfg.timeout * 1000;
m.lru.SetMaxCacheSize(m_cfg.max_clients);
m.timer_id = ch->GetService().GetTimer().Schedule(&m, 1, 5,
SECONDS);
}
IdleConn tmp;
m.lru.Insert(conn.conn_id, conn, tmp);
}
示例5: TEST
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();
}
示例6: TestTLS
namespace thread_tls2
{
class TestTLS
{
public:
TestTLS()
{
num = -1;
cout << "TestTLS : [" << this << "] " << num << "\n";
}
~TestTLS()
{
cout << "~TestTLS : [" << this << "] " << num << "\n";
}
void set(int n) { num = n; }
void plus(int n) { num += n; }
void print() { cout << "print : [" << this << "] " << num << "\n"; }
private:
int num;
};
ThreadLocal<TestTLS> g_tls;
void testTLS(int i)
{
g_tls->plus(i);
g_tls->print();
}
void test_threadtls()
{
g_tls->set(10);
g_tls->print();
Thread t1(std::bind(testTLS, 23));
t1.join();
Thread t2(std::bind(testTLS, 100));
t2.join();
g_tls->print();
}
}
示例7: MOZ_ASSERT
//.........这里部分代码省略.........
// aPrincipal is passed inconsistently, so even when we are already on
// the main thread, we may have been passed a null aPrincipal.
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(principalInfo);
if (principal) {
nsAutoString addonId;
Unused << NS_WARN_IF(NS_FAILED(principal->GetAddonId(addonId)));
isAddon = !addonId.IsEmpty();
}
}
if (isInternal) {
// Chrome privilege and internal origins always get persistent storage.
persistenceType = PERSISTENCE_TYPE_PERSISTENT;
} else if (isAddon || DOMPrefs::IndexedDBStorageOptionsEnabled()) {
persistenceType = PersistenceTypeFromStorage(aStorageType);
} else {
persistenceType = PERSISTENCE_TYPE_DEFAULT;
}
DatabaseMetadata& metadata = commonParams.metadata();
metadata.name() = aName;
metadata.persistenceType() = persistenceType;
FactoryRequestParams params;
if (aDeleting) {
metadata.version() = 0;
params = DeleteDatabaseRequestParams(commonParams);
} else {
metadata.version() = version;
params = OpenDatabaseRequestParams(commonParams);
}
if (!mBackgroundActor) {
BackgroundChildImpl::ThreadLocal* threadLocal =
BackgroundChildImpl::GetThreadLocalForCurrentThread();
nsAutoPtr<ThreadLocal> newIDBThreadLocal;
ThreadLocal* idbThreadLocal;
if (threadLocal && threadLocal->mIndexedDBThreadLocal) {
idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
} else {
nsCOMPtr<nsIUUIDGenerator> uuidGen =
do_GetService("@mozilla.org/uuid-generator;1");
MOZ_ASSERT(uuidGen);
nsID id;
MOZ_ALWAYS_SUCCEEDS(uuidGen->GenerateUUIDInPlace(&id));
newIDBThreadLocal = idbThreadLocal = new ThreadLocal(id);
}
PBackgroundChild* backgroundActor =
BackgroundChild::GetOrCreateForCurrentThread();
if (NS_WARN_IF(!backgroundActor)) {
IDB_REPORT_INTERNAL_ERR();
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
return nullptr;
}
{
BackgroundFactoryChild* actor = new BackgroundFactoryChild(this);
// Set EventTarget for the top-level actor.
// All child actors created later inherit the same event target.
backgroundActor->SetEventTargetForActor(actor, EventTarget());
示例8: secureRandom
void Random::secureRandom(void* data, size_t size) {
static ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
bufferedRandomDevice->get(data, size);
}
示例9: test_threadlocalstroage
void test_threadlocalstroage()
{
g_tls->set(10);
g_tls->print();
Thread t1(std::bind(testTLS, 23));
t1.join();
Thread t2(std::bind(testTLS, 100));
t2.join();
g_tls->print();
}
示例10: snprintf
const string& Thread::getTidString()
{
if (t_tidstring.value().empty())
{
Thread::ThreadHandle ret_tid;
ret_tid = ::pthread_self();
t_tid.value() = ret_tid;
char buf[32] = {0};
snprintf(buf, sizeof(buf), "%ll", (uint64_t)ret_tid);
t_tidstring.value() = buf;
}
return t_tidstring;
}
示例11: CoroutineManager
//static
CoroutineManager& CoroutineManager::getInstance()
{
CoroutineManager *pInstance = coroutineManagerInstance;
if(!pInstance) {
pInstance = new CoroutineManager();
coroutineManagerInstance.set(pInstance);
}
return *pInstance;
}
示例12:
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();
}
示例13: 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;
}
示例14: Startup
static void Startup()
{
/* We can tolerate init() failing.
The if block turns off warn_unused_result. */
if (!sTlsKey.init()) {}
}
示例15: get
int get() { return value.get(); }