本文整理汇总了C++中QThreadStorage::setLocalData方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadStorage::setLocalData方法的具体用法?C++ QThreadStorage::setLocalData怎么用?C++ QThreadStorage::setLocalData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThreadStorage
的用法示例。
在下文中一共展示了QThreadStorage::setLocalData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: hasLocalData
void tst_QThreadStorage::hasLocalData()
{
QThreadStorage<Pointer *> pointers;
QVERIFY(!pointers.hasLocalData());
pointers.setLocalData(new Pointer);
QVERIFY(pointers.hasLocalData());
pointers.setLocalData(0);
QVERIFY(!pointers.hasLocalData());
}
示例3: 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());
}
示例4: IconvProcessor
IconvProcessor & ucs4ToUtf8()
{
static QThreadStorage<IconvProcessor *> processor;
if (!processor.hasLocalData())
processor.setLocalData(new IconvProcessor("UTF-8", ucs4_codeset));
return *processor.localData();
}
示例5: start
void RpcConnection::start()
{
QString id = QString("[%1:%2] ");
clientSock = new QTcpSocket;
if (!clientSock->setSocketDescriptor(socketDescriptor)) {
qWarning("Unable to initialize TCP socket for incoming connection");
return;
}
qDebug("clientSock Thread = %p", clientSock->thread());
connId.setLocalData(new QString(id.arg(clientSock->peerAddress().toString())
.arg(clientSock->peerPort())));
qDebug("accepting new connection from %s: %d",
clientSock->peerAddress().toString().toAscii().constData(),
clientSock->peerPort());
inStream = new google::protobuf::io::CopyingInputStreamAdaptor(
new PbQtInputStream(clientSock));
inStream->SetOwnsCopyingStream(true);
outStream = new google::protobuf::io::CopyingOutputStreamAdaptor(
new PbQtOutputStream(clientSock));
outStream->SetOwnsCopyingStream(true);
connect(clientSock, SIGNAL(readyRead()),
this, SLOT(on_clientSock_dataAvail()));
connect(clientSock, SIGNAL(disconnected()),
this, SLOT(on_clientSock_disconnected()));
connect(clientSock, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(on_clientSock_error(QAbstractSocket::SocketError)));
}
示例6: getInstance
OAuthNetworkAccessManager* OAuthNetworkAccessManager::getInstance() {
if (!oauthNetworkAccessManagers.hasLocalData()) {
oauthNetworkAccessManagers.setLocalData(new OAuthNetworkAccessManager());
}
return oauthNetworkAccessManagers.localData();
}
示例7: init
void tst_QThreadStorage::init()
{
dummy[1].setLocalData(new int(5));
dummy[2].setLocalData(new int(4));
dummy[3].setLocalData(new int(3));
tls1.setLocalData(new QString());
}
示例8: trackerRelease
RDFServicePtr trackerRelease()
{
if(!tracker_persistent_tls.hasLocalData())
return RDFServicePtr();
RDFServicePtr ret = *tracker_persistent_tls.localData();
tracker_persistent_tls.setLocalData(0);
return ret;
}
示例9:
/*!
Returns the currently running Coroutine for the active thread.
This function will return a unique Coroutine instance that is in the
Running state for the initial 'coroutine' of a thread.
*/
Coroutine *Coroutine::currentCoroutine()
{
// establish a context for the starting coroutine
if (!qt_currentCoroutine.hasLocalData()) {
// set qt_currentCoroutine before actually constructing the root
// coroutine to avoid recursing through the constructor call below
Coroutine **currentPtr = new Coroutine*;
qt_currentCoroutine.setLocalData(currentPtr);
*currentPtr = new Coroutine;
qt_threadRootCoroutine.setLocalData(*currentPtr);
(*currentPtr)->_status = Running;
return *currentPtr;
}
return *qt_currentCoroutine.localData();
}
示例10: cacheObject
void cacheObject(const QString &key, SomeClass *object)
//! [7] //! [8]
{
if (!caches.hasLocalData())
caches.setLocalData(new QCache<QString, SomeClass>);
caches.localData()->insert(key, object);
}
示例11: CGHost
CGHost :: CGHost( CConfig *CFG, QString configFile )
: d_ptr(new CGHostPrivate()),
m_ConfigFile(configFile)
{
currentGHost.setLocalData( this );
foreach( QObject *plugin, QPluginLoader::staticInstances() )
{
LoadPlugin( plugin, CFG );
}
示例12:
static inline Cache *cache()
{
Cache *rv = statCache.localData();
if (!rv) {
rv = new Cache;
statCache.setLocalData(rv);
}
return rv;
}
示例13: 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);
}
示例14: nCmp
bool Utils::String::naturalCompareCaseInsensitive(const QString &left, const QString &right)
{
// provide a single `NaturalCompare` instance for easy use
// https://doc.qt.io/qt-5/threads-reentrancy.html
#ifdef Q_OS_MAC // workaround for Apple xcode: https://stackoverflow.com/a/29929949
static QThreadStorage<NaturalCompare> nCmp;
if (!nCmp.hasLocalData()) nCmp.setLocalData(NaturalCompare(false));
return (nCmp.localData())(left, right);
#else
thread_local NaturalCompare nCmp(false);
return nCmp(left, right);
#endif
}
示例15: processor
vector<char_type>
eightbit_to_ucs4(char const * s, size_t ls, string const & encoding)
{
static QThreadStorage<map<string, IconvProcessor> *> static_processors;
if (!static_processors.hasLocalData())
static_processors.setLocalData(new map<string, IconvProcessor>);
map<string, IconvProcessor> & processors = *static_processors.localData();
if (processors.find(encoding) == processors.end()) {
IconvProcessor processor(ucs4_codeset, encoding.c_str());
processors.insert(make_pair(encoding, processor));
}
return iconv_convert<char_type>(processors[encoding], s, ls);
}