本文整理汇总了C++中QSemaphore::acquire方法的典型用法代码示例。如果您正苦于以下问题:C++ QSemaphore::acquire方法的具体用法?C++ QSemaphore::acquire怎么用?C++ QSemaphore::acquire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSemaphore
的用法示例。
在下文中一共展示了QSemaphore::acquire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zablokujSockety
void WatekStatusu::zablokujSockety()
{
pisanieWTrakcie.acquire();
czytanie.acquire();
mutCzytelnik.acquire();
if (++iloscCzytlenikow == 1)
pisanie.acquire();
mutCzytelnik.release();
czytanie.release();
pisanieWTrakcie.release();
}
示例2: 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
}
示例3: run
void Consumer::run()
{
for (int i = 0; i < DataSize; ++i) {
usedSpace.acquire();
QCOMPARE(buffer[i % BufferSize], alphabet[i % AlphabetSize]);
freeSpace.release();
}
for (int i = 0; i < DataSize; ++i) {
if ((i % ConsumerChunkSize) == 0)
usedSpace.acquire(ConsumerChunkSize);
QCOMPARE(buffer[i % BufferSize], alphabet[i % AlphabetSize]);
if ((i % ConsumerChunkSize) == (ConsumerChunkSize - 1))
freeSpace.release(ConsumerChunkSize);
}
}
示例4: odblokujSockety
void WatekStatusu::odblokujSockety()
{
mutCzytelnik.acquire();
if (--iloscCzytlenikow == 0)
pisanie.release();
mutCzytelnik.release();
}
示例5: sipNoMethod
static PyObject *meth_QSemaphore_acquire(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds)
{
PyObject *sipParseErr = NULL;
{
int a0 = 1;
QSemaphore *sipCpp;
static const char *sipKwdList[] = {
sipName_n,
};
if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "B|i", &sipSelf, sipType_QSemaphore, &sipCpp, &a0))
{
Py_BEGIN_ALLOW_THREADS
sipCpp->acquire(a0);
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QSemaphore, sipName_acquire, NULL);
return NULL;
}
示例6: skin_surface_free
static void skin_surface_free(SkinSurface *s)
{
D("skin_surface_free %d", s->id);
QSemaphore semaphore;
s->window->releaseBitmap(s, &semaphore);
semaphore.acquire();
free(s);
}
示例7: 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();
}
示例8: skin_surface_fill
extern void skin_surface_fill(SkinSurface *dst, SkinRect *rect, uint32_t argb_premul)
{
D("skin_surface_fill %d: %d, %d, %d, %d: %x", dst->id, rect->pos.x, rect->pos.y, rect->size.w, rect->size.h, argb_premul);
QRect qrect(rect->pos.x, rect->pos.y, rect->size.w, rect->size.h);
QColor color(argb_premul);
QSemaphore semaphore;
dst->window->fill(dst, &qrect, &color, &semaphore);
semaphore.acquire();
}
示例9: skin_event_poll
extern bool skin_event_poll(SkinEvent* event) {
bool retval;
QSemaphore semaphore;
EmulatorWindow *window = EmulatorWindow::getInstance();
if (window == false) return false;
window->pollEvent(event, &retval, &semaphore);
semaphore.acquire();
return retval;
}
示例10: skin_surface_update
extern void skin_surface_update(SkinSurface *surface, SkinRect *rect)
{
#if 0
D("skin_surface_update %d: %d,%d,%d,%d", surface->id, rect->pos.x, rect->pos.y, rect->size.w, rect->size.h);
#endif
QRect qrect(rect->pos.x, rect->pos.y, rect->size.w, rect->size.h);
QSemaphore semaphore;
surface->window->requestUpdate(&qrect, &semaphore);
semaphore.acquire();
}
示例11: run
void Consumer::run()
{
for (int i = 0; i < DataSize; ++i) {
usedBytes.acquire();
fprintf(stderr, "%c", buffer[i % BufferSize]);
freeBytes.release();
}
fprintf(stderr, "\n");
}
示例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: main
int main( int argc, char** argv ) {
qRegisterMetaType<vector<string> >("vector<string>");
QThread* thread = new MainProcessingThread( );
thread->start();
// thread->exec();
QApplication* app = new QApplication( argc, argv );
semaphore.acquire();
grid = new GridViewer(districtMap);
QObject::connect( thread, SIGNAL(sendPath(vector<string>)), grid, SLOT(sendPath(vector<string>))); //, Qt::QueuedConnection );
grid->show();
app->exec();
}
示例15: skin_surface_create_window
extern SkinSurface* skin_surface_create_window(int x, int y, int w, int h, int original_w, int original_h, int is_fullscreen)
{
D("skin_surface_create_window %d, %d, %d, %d, %d, %d, fullscreen: %d", x, y, w, h, original_w, original_h, is_fullscreen);
QSemaphore semaphore;
EmulatorWindow *window = EmulatorWindow::getInstance();
if (window == NULL) return NULL;
SkinSurface *surface = create_surface(w, h, original_w, original_h);
QRect rect(x, y, w, h);
window->showWindow(surface, &rect, is_fullscreen, &semaphore);
semaphore.acquire();
D("ID of backing bitmap surface is %d", surface->id);
return surface;
}