本文整理汇总了C++中QSemaphore::release方法的典型用法代码示例。如果您正苦于以下问题:C++ QSemaphore::release方法的具体用法?C++ QSemaphore::release怎么用?C++ QSemaphore::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSemaphore
的用法示例。
在下文中一共展示了QSemaphore::release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: odblokujSockety
void WatekStatusu::odblokujSockety()
{
mutCzytelnik.acquire();
if (--iloscCzytlenikow == 0)
pisanie.release();
mutCzytelnik.release();
}
示例2: zablokujSockety
void WatekStatusu::zablokujSockety()
{
pisanieWTrakcie.acquire();
czytanie.acquire();
mutCzytelnik.acquire();
if (++iloscCzytlenikow == 1)
pisanie.acquire();
mutCzytelnik.release();
czytanie.release();
pisanieWTrakcie.release();
}
示例3: tryAcquire
void tst_QSemaphore::tryAcquire()
{
QSemaphore semaphore;
QCOMPARE(semaphore.available(), 0);
semaphore.release();
QCOMPARE(semaphore.available(), 1);
QVERIFY(!semaphore.tryAcquire(2));
QCOMPARE(semaphore.available(), 1);
semaphore.release();
QCOMPARE(semaphore.available(), 2);
QVERIFY(!semaphore.tryAcquire(3));
QCOMPARE(semaphore.available(), 2);
semaphore.release(10);
QCOMPARE(semaphore.available(), 12);
QVERIFY(!semaphore.tryAcquire(100));
QCOMPARE(semaphore.available(), 12);
semaphore.release(10);
QCOMPARE(semaphore.available(), 22);
QVERIFY(!semaphore.tryAcquire(100));
QCOMPARE(semaphore.available(), 22);
QVERIFY(semaphore.tryAcquire());
QCOMPARE(semaphore.available(), 21);
QVERIFY(semaphore.tryAcquire());
QCOMPARE(semaphore.available(), 20);
QVERIFY(semaphore.tryAcquire(10));
QCOMPARE(semaphore.available(), 10);
QVERIFY(semaphore.tryAcquire(10));
QCOMPARE(semaphore.available(), 0);
// should not be able to acquire more
QVERIFY(!semaphore.tryAcquire());
QCOMPARE(semaphore.available(), 0);
QVERIFY(!semaphore.tryAcquire());
QCOMPARE(semaphore.available(), 0);
QVERIFY(!semaphore.tryAcquire(10));
QCOMPARE(semaphore.available(), 0);
QVERIFY(!semaphore.tryAcquire(10));
QCOMPARE(semaphore.available(), 0);
}
示例4: run
void Customer::run() {
waitChair.acquire(); // wait for a chair
barberReady->acquire(); // wait for a barber to be ready
l2.lock();
int bID = buffer[out];
out = (out + 1) % numBarbers;
l2.unlock();
waitChair.release(); // get up from the chair
barberChair.acquire(); // wait for an available barber chair
customerReady[bID].release(); // signal that customer is ready
concurPrint(ID, bID);
barberDone[bID].acquire(); // wait for barber to finish haircut
barberChair.release(); // get up from barber's chair
}
示例5: run
void Producer::run()
{
for (int i = 0; i < DataSize; ++i) {
freeSpace.acquire();
buffer[i % BufferSize] = alphabet[i % AlphabetSize];
usedSpace.release();
}
for (int i = 0; i < DataSize; ++i) {
if ((i % ProducerChunkSize) == 0)
freeSpace.acquire(ProducerChunkSize);
buffer[i % BufferSize] = alphabet[i % AlphabetSize];
if ((i % ProducerChunkSize) == (ProducerChunkSize - 1))
usedSpace.release(ProducerChunkSize);
}
}
示例6: semSync
ThreadManager& ServerThreadManager::endSync(int jobId)
{
QSemaphore *sem = semSync(jobId);
if (sem)
sem->release();
return *this;
}
示例7: initClass
void Barber::initClass(int numB, int numC, QSemaphore *r, QSemaphore *c, QSemaphore *d, int *b) {
customersLeft.release(numC);
barberReady = r;
customerReady = c;
barberDone = d;
buffer = b;
numBarbers = numB;
}
示例8: run
void run()
{
testsTurn.release();
threadsTurn.acquire();
QVERIFY(!recursiveMutex.tryLock());
testsTurn.release();
threadsTurn.acquire();
QVERIFY(recursiveMutex.tryLock());
QVERIFY(lockCount.testAndSetRelaxed(0, 1));
QVERIFY(recursiveMutex.tryLock());
QVERIFY(lockCount.testAndSetRelaxed(1, 2));
QVERIFY(lockCount.testAndSetRelaxed(2, 1));
recursiveMutex.unlock();
QVERIFY(lockCount.testAndSetRelaxed(1, 0));
recursiveMutex.unlock();
testsTurn.release();
threadsTurn.acquire();
QTime timer;
timer.start();
QVERIFY(!recursiveMutex.tryLock(waitTime));
QVERIFY(timer.elapsed() >= waitTime);
QVERIFY(!recursiveMutex.tryLock(0));
testsTurn.release();
threadsTurn.acquire();
timer.start();
QVERIFY(recursiveMutex.tryLock(waitTime));
QVERIFY(timer.elapsed() <= waitTime);
QVERIFY(lockCount.testAndSetRelaxed(0, 1));
QVERIFY(recursiveMutex.tryLock(waitTime));
QVERIFY(lockCount.testAndSetRelaxed(1, 2));
QVERIFY(lockCount.testAndSetRelaxed(2, 1));
recursiveMutex.unlock();
QVERIFY(lockCount.testAndSetRelaxed(1, 0));
recursiveMutex.unlock();
testsTurn.release();
threadsTurn.acquire();
QVERIFY(!recursiveMutex.tryLock(0));
QVERIFY(!recursiveMutex.tryLock(0));
testsTurn.release();
threadsTurn.acquire();
timer.start();
QVERIFY(recursiveMutex.tryLock(0));
QVERIFY(timer.elapsed() < waitTime);
QVERIFY(lockCount.testAndSetRelaxed(0, 1));
QVERIFY(recursiveMutex.tryLock(0));
QVERIFY(lockCount.testAndSetRelaxed(1, 2));
QVERIFY(lockCount.testAndSetRelaxed(2, 1));
recursiveMutex.unlock();
QVERIFY(lockCount.testAndSetRelaxed(1, 0));
recursiveMutex.unlock();
testsTurn.release();
threadsTurn.acquire();
}
示例9: tryAcquireWithTimeoutStarvation
void tst_QSemaphore::tryAcquireWithTimeoutStarvation()
{
class Thread : public QThread
{
public:
QSemaphore startup;
QSemaphore *semaphore;
int amountToConsume, timeout;
void run()
{
startup.release();
forever {
if (!semaphore->tryAcquire(amountToConsume, timeout))
break;
semaphore->release(amountToConsume);
}
}
示例10: run
void Producer::run()
{
for(int i=0;i<DataSize;i++)
{
freeBytes.acquire();
buffer[i%BufferSize]=(i%BufferSize);
usedBytes.release();
}
}
示例11: run
void run()
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
for (int i = 0; i < DataSize; ++i) {
freeBytes.acquire();
buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
usedBytes.release();
}
}
示例12: debug
/**
* \brief Thread-safe vypis o behu servru.
* \param msg Sprava pre vypis
* \retval void
*/
void debug(const char * msg) {
static QSemaphore my_sem(1);
my_sem.acquire();
qDebug() << "[" << QThread::currentThreadId() << "]"
<<QTime::currentTime().toString() << msg;
my_sem.release();
}
示例13: 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();
}
示例14: resumeQtApp
static void resumeQtApp(JNIEnv */*env*/, jobject /*thiz*/)
{
m_surfaceMutex.lock();
m_pauseApplicationMutex.lock();
if (m_androidPlatformIntegration)
m_androidPlatformIntegration->resumeApp();
if (m_pauseApplication)
m_pauseApplicationSemaphore.release();
m_pauseApplicationMutex.unlock();
m_surfaceMutex.unlock();
}
示例15: setSurface
static void setSurface(JNIEnv *env, jobject /*thiz*/, jobject jSurface)
{
#ifndef ANDROID_PLUGIN_OPENGL
if (m_surface)
env->DeleteGlobalRef(m_surface);
m_surface = env->NewGlobalRef(jSurface);
#else
m_surfaceMutex.lock();
EGLNativeWindowType nativeWindow = ANativeWindow_fromSurface(env, jSurface);
bool sameNativeWindow = (nativeWindow != 0 && nativeWindow == m_nativeWindow);
m_nativeWindow = nativeWindow;
if (m_waitForWindow)
m_waitForWindowSemaphore.release();
if (m_androidPlatformIntegration) {
// Use the desktop size.
// On some devices, the getters for the native window size gives wrong values
QSize size = QAndroidPlatformIntegration::defaultDesktopSize();
QPlatformScreen *screen = m_androidPlatformIntegration->screen();
QRect geometry(QPoint(0, 0), size);
if (screen) {
QWindowSystemInterface::handleScreenAvailableGeometryChange(screen->screen(), geometry);
QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), geometry);
}
if (!sameNativeWindow) {
m_surfaceMutex.unlock();
m_androidPlatformIntegration->surfaceChanged();
} else {
// Resize all top level windows, since they share the same surface
foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
QAndroidOpenGLPlatformWindow *window =
static_cast<QAndroidOpenGLPlatformWindow *>(w->handle());
if (window != 0) {
window->lock();
window->scheduleResize(size);
QWindowSystemInterface::handleExposeEvent(window->window(),
QRegion(window->window()->geometry()));
window->unlock();
}
}
m_surfaceMutex.unlock();
}
} else {