本文整理汇总了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;
}
}
//.........这里部分代码省略.........
示例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();
}
示例3: getEnv
JNIEnv* getEnv() noexcept
{
JNIEnv* env = androidJNIEnv.get();
jassert (env != nullptr);
return env;
}
示例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));
}
示例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;
}
示例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();
}
示例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 );
}
示例8: wrapperType
AudioProcessor::AudioProcessor()
: wrapperType (wrapperTypeBeingCreated.get()),
playHead (nullptr),
sampleRate (0),
blockSize (0),
numInputChannels (0),
numOutputChannels (0),
latencySamples (0),
suspended (false),
nonRealtime (false)
{
}
示例9: setEnv
void setEnv (JNIEnv* env) noexcept
{
androidJNIEnv.get() = env;
}
示例10: StackChecker
StackChecker() {
checker.set(this);
}