本文整理汇总了C++中QReadWriteLock类的典型用法代码示例。如果您正苦于以下问题:C++ QReadWriteLock类的具体用法?C++ QReadWriteLock怎么用?C++ QReadWriteLock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QReadWriteLock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readLockLoop
void tst_QReadWriteLock::readLockLoop()
{
QReadWriteLock rwlock;
int runs=10000;
int i;
for (i=0; i<runs; ++i) {
rwlock.lockForRead();
}
for (i=0; i<runs; ++i) {
rwlock.unlock();
}
}
示例2: 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
}
示例3: PyBool_FromLong
static PyObject *meth_QReadWriteLock_tryLockForRead(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
QReadWriteLock *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QReadWriteLock, &sipCpp))
{
bool sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = sipCpp->tryLockForRead();
Py_END_ALLOW_THREADS
return PyBool_FromLong(sipRes);
}
}
示例4: 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;
}
示例5: run
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);
}
示例6: 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;
}
示例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: 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);
}
示例10: readData
QByteArray readData()
{
lock.lockForRead();
...
lock.unlock();
return data;
}
示例11: 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);
}
示例12: 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);
}
示例13: 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;
}
示例14: run
void ReaderThread::run()
{
...
lock.lockForRead();
read_file();
lock.unlock();
...
}
示例15: 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;
}