void QcApplication::postSyncEvent( QcSyncEvent *e, QObject *rcv )
{
  _mutex.lock();
  if( !_instance ) {
    _mutex.unlock();
    return;
  }

  if( QThread::currentThread() == rcv->thread() ) {
    sendEvent( rcv, e );
    delete e;
  }
  else {
    QMutex mutex;
    QWaitCondition cond;

    e->_cond = &cond;
    e->_mutex = &mutex;

    mutex.lock();
    postEvent( rcv, e );
    cond.wait( &mutex );
    mutex.unlock();
  }

  _mutex.unlock();
}
CodaDevicePtr SymbianDeviceManager::getCodaDevice(const QString &port)
{
    ensureInitialized();
    QMutexLocker lock(&d->m_devicesLock);
    const int idx = findByPortName(port);
    if (idx == -1) {
        qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port));
        if (debug)
            qDebug() << *this;
        return CodaDevicePtr();
    }
    SymbianDevice& device = d->m_devices[idx];
    CodaDevicePtr& devicePtr = device.m_data->codaDevice;
    if (devicePtr.isNull() || !devicePtr->device()->isOpen()) {
        // Check we instanciate in the correct thread - we can't afford to create the CodaDevice (and more specifically, open the VirtualSerialDevice) in a thread that isn't guaranteed to be long-lived.
        // Therefore, if we're not in SymbianDeviceManager's thread, rejig things so it's opened in the main thread
        if (QThread::currentThread() != thread()) {
            // SymbianDeviceManager is owned by the main thread
            d->m_codaPortWaitMutex.lock();
            QWaitCondition waiter;
            QCoreApplication::postEvent(this, new QConstructCodaPortEvent((QEvent::Type)d->m_constructCodaPortEventType, port, &devicePtr, &waiter));
            waiter.wait(&d->m_codaPortWaitMutex);
            // When the wait returns (due to the wakeAll in SymbianDeviceManager::customEvent), the CodaDevice will be fully set up
            d->m_codaPortWaitMutex.unlock();
        } else {
            // We're in the main thread, just set it up directly
            constructCodaPort(devicePtr, port);
        }
    // We still carry on in the case we failed to open so the client can access the IODevice's errorString()
    }
    if (devicePtr->device()->isOpen())
        device.m_data->deviceAcquired++;
    return devicePtr;
}
Beispiel #3
0
void TestInvocationPlugin::doOperation(int sleepInterval, int count)
{
	for (int i = 0; i < count; ++i) {
		QWaitCondition sleep;
		sleep.wait(new QMutex(), sleepInterval);
	}
}
Beispiel #4
0
 /// sleep (?)
 void msleep ( unsigned long millisecs ) {
     QMutex mutex;
     QWaitCondition waitCondition;
     mutex.lock();
     waitCondition.wait ( &mutex, millisecs );
     mutex.unlock();
 }
Beispiel #5
0
//"Run" part of the process thread.
void ProcessThread::run()
{
	VideoCapture cap(0);
	if(!cap.isOpened())
	{
		qDebug () << "Video capture (cap) was unable to start... ";
		return;
	}
	frame_cnt=0;
	Mat matImage;
	while(!(this->isStopped))
	{
		frame_cnt++;
		cap >> matImage;
		cv::resize (matImage, matImage, Size(800, 600));
		//resize(matImage, image, Size(800,600));

		mutex.lock();
		Mat matimg = mode->process(matImage);
		QImage qimg((uchar *)matimg.data, matimg.cols, matimg.rows, QImage::Format_RGB888);
		QLabel *label = mode->getProperLabel();
		mutex.unlock();

		QWaitCondition cond;
		QMutex drawMutex;
		drawMutex.lock();
		emit drawImage (&qimg, &cond, &drawMutex, label);
		cond.wait (&drawMutex);
		drawMutex.unlock();
	}
};
 void run()
 {
     readWriteLock.lockForWrite();
     cond.wakeOne();
     cond.wait(&readWriteLock);
     readWriteLock.unlock();
 }
