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

C++ ThreadLocalValue类代码示例

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

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



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

示例1: defined

namespace mongo {

    Client* Client::syncThread;
    mongo::mutex Client::clientsMutex("clientsMutex");
    set<Client*> Client::clients; // always be in clientsMutex when manipulating this
    boost::thread_specific_ptr<Client> currentClient;

#if defined(_DEBUG)
    struct StackChecker;
    ThreadLocalValue<StackChecker *> checker;

    struct StackChecker { 
        enum { SZ = 256 * 1024 };
        char buf[SZ];
        StackChecker() { 
            checker.set(this);
        }
        void init() { 
            memset(buf, 42, sizeof(buf)); 
        }
        static void check(const char *tname) { 
            StackChecker *sc = checker.get();
            const char *p = sc->buf;
            int i = 0;
            for( ; i < SZ; i++ ) { 
                if( p[i] != 42 )
                    break;
            }
            log() << "thread " << tname << " stack usage was " << SZ-i << " bytes" << endl;
            wassert( i > 16000 );
        }
    };
#endif

    /* each thread which does db operations has a Client object in TLS.
       call this when your thread starts.
    */
    Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
#if defined(_DEBUG)
        { 
            if( sizeof(void*) == 8 ) {
                StackChecker sc;
                sc.init();
            }
        }
#endif
        assert( currentClient.get() == 0 );
        Client *c = new Client(desc, mp);
        currentClient.reset(c);
        mongo::lastError.initThread();
        return *c;
    }

    Client::Client(const char *desc, AbstractMessagingPort *p) :
        _context(0),
        _shutdown(false),
        _desc(desc),
        _god(0),
        _lastOp(0),
        _mp(p) {
        _connectionId = setThreadName(desc);
        _curOp = new CurOp( this );
        scoped_lock bl(clientsMutex);
        clients.insert(this);
    }

    Client::~Client() {
        _god = 0;

        if ( _context )
            error() << "Client::~Client _context should be null but is not; client:" << _desc << endl;

        if ( ! _shutdown ) {
            error() << "Client::shutdown not called: " << _desc << endl;
        }

        scoped_lock bl(clientsMutex);
        if ( ! _shutdown )
            clients.erase(this);
        delete _curOp;
    }

    bool Client::shutdown() {
#if defined(_DEBUG)
        { 
            if( sizeof(void*) == 8 ) {
                StackChecker::check( desc() );
            }
        }
#endif
        _shutdown = true;
        if ( inShutdown() )
            return false;
        {
            scoped_lock bl(clientsMutex);
            clients.erase(this);
            if ( isSyncThread() ) {
                syncThread = 0;
            }
        }
//.........这里部分代码省略.........
开发者ID:andradeandrey,项目名称:mongo,代码行数:101,代码来源:client.cpp


示例2: wrapperType

AudioProcessor::AudioProcessor()
    : wrapperType (wrapperTypeBeingCreated.get()),
      playHead (nullptr),
      sampleRate (0),
      blockSize (0),
      latencySamples (0),
     #if JUCE_DEBUG
      textRecursionCheck (false),
     #endif
      suspended (false),
      nonRealtime (false),
      processingPrecision (singlePrecision)
{
  #if ! JucePlugin_IsMidiEffect
   #ifdef JucePlugin_PreferredChannelConfigurations
    const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
   #else
    const short channelConfigs[][2] = { {2, 2} };
   #endif
    int numChannelConfigs = sizeof (channelConfigs) / sizeof (*channelConfigs);

    if (numChannelConfigs > 0)
    {
       #if ! JucePlugin_IsSynth
        busArrangement.inputBuses.add  (AudioProcessorBus ("Input",    AudioChannelSet::canonicalChannelSet (channelConfigs[0][0])));
       #endif
        busArrangement.outputBuses.add (AudioProcessorBus ("Output",   AudioChannelSet::canonicalChannelSet (channelConfigs[0][1])));
    }
  #endif

    updateSpeakerFormatStrings();
}
开发者ID:GRIS-UdeM,项目名称:Octogris,代码行数:32,代码来源:juce_AudioProcessor.cpp


示例3: getEnv

JNIEnv* getEnv() noexcept
{
    JNIEnv* env = androidJNIEnv.get();
    jassert (env != nullptr);

    return env;
}
开发者ID:0x4d52,项目名称:JUCE,代码行数:7,代码来源:juce_android_SystemStats.cpp


示例4: JSRand

BSONObj JSRand(const BSONObj& a, void* data) {
    uassert(12519, "rand accepts no arguments", a.nFields() == 0);
    unsigned r;
#if !defined(_WIN32)
    r = rand_r(&_randomSeed.getRef());
#else
    r = rand();
#endif
    return BSON("" << double(r) / (double(RAND_MAX) + 1));
}
开发者ID:Andiry,项目名称:mongo,代码行数:10,代码来源:shell_utils.cpp


示例5: JSSrand

        BSONObj JSSrand( const BSONObj &a, void* data ) {
            uassert( 12518, "srand requires a single numeric argument",
                     a.nFields() == 1 && a.firstElement().isNumber() );
#if !defined(_WIN32)
            _randomSeed.set( static_cast< unsigned int >( a.firstElement().numberLong() ) ); // grab least significant digits
#else
            srand( static_cast< unsigned int >( a.firstElement().numberLong() ) );
#endif
            return undefinedReturn;
        }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:10,代码来源:shell_utils.cpp


示例6: wrapperType

AudioProcessor::AudioProcessor()
    : wrapperType (wrapperTypeBeingCreated.get()),
      playHead (nullptr),
      currentSampleRate (0),
      blockSize (0),
      latencySamples (0),
     #if JUCE_DEBUG
      textRecursionCheck (false),
     #endif
      suspended (false),
      nonRealtime (false),
      processingPrecision (singlePrecision)
{
   #ifdef JucePlugin_PreferredChannelConfigurations
    const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations };
   #else
    const short channelConfigs[][2] = { {2, 2} };
   #endif

   #ifdef JucePlugin_MaxNumInputChannels
    const int maxInChannels = JucePlugin_MaxNumInputChannels;
   #else
    const int maxInChannels = std::numeric_limits<int>::max();
   #endif
    ignoreUnused (maxInChannels);

   #ifdef JucePlugin_MaxNumOutputChannels
    const int maxOutChannels = JucePlugin_MaxNumOutputChannels;
   #else
    const int maxOutChannels = std::numeric_limits<int>::max();
   #endif
    ignoreUnused (maxOutChannels);

 #if ! JucePlugin_IsMidiEffect
//   #if ! JucePlugin_IsSynth
    const int numInChannels = jmin (maxInChannels, (int) channelConfigs[0][0]);

    if (numInChannels > 0)
        busArrangement.inputBuses.add  (AudioProcessorBus ("Input",  AudioChannelSet::canonicalChannelSet (numInChannels)));
//   #endif

    const int numOutChannels = jmin (maxOutChannels, (int) channelConfigs[0][1]);
    if (numOutChannels > 0)
        busArrangement.outputBuses.add (AudioProcessorBus ("Output", AudioChannelSet::canonicalChannelSet (numOutChannels)));

  #ifdef JucePlugin_PreferredChannelConfigurations
//   #if ! JucePlugin_IsSynth
    AudioProcessor::setPreferredBusArrangement (true,  0, AudioChannelSet::stereo());
//   #endif
    AudioProcessor::setPreferredBusArrangement (false, 0, AudioChannelSet::stereo());
  #endif
 #endif
    updateSpeakerFormatStrings();
}
开发者ID:pingdynasty,项目名称:OwlSim,代码行数:54,代码来源:juce_AudioProcessor.cpp


