Beispiel #1
0
void DynamicThread::start(QMutexLocker& locker)
{
    if (d->inDestruction)
    {
        return;
    }

    switch (d->state)
    {
        case Inactive:
        case Deactivating:
        {
            d->state = Scheduled;
            break;
        }
        case Running:
        case Scheduled:
        {
            return;
        }
    }

    if (!d->threadRequested)
    {
        // avoid issueing multiple thread requests after very fast start/stop/start calls
        d->threadRequested = true;

        locker.unlock();
        ThreadManager::instance()->schedule(d);
        locker.relock();
    }
}
Beispiel #2
0
  void TabProgress::addNewEntry()
  {
    // Prevent XtalOpt threads from modifying the table
    QMutexLocker locker (m_mutex);

    // The new entry will be at the end of the table, so determine the index:
    int index = ui.table_list->rowCount();
    m_opt->tracker()->lockForRead();
    Xtal *xtal = qobject_cast<Xtal*>(m_opt->tracker()->at(index));
    m_opt->tracker()->unlock();
    //qDebug() << "TabProgress::addNewEntry() at index " << index;

    // Turn off signals
    ui.table_list->blockSignals(true);

    // Store current index for later. If -1, this will be re-set at the end of table
    int currentInd = ui.table_list->currentRow();
    if (currentInd >= ui.table_list->rowCount() - 1) currentInd = -1;

    // Add the new row
    ui.table_list->insertRow(index);
    // Columns: once for each column in ProgressColumns:
    for (int i = 0; i < 9; i++) {
      ui.table_list->setItem(index, i, new QTableWidgetItem());
    }

    m_infoUpdateTracker.lockForWrite();
    m_infoUpdateTracker.append(xtal);
    m_infoUpdateTracker.unlock();
    locker.unlock();
    XO_Prog_TableEntry e;
    xtal->lock()->lockForRead();
    e.elapsed = xtal->getOptElapsed();
    e.gen     = xtal->getGeneration();
    e.id      = xtal->getIDNumber();
    e.parents = xtal->getParents();
    e.jobID   = xtal->getJobID();
    e.volume  = xtal->getVolume();
    e.status  = "Waiting for data...";
    e.brush   = QBrush (Qt::white);
    e.spg     = QString::number( xtal->getSpaceGroupNumber()) + ": "
      + xtal->getSpaceGroupSymbol();

    if (xtal->hasEnthalpy() || xtal->getEnergy() != 0)
      e.enthalpy = xtal->getEnthalpy();
    else
      e.enthalpy = 0.0;
    xtal->lock()->unlock();

    ui.table_list->blockSignals(false);

    if (currentInd < 0) currentInd = index;
    if (rowTracking) ui.table_list->setCurrentCell(currentInd, 0);

    locker.unlock();

    setTableEntry(index, e);
    emit infoUpdate();
  }
Beispiel #3
0
  void TabProgress::addNewEntry()
  {
    QMutexLocker locker (m_mutex);

    // The new entry will be at the end of the table, so determine the index:
    int index = ui.table_list->rowCount();
    m_opt->tracker()->lockForRead();
    Scene *scene = qobject_cast<Scene*>(m_opt->tracker()->at(index));
    m_opt->tracker()->unlock();

    // Turn off signals
    ui.table_list->blockSignals(true);

    // Store current index for later. If -1, this will be re-set at the end of table
    int currentInd = ui.table_list->currentRow();
    if (currentInd >= ui.table_list->rowCount() - 1) currentInd = -1;

    // Add the new row
    ui.table_list->insertRow(index);
    // Columns: once for each column in ProgressColumns:
    for (int i = 0; i < 6; i++) {
      ui.table_list->setItem(index, i, new QTableWidgetItem());
    }

    m_infoUpdateTracker.lockForWrite();
    m_infoUpdateTracker.append(scene);
    m_infoUpdateTracker.unlock();
    locker.unlock();
    RD_Prog_TableEntry e;
    scene->lock()->lockForRead();
    e.rank    = scene->getRank();
    e.elapsed = scene->getOptElapsed();
    e.id      = scene->getIDNumber();
    e.jobID   = scene->getJobID();
    e.status  = "Waiting for data...";
    e.brush   = QBrush (Qt::white);

    if (scene->hasEnthalpy() || scene->getEnergy() != 0)
      e.energy = scene->getEnthalpy();
    else
      e.energy = 0.0;
    scene->lock()->unlock();

    ui.table_list->blockSignals(false);

    if (currentInd < 0) currentInd = index;
    if (rowTracking) ui.table_list->setCurrentCell(currentInd, 0);

    locker.unlock();
    setTableEntry(index, e);
    emit infoUpdate();
  }
Beispiel #4
0
void DynamicThread::wait(QMutexLocker& locker)
{
    while (d->state != Inactive)
    {
        d->condVar.wait(locker.mutex());
    }
}
Beispiel #5
0
 LoopReference(QEventLoopPrivate *d, QMutexLocker &locker) : d(d), locker(locker), exceptionCaught(true)
 {
     d->inExec = true;
     d->exit = false;
     ++d->threadData->loopLevel;
     d->threadData->eventLoops.push(d->q_func());
     locker.unlock();
 }
static PyObject *meth_QMutexLocker_mutex(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QMutexLocker *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QMutexLocker, &sipCpp))
        {
            QMutex *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->mutex();
            Py_END_ALLOW_THREADS

            return sipConvertFromType(sipRes,sipType_QMutex,NULL);
        }
    }
static PyObject *meth_QMutexLocker_relock(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QMutexLocker *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QMutexLocker, &sipCpp))
        {
            Py_BEGIN_ALLOW_THREADS
            sipCpp->relock();
            Py_END_ALLOW_THREADS

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QMutexLocker, sipName_relock, NULL);

    return NULL;
}