Beispiel #7
0
screengrab::screengrab()
{        
    // load configuration
    conf = Config::instance();
    conf->loadSettings();

    pixelMap = new QPixmap;
    scrNum = 0;

    // delay on 250 msec
    QMutex mutex;
    mutex.lock();
    QWaitCondition pause;
    pause.wait(&mutex, 250);

    // get screen
    screenShot();

    // auto saving first screenshot
    if (conf->getAutoSave() == true)
    {
        QString format = conf->getSaveFormat();
        QString filePath = getSaveFilePath(format);
        writeScreen(filePath, format);
    }
}
 void run()
 {
     readWriteLock->lockForRead();
     started.wakeOne();
     cond->wait(readWriteLock);
     readWriteLock->unlock();
 }
 void run()
 {
     mutex.lock();
     cond.wakeOne();
     cond.wait(&mutex);
     mutex.unlock();
 }
void QcApplication::postSyncEvent( QcSyncEvent *e, EventHandlerFn handler )
{
  _mutex.lock();
  if( !_instance ) {
    _mutex.unlock();
    return;
  }

  if( QThread::currentThread() == _instance->thread() ) {
    (*handler)(e);
    delete(e);
  }
  else {
    QMutex mutex;
    QWaitCondition cond;

    e->_handler = handler;
    e->_cond = &cond;
    e->_mutex = &mutex;

    mutex.lock();
    postEvent( _instance, e );
    cond.wait( &mutex );
    mutex.unlock();
  }

  _mutex.unlock();
}
 void run()
 {
     mutex->lock();
     started.wakeOne();
     cond->wait(mutex);
     mutex->unlock();
 }
