Esempio n. 1
0
void WatekStatusu::zablokujSockety()
{
    pisanieWTrakcie.acquire();
    czytanie.acquire();
    mutCzytelnik.acquire();
    if (++iloscCzytlenikow == 1)
      pisanie.acquire();
    mutCzytelnik.release();
    czytanie.release();
    pisanieWTrakcie.release();
}
Esempio n. 2
0
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
}
Esempio n. 3
0
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);
    }
}
Esempio n. 4
0
void WatekStatusu::odblokujSockety()
{
    mutCzytelnik.acquire();
    if (--iloscCzytlenikow == 0)
      pisanie.release();
    mutCzytelnik.release();
}
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;
}
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);
}
            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();
            }
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();
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
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();
}
Esempio n. 11
0
void Consumer::run()
{
    for (int i = 0; i < DataSize; ++i) {
        usedBytes.acquire();
        fprintf(stderr, "%c", buffer[i % BufferSize]);
        freeBytes.release();
    }

    fprintf(stderr, "\n");
}
Esempio n. 12
0
/**
 * \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();
}
Esempio n. 13
0
            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();
            }
Esempio n. 14
0
File: main.cpp Progetto: edemairy/TC
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();
}
Esempio n. 15
0
/*
    Test that the thread pool really reuses threads.
*/
void tst_QThreadPool::threadRecycling()
{
    QThreadPool threadPool;

    threadPool.start(new ThreadRecorderTask());
    threadRecyclingSemaphore.acquire();
    QThread *thread1 = recycledThread;

    QTest::qSleep(100);

    threadPool.start(new ThreadRecorderTask());
    threadRecyclingSemaphore.acquire();
    QThread *thread2 = recycledThread;
    QCOMPARE(thread1, thread2);

    QTest::qSleep(100);

    threadPool.start(new ThreadRecorderTask());
    threadRecyclingSemaphore.acquire();
    QThread *thread3 = recycledThread;
    QCOMPARE(thread2, thread3);
}
Esempio n. 16
0
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;
}
void TextConsumer::run()
{
    int i = 0;
    // QSemaphore::availableData():
    // returns the number of available semaphores
    while( atEnd.available() || availableData.available() )
    {
        availableData.acquire();
        qDebug() << buffer[ i ];
        i = (i+1) % bufferSize;
        freeSpace.release();
    }
}
Esempio n. 18
0
void NodeProtocolObjectPrivate::init()
{
    nodeNum = 0;
    ctlCode = 0;
    cmdType = 0;
    cmdNum = 0;
    cmdContent = 0;
    cmdPramLen = 0;
    memset(cmdParam, 0, sizeof(cmdParam));
    if(sem.available() > 0)
    {
        sem.acquire(1);
    }
}
Esempio n. 19
0
void Consumer::run()
{
    for(int i=0;i<DataSize;i++)
    {
        usedBytes.acquire();

        fprintf(stderr,"%d",buffer[i%BufferSize]);
        if(i%16==0&&i!=0)
            fprintf(stderr,"\n");

        freeBytes.release();
    }
    fprintf(stderr,"\n");
}
Esempio n. 20
0
            void run()
            {
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock());
                testsTurn.release();

                threadsTurn.acquire();
                QVERIFY(normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                QTime timer;
                timer.start();
                QVERIFY(!normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() >= 1000);
                testsTurn.release();

                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() <= 1000);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                timer.start();
                QVERIFY(!normalMutex.tryLock(1000));
                QVERIFY(timer.elapsed() >= 1000);
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }
Esempio n. 21
0
            void run()
            {
                testsTurn.release();

                threadsTurn.acquire();
                if (readWriteLock.tryLockForWrite())
                    failureCount++;
                testsTurn.release();

                threadsTurn.acquire();
                if (!readWriteLock.tryLockForWrite())
                    failureCount++;
                if (!lockCount.testAndSetRelaxed(0, 1))
                    failureCount++;
                if (!lockCount.testAndSetRelaxed(1, 0))
                    failureCount++;
                readWriteLock.unlock();
                testsTurn.release();

                threadsTurn.acquire();
                if (readWriteLock.tryLockForWrite(1000))
                    failureCount++;
                testsTurn.release();

                threadsTurn.acquire();
                if (!readWriteLock.tryLockForWrite(1000))
                    failureCount++;
                if (!lockCount.testAndSetRelaxed(0, 1))
                    failureCount++;
                if (!lockCount.testAndSetRelaxed(1, 0))
                    failureCount++;
                readWriteLock.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }
