本文整理汇总了C++中QReadWriteLock::lockForRead方法的典型用法代码示例。如果您正苦于以下问题:C++ QReadWriteLock::lockForRead方法的具体用法?C++ QReadWriteLock::lockForRead怎么用?C++ QReadWriteLock::lockForRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QReadWriteLock
的用法示例。
在下文中一共展示了QReadWriteLock::lockForRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readData
QByteArray readData()
{
lock.lockForRead();
...
lock.unlock();
return data;
}
示例2:
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;
}
示例3:
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;
}
示例4: 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))
{
int sz = offsetof(struct dirent, d_name) + FILENAME_MAX + 1;
struct dirent *entry =
reinterpret_cast<struct dirent*>(calloc(1, sz));
struct dirent *r = NULL;
if ((0 == readdir_r(m_localdirs[dirID], entry, &r)) && (NULL != r))
result = strdup(r->d_name);
free(entry);
}
示例5: run
void run()
{
readWriteLock->lockForRead();
started.wakeOne();
cond->wait(readWriteLock);
readWriteLock->unlock();
}
示例6: 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;
}
示例7: 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();
}
示例8: 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;
}
示例9: 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)) );
}
示例10: readLockUnlockLoop
void tst_QReadWriteLock::readLockUnlockLoop()
{
QReadWriteLock rwlock;
int runs=10000;
int i;
for (i=0; i<runs; ++i) {
rwlock.lockForRead();
rwlock.unlock();
}
}
示例11: 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
}
示例12: run
//! Entrypoint for LogThread
//! Check to see if there are things to log and if so, write them to disk.
//! Otherwise, wait 100ms and check again.
//! Exit only when "go" is false AND all queued events are written
void LogThread::run()
{
while(! actionLog.isEmpty() || go) {
while(! actionLog.isEmpty()) { // Write all queued log entries
lock.lockForRead();
LogEntry entry = actionLog.dequeue();
lock.unlock();
outStream << entry.dat.asInt << entry.position;
++logEntryCountByServo[entry.dat.asBitfield.servoIndex];
yieldCurrentThread();
}
msleep(100);
}
exit(0);
}
示例13: 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);
}
示例14: mythfile_tell
off_t mythfile_tell(int fileID)
{
off_t result = -1;
LOG(VB_FILE, LOG_DEBUG, LOC + QString("mythfile_tell(%1)").arg(fileID));
m_fileWrapperLock.lockForRead();
if (m_ringbuffers.contains(fileID))
result = m_ringbuffers[fileID]->Seek(0, SEEK_CUR);
else if (m_remotefiles.contains(fileID))
result = m_remotefiles[fileID]->Seek(0, SEEK_CUR);
else if (m_localfiles.contains(fileID))
result = lseek(m_localfiles[fileID], 0, SEEK_CUR);
m_fileWrapperLock.unlock();
return result;
}
示例15: mythfile_seek
off_t mythfile_seek(int fileID, off_t offset, int whence)
{
off_t result = -1;
LOG(VB_FILE, LOG_DEBUG, LOC + QString("mythfile_seek(%1, %2, %3)")
.arg(fileID).arg(offset).arg(whence));
m_fileWrapperLock.lockForRead();
if (m_ringbuffers.contains(fileID))
result = m_ringbuffers[fileID]->Seek(offset, whence);
else if (m_remotefiles.contains(fileID))
result = m_remotefiles[fileID]->Seek(offset, whence);
else if (m_localfiles.contains(fileID))
result = lseek(m_localfiles[fileID], offset, whence);
m_fileWrapperLock.unlock();
return result;
}