本文整理汇总了C++中QReadWriteLock::unlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QReadWriteLock::unlock方法的具体用法?C++ QReadWriteLock::unlock怎么用?C++ QReadWriteLock::unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QReadWriteLock
的用法示例。
在下文中一共展示了QReadWriteLock::unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例2:
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;
}
示例3: 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;
}
示例4: readWriteLockUnlockLoop
void tst_QReadWriteLock::readWriteLockUnlockLoop()
{
QReadWriteLock rwlock;
int runs=10000;
int i;
for (i=0; i<runs; ++i) {
rwlock.lockForRead();
rwlock.unlock();
rwlock.lockForWrite();
rwlock.unlock();
}
}
示例5: run
void run()
{
readWriteLock.lockForWrite();
cond.wakeOne();
cond.wait(&readWriteLock);
readWriteLock.unlock();
}
示例6: mythfile_close
int mythfile_close(int fileID)
{
int result = -1;
LOG(VB_FILE, LOG_DEBUG, LOC + QString("mythfile_close(%1)").arg(fileID));
m_fileWrapperLock.lockForRead();
if (m_ringbuffers.contains(fileID))
{
RingBuffer *rb = m_ringbuffers[fileID];
m_ringbuffers.remove(fileID);
delete rb;
result = 0;
}
else if (m_remotefiles.contains(fileID))
{
RemoteFile *rf = m_remotefiles[fileID];
m_remotefiles.remove(fileID);
delete rf;
result = 0;
}
else if (m_localfiles.contains(fileID))
{
close(m_localfiles[fileID]);
m_localfiles.remove(fileID);
result = 0;
}
m_fileWrapperLock.unlock();
return result;
}
示例7: mythfile_stat_fd
int mythfile_stat_fd(int fileID, struct stat *buf)
{
LOG(VB_FILE, LOG_DEBUG, QString("mythfile_stat_fd(%1, %2)")
.arg(fileID).arg((long long)buf));
m_fileWrapperLock.lockForRead();
if (!m_filenames.contains(fileID))
{
m_fileWrapperLock.unlock();
return -1;
}
QString filename = m_filenames[fileID];
m_fileWrapperLock.unlock();
return mythfile_stat(filename.toLocal8Bit().constData(), buf);
}
示例8: if
char *mythdir_readdir(int dirID)
{
char *result = NULL;
LOG(VB_FILE, LOG_DEBUG, LOC + QString("mythdir_readdir(%1)").arg(dirID));
m_dirWrapperLock.lockForRead();
if (m_remotedirs.contains(dirID))
{
int pos = m_remotedirPositions[dirID];
if (m_remotedirs[dirID].size() >= (pos+1))
{
result = strdup(m_remotedirs[dirID][pos].toLocal8Bit().constData());
pos++;
m_remotedirPositions[dirID] = pos;
}
}
else if (m_localdirs.contains(dirID))
{
struct dirent *entry = readdir(m_localdirs[dirID]);
if (entry)
{
result = strdup(entry->d_name);
}
}
m_dirWrapperLock.unlock();
return result;
}
示例9: accuracyChanged
static void accuracyChanged(JNIEnv * /*env*/, jobject /*thiz*/, jint sensor, jint accuracy)
{
listenersLocker.lockForRead();
foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor])
listener->onAccuracyChanged(accuracy);
listenersLocker.unlock();
}
示例10: 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();
}
}
示例11: run
void WriterThread::run()
{
...
lock.lockForWrite();
write_file();
lock.unlock();
...
}
示例12: refreshQueues
void MainWindow::refreshQueues()
{
g_queuesLock.lockForRead();
int i;
for(i=0;i<g_queues.size();i++)
{
QTreeWidgetItem* item;
if(i>=treeQueues->topLevelItemCount())
{
item = new QTreeWidgetItem(treeQueues, QStringList(g_queues[i]->name()));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled);
treeQueues->addTopLevelItem(item);
}
else
{
item = treeQueues->topLevelItem(i);
item->setText(0, g_queues[i]->name());
}
item->setData(0, Qt::UserRole, qVariantFromValue((void*) g_queues[i]));
}
while(i<treeQueues->topLevelItemCount())
qDebug() << "Removing item" << i << treeQueues->takeTopLevelItem(i);
int upt = 0, downt = 0;
int upq = 0, downq = 0;
int cur = getSelectedQueue();
for(int j=0;j<g_queues.size();j++)
{
Queue* q = g_queues[j];
q->lock();
for(int i=0;i<q->size();i++)
{
int up,down;
q->at(i)->speeds(down,up);
downt += down;
upt += up;
if(j == cur)
{
downq += down;
upq += up;
}
}
q->unlock();
}
g_queuesLock.unlock();
m_labelStatus.setText( QString(tr("Queue's speed: %1 down, %2 up")).arg(formatSize(downq,true)).arg(formatSize(upq,true)) );
}
示例13: 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;
}
示例14: sensorChanged
static void sensorChanged(JNIEnv *env, jobject /*thiz*/, jint sensor, jlong timeStamp, jfloatArray array)
{
uint size = env->GetArrayLength(array);
jfloat *values = env->GetFloatArrayElements(array, 0);
listenersLocker.lockForRead();
foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor])
listener->onSensorChanged(timeStamp, values, size);
listenersLocker.unlock();
env->ReleaseFloatArrayElements(array, values, JNI_ABORT); // don't copy back the elements
}
示例15: run
void run()
{
testsTurn.release();
threadsTurn.acquire();
QVERIFY(!readWriteLock.tryLockForRead());
testsTurn.release();
threadsTurn.acquire();
QVERIFY(readWriteLock.tryLockForRead());
lockCount.ref();
QVERIFY(readWriteLock.tryLockForRead());
lockCount.ref();
lockCount.deref();
readWriteLock.unlock();
lockCount.deref();
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
QTime timer;
timer.start();
QVERIFY(!readWriteLock.tryLockForRead(1000));
QVERIFY(timer.elapsed() >= 1000);
testsTurn.release();
threadsTurn.acquire();
timer.start();
QVERIFY(readWriteLock.tryLockForRead(1000));
QVERIFY(timer.elapsed() <= 1000);
lockCount.ref();
QVERIFY(readWriteLock.tryLockForRead(1000));
lockCount.ref();
lockCount.deref();
readWriteLock.unlock();
lockCount.deref();
readWriteLock.unlock();
testsTurn.release();
threadsTurn.acquire();
}