当前位置: 首页>>代码示例>>C++>>正文


C++ ThreadLocal类代码示例

本文整理汇总了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();
}
开发者ID:Acidburn0zzz,项目名称:tor-browser,代码行数:13,代码来源:IDBRequest.cpp

示例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();
  }
开发者ID:Foozle303,项目名称:xbmc,代码行数:12,代码来源:TestThreadLocal.cpp

示例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();
}
开发者ID:SJasoria,项目名称:gecko-dev,代码行数:17,代码来源:IDBTransaction.cpp

示例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);
	}
开发者ID:Ivasek,项目名称:ardb,代码行数:20,代码来源:clients.cpp

示例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();
}
开发者ID:0xheart0,项目名称:xbmc,代码行数:17,代码来源:TestThreadLocal.cpp

示例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();
    }
}
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:42,代码来源:ThreadLocal_test.cpp

示例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());
开发者ID:artines1,项目名称:gecko-dev,代码行数:67,代码来源:IDBFactory.cpp

示例8: secureRandom

void Random::secureRandom(void* data, size_t size) {
  static ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
  bufferedRandomDevice->get(data, size);
}
开发者ID:1Hgm,项目名称:folly,代码行数:4,代码来源:Random.cpp

示例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();
}
开发者ID:Redi0,项目名称:CppLanguagePrograms,代码行数:13,代码来源:Test_Thread.cpp

示例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;
}
开发者ID:wenwuge,项目名称:EasyLib,代码行数:14,代码来源:Thread.cpp

示例11: CoroutineManager

//static
CoroutineManager& CoroutineManager::getInstance()
{
	CoroutineManager *pInstance = coroutineManagerInstance;
	if(!pInstance) {
		pInstance = new CoroutineManager();
		coroutineManagerInstance.set(pInstance);
	}
	return *pInstance;
}
开发者ID:unkstar,项目名称:skuld,代码行数:10,代码来源:coroutine_p.cpp

示例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();
 }
开发者ID:brion,项目名称:hiphop-php,代码行数:10,代码来源:satellite_server.cpp

示例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;
}
开发者ID:jpfreire,项目名称:mozilla-central,代码行数:23,代码来源:BackgroundHangMonitor.cpp

示例14: Startup

 static void Startup()
 {
   /* We can tolerate init() failing.
      The if block turns off warn_unused_result. */
   if (!sTlsKey.init()) {}
 }
开发者ID:jpfreire,项目名称:mozilla-central,代码行数:6,代码来源:BackgroundHangMonitor.cpp

示例15: get

	int get() { return value.get(); }
开发者ID:elmagroud00,项目名称:Experiments,代码行数:1,代码来源:ThreadLocalVariables.cpp


注:本文中的ThreadLocal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。