示例7: check

 static void check(const char *tname) { 
     StackChecker *sc = checker.get();
     const char *p = sc->buf;
     int i = 0;
     for( ; i < SZ; i++ ) { 
         if( p[i] != 42 )
             break;
     }
     log() << "thread " << tname << " stack usage was " << SZ-i << " bytes" << endl;
     wassert( i > 16000 );
 }
开发者ID:andradeandrey,项目名称:mongo,代码行数:11,代码来源:client.cpp


示例8: wrapperType

AudioProcessor::AudioProcessor()
    : wrapperType (wrapperTypeBeingCreated.get()),
      playHead (nullptr),
      sampleRate (0),
      blockSize (0),
      numInputChannels (0),
      numOutputChannels (0),
      latencySamples (0),
      suspended (false),
      nonRealtime (false)
{
}
开发者ID:LeapMotionRV,项目名称:Badaboum,代码行数:12,代码来源:juce_AudioProcessor.cpp


示例9: setEnv

void setEnv (JNIEnv* env) noexcept
{
    androidJNIEnv.get() = env;
}
开发者ID:0x4d52,项目名称:JUCE,代码行数:4,代码来源:juce_android_SystemStats.cpp


示例10: StackChecker

 StackChecker() { 
     checker.set(this);
 }
开发者ID:andradeandrey,项目名称:mongo,代码行数:3,代码来源:client.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ ThreadMessageCallback类代码示例发布时间:2022-05-31
下一篇:
C++ ThreadLocalJNIEnvHolder类代码示例发布时间: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