Esempio n. 22
0
void Bindable::callSlotObject(Detail::Binding binding, void **args)
{
	if (connectionType(binding.m_receiver) == Qt::BlockingQueuedConnection)
	{
		QSemaphore semaphore;
		QMetaCallEvent *ev =
			new QMetaCallEvent(binding.m_object, nullptr, -1, 0, 0, args, &semaphore);
		QCoreApplication::postEvent(const_cast<QObject *>(binding.m_receiver), ev);
		semaphore.acquire();
	}
	else
	{
		binding.m_object->call(const_cast<QObject *>(binding.m_receiver), args);
	}
}
Esempio n. 23
0
static inline void checkPauseApplication()
{
    m_pauseApplicationMutex.lock();
    if (m_pauseApplication) {
        m_pauseApplicationMutex.unlock();
        m_pauseApplicationSemaphore.acquire(); // wait until surface is created

        m_pauseApplicationMutex.lock();
        m_pauseApplication = false;
        m_pauseApplicationMutex.unlock();

        //FIXME
//        QWindowSystemInterface::handleScreenAvailableGeometryChange(0);
//        QWindowSystemInterface::handleScreenGeometryChange(0);
    } else {
        m_pauseApplicationMutex.unlock();
    }
}
void RadioSendThread::run()
{

    RadioServer Server;
    if (!Server.Open())
    {
        printf("Server Open failed!\r\n");
        return;
    }

    int size;
    while (true)
    {

        qDebug() << "Available: " << RadioSendRequest.available();
        RadioSendRequest.acquire();
        if (shutdownView)break;
        RadioSendMutex.lock();
        RadioCmds.set_time_stamp(0);
        size= RadioCmds.cmds_size();
        qDebug() << "size:" << size;
        qDebug() << "IsInitialized: " << RadioCmds.IsInitialized();

        if (RadioCmds.IsInitialized() && size>0 && size<10)
        {

            RadioCmds.set_time_stamp(0);
            Server.Send(RadioCmds);
            qDebug() << "sending";
        }
        else
        {
            printf("Radio Send Packet Error!\r\n");
        }

        Server.Send(RadioCmds);

        RadioCmds.clear_cmds();
        RadioSendMutex.unlock();
        RadioSendRequest.release();
    }
}
Esempio n. 25
0
ThreadManager& ServerThreadManager::reportProgress(const ProgressInfo& pi)
{
    QStringList msg;
    if (pi.hasProgress()) {
        int percent = static_cast<int>( pi.progress()*100 + 0.5 );
        msg << QString("progress: %1%%").arg(percent);
    }
    foreach(const QString& file, pi.files())
        msg << "file: " + file;
    if (pi.needSync())
        msg << "sync";
    if (!msg.isEmpty())
        EQUARES_COUT << msg.join("\n") << endl;
    if (pi.needSync()) {
        QSemaphore *sem = semSync(m_threadData.localData()->jobId);
        Q_ASSERT(sem);
        sem->acquire();
    }
    return *this;
}
Esempio n. 26
0
extern void skin_surface_blit(SkinSurface *dst, SkinPos *pos, SkinSurface *src, SkinRect *rect, SkinBlitOp op)
{
#if 0
    D("skin_surface_blit from %d (%d, %d) to %d: %d,%d,%d,%d", src->id, rect->pos.x, rect->pos.y, dst->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);
    QPoint qpos(pos->x, pos->y);
    QPainter::CompositionMode qop;
    switch(op) {
        default:
        case SKIN_BLIT_COPY:
            qop = QPainter::CompositionMode_Source;
            break;
        case SKIN_BLIT_SRCOVER:
            qop = QPainter::CompositionMode_SourceOver;
            break;
    }
    QSemaphore semaphore;
    dst->window->blit(src->bitmap, &qrect, dst->bitmap, &qpos, &qop, &semaphore);
    semaphore.acquire();
}
Esempio n. 27
0
static SkinSurface *create_surface(int w, int h, int original_w, int original_h)
{
    SkinSurface*  s = (SkinSurface*)malloc(sizeof(*s));
    EmulatorWindow *window = EmulatorWindow::getInstance();
    if (window == NULL) return NULL;
    if (s != NULL) {
        QSemaphore semaphore;
        window->createBitmap(s, original_w, original_h, &semaphore);
        semaphore.acquire();
        s->refcount = 1;
        s->w = w;
        s->h = h;
        s->original_w = original_w;
        s->original_h = original_h;
        s->id = next_id++;
        s->window = window;
        D("Created surface %d %d w,%d h, original %d, %d", s->id, w, h, original_w, original_h);
    }
    else {
        D( "not enough memory to allocate new skin surface !" );
    }
    return  s;
}
Esempio n. 28
0
    void operator()(FeatureBuilder1 & fb)
    {
        buffer_vector<borders::CountryPolygons const *, 32> vec;
        m_countries.ForEachInRect(fb.GetLimitRect(), InsertCountriesPtr(vec));

        switch (vec.size())
        {
        case 0:
            break;
        case 1:
            EmitFeature(vec[0], fb);
            break;
        default:
        {
#if PARALLEL_POLYGONIZER
            m_ThreadPoolSemaphore.acquire();
            m_ThreadPool.start(new PolygonizerTask(this, vec, fb));
#else
            PolygonizerTask task(this, vec, fb);
            task.RunBase();
#endif
        }
        }
    }
Esempio n. 29
0
 void waitForTest()
 {
     semaphore.release();
     testSemaphore.acquire();
 }
            void run()
            {
                testsTurn.release();

                // TEST 1: thread can't acquire lock
                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock());
                testsTurn.release();

                // TEST 2: thread can acquire lock
                threadsTurn.acquire();
                QVERIFY(normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock());
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 3: thread can't acquire lock, timeout = waitTime
                threadsTurn.acquire();
                QTime timer;
                timer.start();
                QVERIFY(!normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() >= waitTime);
                testsTurn.release();

                // TEST 4: thread can acquire lock, timeout = waitTime
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() <= waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                timer.start();
                // it's non-recursive, so the following lock needs to fail
                QVERIFY(!normalMutex.tryLock(waitTime));
                QVERIFY(timer.elapsed() >= waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 5: thread can't acquire lock, timeout = 0
                threadsTurn.acquire();
                QVERIFY(!normalMutex.tryLock(0));
                testsTurn.release();

                // TEST 6: thread can acquire lock, timeout = 0
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(0));
                QVERIFY(timer.elapsed() < waitTime);
                QVERIFY(lockCount.testAndSetRelaxed(0, 1));
                QVERIFY(!normalMutex.tryLock(0));
                QVERIFY(lockCount.testAndSetRelaxed(1, 0));
                normalMutex.unlock();
                testsTurn.release();

                // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795)
                threadsTurn.acquire();
                timer.start();
                QVERIFY(normalMutex.tryLock(3000));
                QVERIFY(timer.elapsed() < 3000);
                normalMutex.unlock();
                testsTurn.release();

                threadsTurn.acquire();
            }