Beispiel #12
0
int main(int argc, char *argv[])
{

#ifndef QT_DEBUG
    QString fileName = FilePirate::StoragePath + "captains-log.log";
    QFile *log = new QFile(fileName);
    if (log->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
        out = new QTextStream(log);
        qInstallMsgHandler(logOutput);
    } else {
        qDebug() << "Error opening log file '" << fileName << "'. All debug output redirected to console.";
    }
#endif


    SingleApplication a(argc, argv, "9578A25E-F82A-4558-842C-1DE074F3C232");

    if (a.alreadyExists()) {
        qDebug() << "FilePirate is already running.";
        a.sendMessage("fg");
        return 0;
    }

    QPixmap pixmap(":/images/splash.png");
    QSplashScreen *splash = new QSplashScreen(pixmap);
    splash->show();
    a.processEvents();
    splash->showMessage("Loading...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
    qDebug() << "Registering URL handler...";
    QDesktopServices::setUrlHandler("pirate",&FilePirate::Application(),"handleUrl");
    a.processEvents();
    // Force the user to see the splash screen for at least some time
    QMutex dummy;
    dummy.lock();
    QWaitCondition wait;
    wait.wait(&dummy, 750);
    dummy.unlock();
    // And move on to the rest of loading
    splash->showMessage("Loading settings...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
    // load the settings here
    FilePirate::Application().settingsLoaded = FilePirate::Application().loadSettings();
    splash->showMessage("Loading local filelist...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
    FilePirate::Application().fileMon->fullRefreshFileList();

    // bring up the filelist - this is a good time to start up the settings dialog
    // if the user hasn't done so yet...
    splash->showMessage("Finishing up...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
    FilePirate::Application().moveHelpersToThreads();

    MainWindow w;
    w.show();
    splash->finish(&w);

    a.connect(&a, SIGNAL(messageAvailable(QStringList)), &w, SLOT(secondInstanceMessages(QStringList)));

    delete splash;

    return a.exec();
}
Beispiel #13
0
void msleep(unsigned long msecs)
{
    QWaitCondition w;
    QMutex sleepMutex;
    sleepMutex.lock();
    w.wait(&sleepMutex, msecs);
    sleepMutex.unlock();
}
Beispiel #14
0
void Core::sleep(int msec)
{
    QMutex mutex;
    mutex.lock();
    QWaitCondition pause;
    pause.wait(&mutex, msec); // def 240
    mutex.unlock();
}
Beispiel #15
0
void Wait(long int time)
{
	QMutex dummy;
	dummy.lock();
	QWaitCondition waitCondition;
	waitCondition.wait(&dummy, time);
	dummy.unlock();
}
    void run()
    {
        pointers.setLocalData(new Pointer);

        QMutexLocker locker(&mutex);
        cond.wakeOne();
        cond.wait(&mutex);
    }
Beispiel #17
0
void MainWindow::msleep(unsigned long msecs){
    QMutex mutex;
    mutex.lock();

    QWaitCondition waitCondition;
    waitCondition.wait(&mutex, msecs);

    mutex.unlock();
}
Beispiel #18
0
void wl_input_wait(struct wl_input_event *ev, int sleep)
{
	WikiDisplay *display = window->display;
	QWaitCondition *w = display->waitCondition;
	QMutex mutex;

	ev->type = -1;

	do {
		mutex.lock();
		if (sleep && display->keyEventQueue->isEmpty() && display->mouseEventQueue->isEmpty()) {
			w->wait(&mutex);
		}

		if (!display->keyEventQueue->isEmpty()) {
			display->keyQueueMutex->lock();
			QKeyEvent keyEvent = display->keyEventQueue->dequeue();
			display->keyQueueMutex->unlock();
			ev->type = WL_INPUT_EV_TYPE_KEYBOARD;
			/* determine key type */
			if (keyEvent.key() == Qt::Key_Down) {
				ev->key_event.keycode = WL_INPUT_KEY_CURSOR_DOWN;
				ev->type = WL_INPUT_EV_TYPE_CURSOR;
			} else if (keyEvent.key() == Qt::Key_Up) {
				ev->key_event.keycode = WL_INPUT_KEY_CURSOR_UP;
				ev->type = WL_INPUT_EV_TYPE_CURSOR;
			} else if (keyEvent.text().length() > 0) {
				ev->key_event.keycode = keyEvent.text().at(0).unicode();
			} else {
				ev->key_event.keycode = keyEvent.key();
			}

			switch (keyEvent.type()) {
			case QEvent::KeyPress:
				ev->key_event.value = 1;
				break;
			case QEvent::KeyRelease:
				ev->key_event.value = 0;
				break;
			default:
				break;
			}
		}

		if (!display->mouseEventQueue->isEmpty()) {
			display->mouseQueueMutex->lock();
			QMouseEvent mouseEvent = display->mouseEventQueue->dequeue();
			display->mouseQueueMutex->unlock();
			ev->type = WL_INPUT_EV_TYPE_TOUCH;
			ev->touch_event.x = mouseEvent.x();
			ev->touch_event.y = mouseEvent.y();
			ev->touch_event.value = (mouseEvent.type() == QEvent::MouseButtonPress) ? 1 : 0;
		}

		mutex.unlock();
	} while (ev->type == -1 && sleep);
}
void ModelPropertyAnimation::trigger(QAbstractAnimation *animation, bool synchrone, DeletionContext deletionContext)
{
    /* The connexion below won't delete indefinitely looping animation.
     * To avoid memory leaks, the deletionContext paramater is introduced.
     */
    connect(animation, &QAbstractAnimation::finished, [=](){animation->deleteLater();});

    /* Considering what's stated in Qt's doc about Qt::AutoConnection behaviour
     * (see QObject::connect), we need to make sure
     *     ESPECIALLY WHEN this function is called from a thread other than the gui-thread:
     *         from an algorithm thread for instance,
     * that the animation passed as parameter leaves in the gui-thread,
     * so that it can perform flawlessly.
     *
     * Indeed, IN THAT CASE, performing a direct call to QAbstractAnimation::start causes the animation
     * not to perform in the way it should. So we first move it to the gui-thread and then
     * emit a signal which finally triggers its execution.
     *
     * This isn't probably the best way to address this issue, but it works.
     */
    // connect(this, &ModelPropertyAnimation::_startIt, animation, &QAbstractAnimation::start);
    // the previous syntax doesn't work due to argument count mismatching.
    connect(this, SIGNAL(_startIt()), animation, SLOT(start()));
    animation->moveToThread(QApplication::instance()->thread());
    auto startAnimation = [=]() { // define a function that will start the animation
        emit _startIt();
        // disconnect the signal, to make sure any further emission is ignored.
        disconnect(this, SIGNAL(_startIt()), animation, SLOT(start()));
    };

    QThread *t = nullptr;
    switch(deletionContext) {
    case None:                                               break;
    case ThisThread: t = thread();                           break;
    case GuiThread:  t = QApplication::instance()->thread(); break;
    }
    if(t) {
        connect(t, &QThread::finished, animation, &QAbstractAnimation::deleteLater);
    }

    if(!synchrone) {
        startAnimation();
    }
    else {
        QMutex mutex;
        QWaitCondition condition;
        auto connexion = connect(animation, &QAbstractAnimation::finished, [&condition](){condition.wakeAll();});

        mutex.lock();
        startAnimation();
        condition.wait(&mutex);
        mutex.unlock();

        disconnect(connexion);
    }
}
    void run() {
        readWriteLock->lockForWrite();

        ready = true;
        startup->wakeOne();

        returnValue = waitCondition->wait(readWriteLock, timeout);

        readWriteLock->unlock();
    }
    void run() {
        mutex->lock();

        ready = true;
        startup->wakeOne();

        returnValue = waitCondition->wait(mutex, timeout);

        mutex->unlock();
    }
Beispiel #22
0
void TestInvocationPlugin::doOperation(invocation::Progress *progress, int sleepInterval, int count)
{
	progress->setMinimum(0);
	progress->setMaximum(count-1);
	for (int i = 0; i < count; ++i) {
		QWaitCondition sleep;
		sleep.wait(new QMutex(), sleepInterval);
		progress->setValue(i);
	}
}
Beispiel #23
0
void Seq::stopWait()
      {
      stop();
      QWaitCondition sleep;
      while (state != TRANSPORT_STOP) {
            mutex.lock();
            sleep.wait(&mutex, 100);
            mutex.unlock();
            }
      }
Beispiel #24
0
static void msleep(unsigned long msecs)
{
    QMutex mutex;
    mutex.lock();

    QWaitCondition waitCondition;
    waitCondition.wait(&mutex, msecs);

    mutex.unlock();
}
 void run()
 {
     readWriteLock->lockForWrite();
     ++count;
     dummy.wakeOne(); // this wakeup should be lost
     started.wakeOne();
     dummy.wakeAll(); // this one too
     cond->wait(readWriteLock);
     --count;
     readWriteLock->unlock();
 }
 void run()
 {
     mutex->lock();
     ++count;
     dummy.wakeOne(); // this wakeup should be lost
     started.wakeOne();
     dummy.wakeAll(); // this one too
     cond->wait(mutex);
     --count;
     mutex->unlock();
 }
Beispiel #27
0
    /**
     * @brief enlève un vélo du site, si aucun vélo n'est disponible, attends
     *        que quelqu'un en dépose un
     */
    void take() {
        mutex.lock();

        while(_nbBikes <= 0){
            availableBike.wait(&mutex);
        }
        --_nbBikes;
        availableBorne.wakeOne();
        gui_interface->setBikes(ID, _nbBikes);

        mutex.unlock();
    }
Beispiel #28
0
    /**
     * @brief rajoute un vélo sur le site, si auncune borne n'est disponnible
     *        attends qu'une borne se libère
     */
    void put(){
        mutex.lock();

        while(_nbBikes >= NB_BORNES){
            availableBorne.wait(&mutex);
        }
        ++_nbBikes;
        availableBike.wakeOne();
        gui_interface->setBikes(ID, _nbBikes);

        mutex.unlock();
    }
Beispiel #29
0
void Consumer1::run()
{
    qDebug() << "Consumer " << m_id << " before wakeall ";

    if(m_bWakeAll)
        g_con.wakeAll();
    else
        g_con.wakeOne();

    qDebug() << "Consumer " << m_id << " after wakeall";


}
    void run()
    {
        test_mutex.lock();

        mutex.lock();
        for (int i = 0; i < iterations; ++i) {
            cond.wakeOne();
            cond.wait(&mutex);
        }
        mutex.unlock();

        test_mutex.unlock();
    }