• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ThreadLocal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ThreadLocal的典型用法代码示例。如果您正苦于以下问题:C++ ThreadLocal类的具体用法?C++ ThreadLocal怎么用?C++ ThreadLocal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ThreadLocal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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

TEST(ThreadLocalStorage, NotSetReturnsNull) {
    static ThreadLocal<int> number;

    EXPECT_EQ(nullptr, number.get());
}
开发者ID:AnithaGorli,项目名称:mapbox-gl-native,代码行数:5,代码来源:thread_local.cpp


示例10: TEST

TEST(ThreadLocal, Unthreaded)
{
  EXPECT_EQ(sVar.get(), 0);
  sVar = 10;
  EXPECT_EQ(sVar.get(), 10);
}
开发者ID:alliedmodders,项目名称:amtl,代码行数:6,代码来源:test-threadlocal-unthreaded.cpp


示例11: if


//.........这里部分代码省略.........
        m_server->stop();
        m_server->waitForEnd();
    }
private:
    ServerPtr m_server;
};

///////////////////////////////////////////////////////////////////////////////
// DanglingPageServer: same as LibEventServer

class DanglingPageServer : public SatelliteServer {
public:
    DanglingPageServer(SatelliteServerInfoPtr info) {
        m_server = ServerPtr
                   (new TypedServer<LibEventServer, HttpRequestHandler>
                    (RuntimeOption::ServerIP, info->getPort(), info->getThreadCount(),
                     info->getTimeoutSeconds()));
    }

    virtual void start() {
        m_server->start();
    }
    virtual void stop() {
        m_server->stop();
        m_server->waitForEnd();
    }
private:
    ServerPtr m_server;
};

///////////////////////////////////////////////////////////////////////////////
// RPCServer: LibEventServer + RPCRequestHandler

static ThreadLocal<RPCRequestHandler> s_rpc_request_handler;

class RPCServerImpl : public LibEventServer {
public:
    RPCServerImpl(const std::string &address, SatelliteServerInfoPtr info)
        : LibEventServer(address, info->getPort(), info->getThreadCount(),
                         info->getTimeoutSeconds()),
          m_serverInfo(info) {
    }

    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();
    }

    virtual void releaseRequestHandler(RequestHandler *handler) {
        // do nothing
    }

    virtual void onThreadExit(RequestHandler *handler) {
        s_rpc_request_handler.reset();
    }

private:
    SatelliteServerInfoPtr m_serverInfo;
};
开发者ID:brion,项目名称:hiphop-php,代码行数:66,代码来源:satellite_server.cpp


示例12:

NestedDiagnosticContext& NestedDiagnosticContext::current()
{
	static ThreadLocal<NestedDiagnosticContext> ndc;
	return ndc.get();
}
开发者ID:RangelReale,项目名称:sandbox,代码行数:5,代码来源:NestedDiagnosticContext.cpp


示例13: luaLoadLib

        luaLoadLib(m_lua, "cjson", luaopen_cjson);
        luaLoadLib(m_lua, "struct", luaopen_struct);
        luaLoadLib(m_lua, "cmsgpack", luaopen_cmsgpack);
        return 0;
    }

    int LUAInterpreter::RemoveUnsupportedFunctions()
    {
        lua_pushnil(m_lua);
        lua_setglobal(m_lua, "loadfile");
        return 0;
    }

    static ThreadLocal<Context*> g_local_ctx;
    static ThreadLocal<LuaExecContext*> g_lua_exec_ctx;

    struct LuaExecContextGuard
    {
            LuaExecContext ctx;
            LuaExecContextGuard()
            {
                g_lua_exec_ctx.SetValue(&ctx);
            }
            ~LuaExecContextGuard()
            {
                g_lua_exec_ctx.SetValue(NULL);
            }
    };

    int LUAInterpreter::CallArdb(lua_State *lua, bool raise_error)
开发者ID:masterve,项目名称:test,代码行数:30,代码来源:lua_scripting.cpp


示例14: ThreadLocalVariables

	ThreadLocalVariables() : canceled(false){
		value.set(0);
	}
开发者ID:elmagroud00,项目名称:Experiments,代码行数:3,代码来源:ThreadLocalVariables.cpp


示例15: MOZ_ASSERT

already_AddRefed<IDBOpenDBRequest>
IDBFactory::OpenInternal(JSContext* aCx,
                         nsIPrincipal* aPrincipal,
                         const nsAString& aName,
                         const Optional<uint64_t>& aVersion,
                         const Optional<StorageType>& aStorageType,
                         bool aDeleting,
                         ErrorResult& aRv)
{
    MOZ_ASSERT(mWindow || mOwningObject);
    MOZ_ASSERT_IF(!mWindow, !mPrivateBrowsingMode);

    CommonFactoryRequestParams commonParams;
    commonParams.privateBrowsingMode() = mPrivateBrowsingMode;

    PrincipalInfo& principalInfo = commonParams.principalInfo();

    if (aPrincipal) {
        if (!NS_IsMainThread()) {
            MOZ_CRASH("Figure out security checks for workers!");
        }
        MOZ_ASSERT(nsContentUtils::IsCallerChrome());

        if (NS_WARN_IF(NS_FAILED(PrincipalToPrincipalInfo(aPrincipal,
                                 &principalInfo)))) {
            IDB_REPORT_INTERNAL_ERR();
            aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
            return nullptr;
        }

        if (principalInfo.type() != PrincipalInfo::TContentPrincipalInfo &&
                principalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) {
            IDB_REPORT_INTERNAL_ERR();
            aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
            return nullptr;
        }
    } else {
        principalInfo = *mPrincipalInfo;
    }

    uint64_t version = 0;
    if (!aDeleting && aVersion.WasPassed()) {
        if (aVersion.Value() < 1) {
            aRv.ThrowTypeError<MSG_INVALID_VERSION>();
            return nullptr;
        }
        version = aVersion.Value();
    }

    // Nothing can be done here if we have previously failed to create a
    // background actor.
    if (mBackgroundActorFailed) {
        IDB_REPORT_INTERNAL_ERR();
        aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
        return nullptr;
    }

    PersistenceType persistenceType;

    if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
        // Chrome privilege always gets persistent storage.
        persistenceType = PERSISTENCE_TYPE_PERSISTENT;
    } else {
        persistenceType = PersistenceTypeFromStorage(aStorageType);
    }

    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 && mPendingRequests.IsEmpty()) {
        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);
        }

        if (PBackgroundChild* actor = BackgroundChild::GetForCurrentThread()) {
//.........这里部分代码省略.........
开发者ID:leplatrem,项目名称:gecko-dev,代码行数:101,代码来源:IDBFactory.cpp


示例16: 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


示例17: 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


示例18: 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


示例19:

 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ThreadLocalJNIEnvHolder类代码示例发布时间:2022-05-31
下一篇:
C++ ThreadInfo类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap