Skip to content

Commit

Permalink
BUG: Fix crash when stopping jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Punzo authored and lassoan committed Mar 20, 2024
1 parent f3846b2 commit fb72e1a
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 202 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

# Exclude QtCreator files ...
CMakeLists.txt.user*
CMakeCache.txt
CMakeFiles/cmake.check_cache

# ignore ctags file
tags
20 changes: 10 additions & 10 deletions Libs/Core/ctkJobScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ctkJobSchedulerPrivate::init()
this, SLOT(onQueueJobsInThreadPool()));

this->ThreadPool = QSharedPointer<QThreadPool>(new QThreadPool());
this->ThreadPool->setMaxThreadCount(10);
this->ThreadPool->setMaxThreadCount(20);
}

//------------------------------------------------------------------------------
Expand All @@ -69,7 +69,7 @@ void ctkJobSchedulerPrivate::onQueueJobsInThreadPool()
return;
}

this->QueueMutex.tryLock();
this->QueueMutex.lock();
foreach (QThread::Priority priority, (QList<QThread::Priority>()
<< QThread::Priority::HighestPriority
<< QThread::Priority::HighPriority
Expand Down Expand Up @@ -135,7 +135,7 @@ bool ctkJobSchedulerPrivate::insertJob(QSharedPointer<ctkAbstractJob> job)
QObject::connect(job.data(), SIGNAL(progressJobDetail(QVariant)),
q, SIGNAL(progressJobDetail(QVariant)));

this->QueueMutex.tryLock();
this->QueueMutex.lock();
this->JobsQueue.insert(job->jobUID(), job);
this->QueueMutex.unlock();

Expand Down Expand Up @@ -165,7 +165,7 @@ bool ctkJobSchedulerPrivate::removeJob(const QString& jobUID)
.arg(jobUID)
.arg(QString::number(reinterpret_cast<quint64>(QThread::currentThreadId()), 16)));

this->QueueMutex.tryLock();
this->QueueMutex.lock();
QSharedPointer<ctkAbstractJob> job = this->JobsQueue.value(jobUID);
if (!job)
{
Expand All @@ -192,7 +192,7 @@ void ctkJobSchedulerPrivate::removeJobs(const QStringList &jobUIDs)
Q_Q(ctkJobScheduler);

QList<QVariant> datas;
this->QueueMutex.tryLock();
this->QueueMutex.lock();
foreach (QString jobUID, jobUIDs)
{
QSharedPointer<ctkAbstractJob> job = this->JobsQueue.value(jobUID);
Expand Down Expand Up @@ -285,7 +285,7 @@ ctkJobScheduler::~ctkJobScheduler()
int ctkJobScheduler::numberOfJobs()
{
Q_D(ctkJobScheduler);
d->QueueMutex.tryLock();
d->QueueMutex.lock();
int numberOfJobs = d->JobsQueue.count();
d->QueueMutex.unlock();
return numberOfJobs;
Expand All @@ -296,7 +296,7 @@ int ctkJobScheduler::numberOfPersistentJobs()
{
Q_D(ctkJobScheduler);
int numberOfPersistentJobs = 0;
d->QueueMutex.tryLock();
d->QueueMutex.lock();
foreach (QSharedPointer<ctkAbstractJob> job, d->JobsQueue)
{
if (job->isPersistent())
Expand Down Expand Up @@ -344,7 +344,7 @@ QSharedPointer<ctkAbstractJob> ctkJobScheduler::getJobSharedByUID(const QString&
{
Q_D(ctkJobScheduler);

d->QueueMutex.tryLock();
d->QueueMutex.lock();
QMap<QString, QSharedPointer<ctkAbstractJob>>::iterator it = d->JobsQueue.find(jobUID);
if (it == d->JobsQueue.end())
{
Expand Down Expand Up @@ -397,7 +397,7 @@ void ctkJobScheduler::stopAllJobs(bool stopPersistentJobs)
Q_D(ctkJobScheduler);

QStringList initializedStoppedJobsUIDs;
d->QueueMutex.tryLock();
d->QueueMutex.lock();
// Stops jobs without a worker (in waiting, still in main thread).
foreach (QSharedPointer<ctkAbstractJob> job, d->JobsQueue)
{
Expand Down Expand Up @@ -470,7 +470,7 @@ void ctkJobScheduler::stopJobsByJobUIDs(const QStringList &jobUIDs)
}

QStringList initializedStoppedJobsUIDs;
d->QueueMutex.tryLock();
d->QueueMutex.lock();
// Stops jobs without a worker (in waiting, still in main thread)
foreach (QSharedPointer<ctkAbstractJob> job, d->JobsQueue)
{
Expand Down
2 changes: 1 addition & 1 deletion Libs/Core/ctkJobScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CTK_CORE_EXPORT ctkJobScheduler : public QObject

///@{
/// Maximum number of concurrent QThreads spawned by the threadPool in the Job pool
/// default: 10
/// default: 20
int maximumThreadCount() const;
void setMaximumThreadCount(int maximumThreadCount);
///@}
Expand Down
44 changes: 17 additions & 27 deletions Libs/DICOM/Core/ctkDICOMEcho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ctkDICOMEchoPrivate
QString CalledAETitle;
QString Host;
int Port;
DcmSCU SCU;
DcmSCU *SCU;
};

//------------------------------------------------------------------------------
Expand All @@ -63,8 +63,9 @@ ctkDICOMEchoPrivate::ctkDICOMEchoPrivate()
this->Host = "";
this->Port = 80;

this->SCU.setACSETimeout(3);
this->SCU.setConnectionTimeout(3);
this->SCU = new DcmSCU();
this->SCU->setACSETimeout(3);
this->SCU->setConnectionTimeout(3);
}

//------------------------------------------------------------------------------
Expand All @@ -77,7 +78,7 @@ ctkDICOMEcho::ctkDICOMEcho(QObject* parentObject)
{
Q_D(ctkDICOMEcho);

d->SCU.setVerbosePCMode(false);
d->SCU->setVerbosePCMode(false);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -157,25 +158,25 @@ int ctkDICOMEcho::port() const
void ctkDICOMEcho::setConnectionTimeout(int timeout)
{
Q_D(ctkDICOMEcho);
d->SCU.setACSETimeout(timeout);
d->SCU.setConnectionTimeout(timeout);
d->SCU->setACSETimeout(timeout);
d->SCU->setConnectionTimeout(timeout);
}

//-----------------------------------------------------------------------------
int ctkDICOMEcho::connectionTimeout() const
{
Q_D(const ctkDICOMEcho);
return d->SCU.getConnectionTimeout();
return d->SCU->getConnectionTimeout();
}

//------------------------------------------------------------------------------
bool ctkDICOMEcho::echo()
{
Q_D(ctkDICOMEcho);

d->SCU.setPeerAETitle(OFString(this->calledAETitle().toStdString().c_str()));
d->SCU.setPeerHostName(OFString(this->host().toStdString().c_str()));
d->SCU.setPeerPort(this->port());
d->SCU->setPeerAETitle(OFString(this->calledAETitle().toStdString().c_str()));
d->SCU->setPeerHostName(OFString(this->host().toStdString().c_str()));
d->SCU->setPeerPort(this->port());

logger.debug("Setting Transfer Syntaxes");

Expand All @@ -184,15 +185,15 @@ bool ctkDICOMEcho::echo()
transferSyntaxes.push_back(UID_BigEndianExplicitTransferSyntax);
transferSyntaxes.push_back(UID_LittleEndianImplicitTransferSyntax);

d->SCU.addPresentationContext(UID_VerificationSOPClass, transferSyntaxes);
if (!d->SCU.initNetwork().good())
d->SCU->addPresentationContext(UID_VerificationSOPClass, transferSyntaxes);
if (!d->SCU->initNetwork().good())
{
logger.error("Error initializing the network");
return false;
}
logger.debug("Negotiating Association");

OFCondition result = d->SCU.negotiateAssociation();
OFCondition result = d->SCU->negotiateAssociation();
if (result.bad())
{
logger.error("Error negotiating the association: " + QString(result.text()));
Expand All @@ -201,26 +202,15 @@ bool ctkDICOMEcho::echo()

logger.info("Seding Echo");
// Issue ECHO request and let scu find presentation context itself (0)
OFCondition status = d->SCU.sendECHORequest(0);
OFCondition status = d->SCU->sendECHORequest(0);
if (!status.good())
{
logger.error("Echo failed");
d->SCU.releaseAssociation();
d->SCU->releaseAssociation();
return false;
}

d->SCU.releaseAssociation();
d->SCU->releaseAssociation();

return true;
}

//------------------------------------------------------------------------------
void ctkDICOMEcho::cancel()
{
Q_D(ctkDICOMEcho);

if (d->SCU.isConnected())
{
d->SCU.releaseAssociation();
}
}
3 changes: 0 additions & 3 deletions Libs/DICOM/Core/ctkDICOMEcho.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMEcho : public QObject
/// Echo connection.
Q_INVOKABLE bool echo();

/// Cancel the current operation
Q_INVOKABLE void cancel();

protected:
QScopedPointer<ctkDICOMEchoPrivate> d_ptr;

Expand Down
Loading

0 comments on commit fb72e1a

Please sign in to comment.