本文整理汇总了C++中QThreadStorage::localData方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadStorage::localData方法的具体用法?C++ QThreadStorage::localData怎么用?C++ QThreadStorage::localData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThreadStorage
的用法示例。
在下文中一共展示了QThreadStorage::localData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: localData
void tst_QThreadStorage::localData()
{
QThreadStorage<Pointer*> pointers;
Pointer *p = new Pointer;
QVERIFY(!pointers.hasLocalData());
pointers.setLocalData(p);
QVERIFY(pointers.hasLocalData());
QCOMPARE(pointers.localData(), p);
pointers.setLocalData(0);
QCOMPARE(pointers.localData(), (Pointer *)0);
QVERIFY(!pointers.hasLocalData());
}
示例2: connIdMsgHandler
void RpcConnection::connIdMsgHandler(QtMsgType /*type*/, const char* msg)
{
if (connId.hasLocalData()) {
QString newMsg(*connId.localData());
newMsg.append(msg);
newMsg.replace(QChar('\n'), QString("\n").append(*connId.localData()));
fprintf(stderr, "%s\n", qPrintable(newMsg));
fflush(stderr);
return;
}
fprintf(stderr, "%s\n", msg);
fflush(stderr);
}
示例3: yieldHelper
void Coroutine::yieldHelper(Status stopStatus)
{
Coroutine *stoppingCoroutine = *qt_currentCoroutine.localData();
Q_ASSERT(stoppingCoroutine);
Q_ASSERT(stoppingCoroutine->_status == Running);
stoppingCoroutine->_status = stopStatus;
Coroutine *continuingCoroutine = stoppingCoroutine->_caller;
Q_ASSERT(continuingCoroutine);
stoppingCoroutine->_caller = 0;
*qt_currentCoroutine.localData() = continuingCoroutine;
switchStack(continuingCoroutine->_stackPointer, &stoppingCoroutine->_stackPointer);
}
示例4: cont
/*!
Passes control to the coroutine.
The coroutine will run until it terminates or is stopped by a call to yield().
Returns whether it can be continued again.
Calling this function is only valid if in the NotStarted or Stopped state.
\sa yield()
*/
bool Coroutine::cont()
{
Q_ASSERT(_status == NotStarted || _status == Stopped);
Q_ASSERT(!_caller);
if (!_stackPointer)
createStack();
_status = Running;
_caller = *qt_currentCoroutine.localData();
*qt_currentCoroutine.localData() = this;
switchStack(_stackPointer, &_caller->_stackPointer);
return _status != Terminated;
}
示例5: lock
QSharedPointer<RDFGraphCache> TrackerService::getRDFGraphCache(bool persistent)
{
QSharedPointer<RDFGraphCache> ret;
if(!tracker_tls.hasLocalData()
// check if the weak pointer in local data is valid and store it to ret
|| !(ret = *tracker_tls.localData()))
{
static bool initialized = false;
if(!initialized)
{
QMutexLocker lock(&tracker_global_lock_g);
if(!initialized)
initialized = initializeTrackerEnvironment();
}
QSharedPointer<TrackerService> tracker
= QSharedCreator<TrackerService>::create();
tracker->setParent( tracker.toWeakRef() );
ret = QSharedCreator<RDFGraphCache>::create(tracker);
tracker_tls.setLocalData(new QWeakPointer<RDFGraphCache>(ret));
}
if(persistent && !tracker_persistent_tls.hasLocalData())
tracker_persistent_tls.setLocalData
(new TLSDestroyer<QSharedPointer<RDFGraphCache> >(ret));
return ret;
}
示例6: getInstance
OAuthNetworkAccessManager* OAuthNetworkAccessManager::getInstance() {
if (!oauthNetworkAccessManagers.hasLocalData()) {
oauthNetworkAccessManagers.setLocalData(new OAuthNetworkAccessManager());
}
return oauthNetworkAccessManagers.localData();
}
示例7: IconvProcessor
IconvProcessor & ucs4ToUtf8()
{
static QThreadStorage<IconvProcessor *> processor;
if (!processor.hasLocalData())
processor.setLocalData(new IconvProcessor("UTF-8", ucs4_codeset));
return *processor.localData();
}
示例8: getTileImage
ImagePtr PixelStreamUpdater::getTileImage(const uint tileIndex,
const deflect::View view) const
{
// guard against frame swap during asynchronous readings
const QReadLocker frameLock(&_frameMutex);
try
{
if (!_frameLeftOrMono)
throw std::runtime_error("No frames yet");
if (tileIndex >= _perTileLock->size())
throw std::runtime_error("Tile index is invalid");
// prevent double-decoding of a tile that could occur unexpectedly when
// resizing the stream window
std::lock_guard<std::mutex> lock{_perTileLock->at(tileIndex)};
const bool rightEye = view == deflect::View::right_eye;
const bool rightFrame = rightEye && !_frameRight->tiles.empty();
const auto& processor = rightFrame ? _processRight : _processorLeft;
// turbojpeg handles need to be per thread, and this function may be
// called from multiple threads
static QThreadStorage<deflect::server::TileDecoder> tileDecoders;
return processor->getTileImage(tileIndex, tileDecoders.localData());
}
catch (const std::runtime_error& e)
{
print_log(LOG_ERROR, LOG_STREAM, "Error decoding stream tile: '%s'",
e.what());
std::rethrow_exception(std::current_exception());
}
}
示例9: removeFromCache
void removeFromCache(const QString &key)
//! [8] //! [9]
{
if (!caches.hasLocalData())
return;
caches.localData().remove(key);
}
示例10: trackerRelease
RDFServicePtr trackerRelease()
{
if(!tracker_persistent_tls.hasLocalData())
return RDFServicePtr();
RDFServicePtr ret = *tracker_persistent_tls.localData();
tracker_persistent_tls.setLocalData(0);
return ret;
}
示例11: cacheObject
void cacheObject(const QString &key, SomeClass *object)
//! [7] //! [8]
{
if (!caches.hasLocalData())
caches.setLocalData(new QCache<QString, SomeClass>);
caches.localData()->insert(key, object);
}
示例12: currentContext
/*!
Returns the last context which called makeCurrent. This function is thread aware.
*/
const QPlatformGLContext* QPlatformGLContext::currentContext()
{
QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData();
if(threadContext) {
return threadContext->context;
}
return 0;
}
示例13:
static inline Cache *cache()
{
Cache *rv = statCache.localData();
if (!rv) {
rv = new Cache;
statCache.setLocalData(rv);
}
return rv;
}
示例14: defer
void defer(const VoidFunc & function)
{
// create a helper in this thread if not yet created
if( ! deferHelpers.hasLocalData()) {
deferHelpers.setLocalData( new DeferHelper);
}
// queue up the function execution in this same thread
// (because the object was created in this same thread)
deferHelpers.localData()-> queue( function);
}
示例15:
QctThreadLocalData *
QctThreadLocalData::instance()
{
static QThreadStorage<QctThreadLocalData *> storage;
QctThreadLocalData *data = storage.localData();
if (0 == data) {
data = new QctThreadLocalData;
storage.setLocalData(data);
}
return data;
}