bool TaskWidget::commonRunTask() { // Initialize the task try { assert(mpDataModel != NULL); if (!mpTask->initialize(CCopasiTask::OUTPUT_UI, mpDataModel, NULL)) throw CCopasiException(CCopasiMessage::peekLastMessage()); } catch (CCopasiException & /*Exception*/) { if (CCopasiMessage::peekLastMessage().getNumber() != MCCopasiMessage + 1) { if (mProgressBar != NULL) mProgressBar->finish(); CQMessageBox::critical(this, "Initialization Error", CCopasiMessage::getAllMessageText().c_str(), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); finishTask(); return false; } } if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::ERROR) { if (mProgressBar != NULL) mProgressBar->finish(); CQMessageBox::critical(this, "Initialization Error", CCopasiMessage::getAllMessageText().c_str(), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); finishTask(); return false; } if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::COMMANDLINE) { C_INT Result = CQMessageBox::question(this, "Initialization Warning", CCopasiMessage::getAllMessageText().c_str(), QMessageBox::Ignore | QMessageBox::Abort, QMessageBox::Ignore); if (Result == QMessageBox::Abort) { finishTask(); return false; } } CCopasiMessage::clearDeque(); // Execute the task mpTaskThread->start(); return true; }
void XournalScheduler::removeSource(void* source, JobType type, JobPriority priority) { XOJ_CHECK_TYPE(XournalScheduler); g_mutex_lock(&this->jobQueueMutex); int length = g_queue_get_length(this->jobQueue[priority]); for (int i = 0; i < length; i++) { Job* job = (Job*) g_queue_peek_nth(this->jobQueue[priority], i); if (job->getType() == type) { if (job->getSource() == source) { job->deleteJob(); g_queue_remove(this->jobQueue[priority], job); job->unref(); break; } } } // wait until the last job is done // we can be sure we don't access "source" finishTask(); g_mutex_unlock(&this->jobQueueMutex); }
void SMTWorker::run() { assert(m_pCT); while (!isStopped()) { MCFThreadStatus status = m_pCT->getStatus(m_uiId); while (status == MCFThreadStatus::SF_STATUS_PAUSE) { gcSleep(500); status = m_pCT->getStatus(m_uiId); } if (status == MCFThreadStatus::SF_STATUS_STOP) break; if (status == MCFThreadStatus::SF_STATUS_NULL) { if (!newTask()) continue; } //make sure we dont do compression if we are ment to be stopped if (!isStopped() && status == MCFThreadStatus::SF_STATUS_CONTINUE) { try { doWork(); } catch (gcException &e) { gcString name("Null File"); if (m_pCurFile) name = m_pCurFile->getName(); gcException e2((ERROR_ID)e.getErrId(), e.getSecErrId(), gcString("{0} [{1}]", e.getErrMsg(), name)); finishTask(); m_pCT->reportError(m_uiId, e2); return; } } } m_phFhSink->close(); }
void TaskWidget::slotFinishThread() { if (!mpTaskThread->success() && CCopasiMessage::size() != 0) { CQMessageBox::critical(this, "Calculation Error", CCopasiMessage::getAllMessageText().c_str(), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); } else if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::COMMANDLINE) { CQMessageBox::information(this, "Calculation Warning", CCopasiMessage::getAllMessageText().c_str(), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); } finishTask(); }
void SMTWorker::doWork() { assert(m_pCurFile); assert(m_phFhSink); uint32 buffSize = BLOCKSIZE; bool endFile = false; if ((m_pCurFile->getSize() - m_uiTotRead) < buffSize) { buffSize = (uint32)(((uint64)m_pCurFile->getSize()) - m_uiTotRead); endFile = true; } if (buffSize == 0) { if (m_pCurFile->isCompressed()) { //need to make sure we finish the compression off doCompression(nullptr, 0, true); } else { finishTask(); m_pCT->endTask(m_uiId); } } else { UTIL::MISC::Buffer buff(buffSize); m_hFhSource.read(buff, buffSize); m_uiTotRead += buffSize; m_uiTotFileRead += buffSize; m_pMD5Norm->update(buff, buffSize); if (!m_pCurFile->isCompressed()) writeFile(buff, buffSize, endFile); else doCompression(buff, buffSize, endFile); } }
void SMTWorker::writeFile(const char* buff, uint32 buffSize, bool endFile) { if (buff && buffSize > 0) { m_phFhSink->write(buff, buffSize); m_uiCurOffset += buffSize; m_pCT->reportProgress(m_uiId, m_uiTotFileRead); m_pCRC->addData((unsigned char*)buff, buffSize); } if (endFile) { if (m_pCurFile->isCompressed()) m_pCurFile->setCSize(m_uiCompressSize); finishTask(); m_pCT->endTask(m_uiId); } }
bool StoreDataVessel::calculate(){ unsigned myelem = getAction()->getCurrentPositionInTaskList(); // Normalize vector if it is required finishTask( myelem ); // Store the values if( !hard_cut ){ storeValues( myelem ); // Store the derivatives if we are not using low memory if( !(getAction()->lowmem) && getAction()->derivativesAreRequired() ) storeDerivativesHighMem( myelem ); } else { if( getAction()->getElementValue(getAction()->getIndexOfWeight())>wtol ){ storeValues( myelem ); // Store the derivatives if we are not using low memory if( !(getAction()->lowmem) && getAction()->derivativesAreRequired() ) storeDerivativesHighMem( myelem ); } } return true; }