本文整理汇总了C++中QReadWriteLock::lockForWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ QReadWriteLock::lockForWrite方法的具体用法?C++ QReadWriteLock::lockForWrite怎么用?C++ QReadWriteLock::lockForWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QReadWriteLock
的用法示例。
在下文中一共展示了QReadWriteLock::lockForWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mythdir_opendir
int mythdir_opendir(const char *dirname)
{
LOG(VB_FILE, LOG_DEBUG, LOC + QString("mythdir_opendir(%1)").arg(dirname));
int id = 0;
if (strncmp(dirname, "myth://", 7))
{
DIR *dir = opendir(dirname);
m_dirWrapperLock.lockForWrite();
id = getNextDirID();
m_localdirs[id] = dir;
m_dirnames[id] = dirname;
m_dirWrapperLock.unlock();
}
else
{
QStringList list;
QUrl qurl(dirname);
QString storageGroup = qurl.userName();
list.clear();
if (storageGroup.isEmpty())
storageGroup = "Default";
list << "QUERY_SG_GETFILELIST";
list << qurl.host();
list << storageGroup;
QString path = qurl.path();
if (!qurl.fragment().isEmpty())
path += "#" + qurl.fragment();
list << path;
list << "1";
bool ok = gCoreContext->SendReceiveStringList(list);
if ((!ok) ||
((list.size() == 1) && (list[0] == "EMPTY LIST")))
list.clear();
m_dirWrapperLock.lockForWrite();
id = getNextDirID();
m_remotedirs[id] = list;
m_remotedirPositions[id] = 0;
m_dirnames[id] = dirname;
m_dirWrapperLock.unlock();
}
return id;
}
示例2: run
void run()
{
readWriteLock.lockForWrite();
cond.wakeOne();
cond.wait(&readWriteLock);
readWriteLock.unlock();
}
示例3: newQueue
void MainWindow::newQueue()
{
QueueDlg dlg(this);
if(dlg.exec() == QDialog::Accepted)
{
Queue* q = new Queue;
q->setName(dlg.m_strName);
q->setSpeedLimits(dlg.m_nDownLimit,dlg.m_nUpLimit);
if(dlg.m_bLimit)
q->setTransferLimits(dlg.m_nDownTransfersLimit,dlg.m_nUpTransfersLimit);
else
q->setTransferLimits(-1, -1);
q->setUpAsDown(dlg.m_bUpAsDown);
q->setDefaultDirectory(dlg.m_strDefaultDirectory);
q->setMoveDirectory(dlg.m_strMoveDirectory);
g_queuesLock.lockForWrite();
g_queues << q;
g_queuesLock.unlock();
Queue::saveQueuesAsync();
refreshQueues();
}
}
示例4:
unsigned int
Album::id() const
{
Q_D( const Album );
s_idMutex.lockForRead();
const bool waiting = d->waitingForId;
unsigned int finalId = d->id;
s_idMutex.unlock();
if ( waiting )
{
finalId = d->idFuture.result();
s_idMutex.lockForWrite();
d->id = finalId;
d->waitingForId = false;
if ( d->id > 0 )
s_albumsById.insert( d->id, d->ownRef.toStrongRef() );
s_idMutex.unlock();
}
return finalId;
}
示例5:
unsigned int
TrackData::trackId() const
{
s_dataidMutex.lockForRead();
const bool waiting = m_waitingForId;
unsigned int finalId = m_trackId;
s_dataidMutex.unlock();
if ( waiting )
{
finalId = m_idFuture.result();
s_dataidMutex.lockForWrite();
m_trackId = finalId;
m_waitingForId = false;
if ( m_trackId > 0 )
{
s_trackDatasById.insert( m_trackId, m_ownRef.toStrongRef() );
}
s_dataidMutex.unlock();
}
return finalId;
}
示例6: writeLockUnlockLoop
void tst_QReadWriteLock::writeLockUnlockLoop()
{
QReadWriteLock rwlock;
int runs=10000;
int i;
for (i=0; i<runs; ++i) {
rwlock.lockForWrite();
rwlock.unlock();
}
}
示例7: terminateRequested
void TonemapperThread::terminateRequested() {
if (forciblyTerminated)
return;
lock.lockForWrite();
pregamma=-1;
xsize=-1;
lock.unlock();
forciblyTerminated=true;
//HACK oddly enough for the other operators we cannot emit finished (it segfaults)
if (opts.tmoperator==mantiuk || opts.tmoperator==ashikhmin || opts.tmoperator==pattanaik )
emit finished();
terminate();
}
示例8: mythdir_check
int mythdir_check(int id)
{
LOG(VB_FILE, LOG_DEBUG, QString("mythdir_check(%1)").arg(id));
int result = 0;
m_dirWrapperLock.lockForWrite();
if (m_localdirs.contains(id))
result = 1;
else if (m_remotedirs.contains(id))
result = 1;
m_dirWrapperLock.unlock();
return result;
}
示例9: writeLockLoop
void tst_QReadWriteLock::writeLockLoop()
{
/*
If you include this, the test should print one line
and then block.
*/
#if 0
QReadWriteLock rwlock;
int runs=10000;
int i;
for (i=0; i<runs; ++i) {
rwlock.lockForWrite();
qDebug("I am going to block now.");
}
#endif
}
示例10: mythfile_check
int mythfile_check(int id)
{
VERBOSE(VB_FILE+VB_EXTRA,
QString("mythfile_check(%1)").arg(id));
int result = 0;
m_fileWrapperLock.lockForWrite();
if (m_localfiles.contains(id))
result = 1;
else if (m_remotefiles.contains(id))
result = 1;
else if (m_ringbuffers.contains(id))
result = 1;
m_fileWrapperLock.unlock();
return result;
}
示例11: main
int main(int argc, char** argv)
{
int i;
const int n_threads = 10;
std::vector<QThread*> tid(n_threads);
s_iterations = argc > 1 ? atoi(argv[1]) : 1000;
fprintf(stderr, "Start of test.\n");
{
// Stack-allocated reader-writer lock.
QReadWriteLock RWL;
RWL.lockForRead();
RWL.unlock();
RWL.lockForWrite();
RWL.unlock();
}
pthread_barrier_init(&s_barrier, 0, n_threads);
s_pRWlock = new QReadWriteLock();
for (i = 0; i < n_threads; i++)
{
tid[i] = new IncThread;
tid[i]->start();
}
for (i = 0; i < n_threads; i++)
{
tid[i]->wait();
delete tid[i];
}
delete s_pRWlock;
s_pRWlock = 0;
pthread_barrier_destroy(&s_barrier);
if (s_counter == n_threads * s_iterations)
fprintf(stderr, "Test successful.\n");
else
fprintf(stderr, "Test failed: counter = %d, should be %d\n",
s_counter, n_threads * s_iterations);
return 0;
}
示例12: threadStressTest
void tst_QGlobalStatic::threadStressTest()
{
class ThreadStressTestThread: public QThread
{
public:
QReadWriteLock *lock;
void run()
{
QReadLocker l(lock);
//usleep(qrand() * 200 / RAND_MAX);
// thundering herd
try {
threadStressTestGS();
} catch (int) {
}
}
};
ThrowingType::constructedCount.store(0);
ThrowingType::destructedCount.store(0);
int expectedConstructionCount = threadStressTestControlVar.load() + 1;
if (expectedConstructionCount <= 0)
QSKIP("This test cannot be run more than once");
const int numThreads = 200;
ThreadStressTestThread threads[numThreads];
QReadWriteLock lock;
lock.lockForWrite();
for (int i = 0; i < numThreads; ++i) {
threads[i].lock = &lock;
threads[i].start();
}
// wait for all threads
// release the herd
lock.unlock();
for (int i = 0; i < numThreads; ++i)
threads[i].wait();
QCOMPARE(ThrowingType::constructedCount.loadAcquire(), expectedConstructionCount);
QCOMPARE(ThrowingType::destructedCount.loadAcquire(), 0);
}
示例13: deleteQueue
void MainWindow::deleteQueue()
{
int queue;
queue = getSelectedQueue();
if(g_queues.empty() || queue < 0)
return;
if(QMessageBox::warning(this, tr("Delete queue"),
tr("Do you really want to delete the active queue?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes)
{
g_queuesLock.lockForWrite();
delete g_queues.takeAt(queue);
g_queuesLock.unlock();
Queue::saveQueuesAsync();
refreshQueues();
}
}
示例14: lock
trackdata_ptr
TrackData::get( unsigned int id, const QString& artist, const QString& track )
{
s_dataidMutex.lockForRead();
if ( s_trackDatasById.contains( id ) )
{
trackdata_wptr track = s_trackDatasById.value( id );
s_dataidMutex.unlock();
if ( track )
return track;
}
s_dataidMutex.unlock();
QMutexLocker lock( &s_datanameCacheMutex );
const QString key = cacheKey( artist, track );
if ( s_trackDatasByName.contains( key ) )
{
trackdata_wptr track = s_trackDatasByName.value( key );
if ( track )
return track;
}
trackdata_ptr t = trackdata_ptr( new TrackData( id, artist, track ), &TrackData::deleteLater );
t->moveToThread( QCoreApplication::instance()->thread() );
t->setWeakRef( t.toWeakRef() );
s_trackDatasByName.insert( key, t );
if ( id > 0 )
{
s_dataidMutex.lockForWrite();
s_trackDatasById.insert( id, t );
s_dataidMutex.unlock();
}
else
t->loadId( false );
return t;
}
示例15: lock
void
Album::deleteLater()
{
QMutexLocker lock( &s_nameCacheMutex );
const QString key = albumCacheKey( m_artist, m_name );
if ( s_albumsByName.contains( key ) )
{
s_albumsByName.remove( key );
}
if ( m_id > 0 )
{
s_idMutex.lockForWrite();
if ( s_albumsById.contains( m_id ) )
{
s_albumsById.remove( m_id );
}
s_idMutex.unlock();
}
QObject::deleteLater();
}