Skip to content

Commit

Permalink
STYLE: Replace QMutex with QMutexLocker in the ctkJobScheduler
Browse files Browse the repository at this point in the history
STYLE: Fix indentation for visual dicom borwser classes
STYLE: Fix doxygen for visual dicom borwser classes

Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
Co-authored-by: Andras Lasso <[email protected]>
  • Loading branch information
3 people committed Apr 8, 2024
1 parent e4093e2 commit 8a61e8a
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 319 deletions.
361 changes: 188 additions & 173 deletions Libs/Core/ctkJobScheduler.cpp

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Libs/DICOM/Core/ctkDICOMDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ bool ctkDICOMDatabasePrivate::insertConnectionName(int& dbConnectionNameID,
logger.debug("New connection name inserted: database item ID = " + QString().setNum(dbConnectionNameID));
}

patientConnectionName dbpConnectionName;
dbpConnectionName.connectionName = connectionName;
dbpConnectionName.dbPatientID = dbPatientID;
PatientConnectionName dbpConnectionName;
dbpConnectionName.ConnectionName = connectionName;
dbpConnectionName.DBPatientID = dbPatientID;
this->InsertedConnectionNamesIDCache[dbpConnectionName] = dbConnectionNameID;
return connectionNameFound;
}
Expand Down Expand Up @@ -777,10 +777,10 @@ bool ctkDICOMDatabasePrivate::insertPatientStudySeries(const ctkDICOMItem& datas
}
}

patientConnectionName dbpConnectionName;
dbpConnectionName.connectionName = connectionName;
dbpConnectionName.dbPatientID = dbPatientID;
QMap<patientConnectionName, int>::iterator connectionNameIDit =
PatientConnectionName dbpConnectionName;
dbpConnectionName.ConnectionName = connectionName;
dbpConnectionName.DBPatientID = dbPatientID;
QMap<PatientConnectionName, int>::iterator connectionNameIDit =
this->InsertedConnectionNamesIDCache.find(dbpConnectionName);
if (connectionNameIDit == this->InsertedConnectionNamesIDCache.end())
{
Expand Down
16 changes: 8 additions & 8 deletions Libs/DICOM/Core/ctkDICOMDatabase_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMDatabasePrivate
QMap<QString, int> InsertedPatientsCompositeIDCache;

/// map from patient database ID and connection name to database ID
struct patientConnectionName{
int dbPatientID;
QString connectionName;
struct PatientConnectionName{
int DBPatientID;
QString ConnectionName;

// Define comparison function for sorting
bool operator < (const patientConnectionName& other) const
bool operator < (const PatientConnectionName& other) const
{
if (dbPatientID != other.dbPatientID)
if (DBPatientID != other.DBPatientID)
{
return dbPatientID < other.dbPatientID;
return DBPatientID < other.DBPatientID;
}
return connectionName < other.connectionName;
return ConnectionName < other.ConnectionName;
}
};
QMap<patientConnectionName, int> InsertedConnectionNamesIDCache;
QMap<PatientConnectionName, int> InsertedConnectionNamesIDCache;

/// map studies and series UIDs
QSet<QString> InsertedStudyUIDsCache;
Expand Down
20 changes: 9 additions & 11 deletions Libs/DICOM/Core/ctkDICOMEcho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ctkDICOMEchoPrivate
ctkDICOMEchoPrivate();
~ctkDICOMEchoPrivate();

/// Warning: releaseAssociation is not a thread safe method.
/// \warning: releaseAssociation is not a thread safe method.
/// If called concurrently from different threads DCMTK can crash.
/// Therefore use this method instead of calling directly SCU->releaseAssociation()
OFCondition releaseAssociation();
Expand Down Expand Up @@ -96,14 +96,14 @@ ctkDICOMEchoPrivate::ctkDICOMEchoPrivate()
ctkDICOMEchoPrivate::~ctkDICOMEchoPrivate()
{
if (this->SCU && this->SCU->isConnected())
{
this->releaseAssociation();
}
{
this->releaseAssociation();
}

if (this->SCU)
{
delete this->SCU;
}
if (this->SCU)
{
delete this->SCU;
}
}

//------------------------------------------------------------------------------
Expand All @@ -115,17 +115,15 @@ OFCondition ctkDICOMEchoPrivate::releaseAssociation()
return status;
}

this->AssociationMutex.lock();
QMutexLocker locker(&this->AssociationMutex);
if (this->AssociationClosing)
{
this->AssociationMutex.unlock();
return status;
}

this->AssociationClosing = true;
status = this->SCU->releaseAssociation();
this->AssociationClosing = false;
this->AssociationMutex.unlock();

return status;
}
Expand Down
4 changes: 2 additions & 2 deletions Libs/DICOM/Core/ctkDICOMEcho.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMEcho : public QObject
int connectionTimeout() const;
///@}

/// operation is canceled?
/// Return true if the operation was canceled.
Q_INVOKABLE bool wasCanceled();

/// Echo connection.
Q_INVOKABLE bool echo();

///@{
/// Access the list of datasets from the last operation.
/// Reference job uid.
void setJobUID(const QString& jobUID);
QString jobUID() const;
///@}
Expand Down
2 changes: 2 additions & 0 deletions Libs/DICOM/Core/ctkDICOMEchoWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMEchoWorker : public ctkAbstractWorker
/// Cancel worker. This method is thread safe
void requestCancel() override;

///@{
/// Job.
/// These methods are not thread safe
void setJob(QSharedPointer<ctkAbstractJob> job) override;
using ctkAbstractWorker::setJob;
///@}

///@{
/// Echo.
Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Core/ctkDICOMInserter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMInserter : public QObject
QStringList tagsToExcludeFromStorage() const;
///@}

/// operation is canceled?
/// Return true if the operation was canceled.
Q_INVOKABLE bool wasCanceled();

/// add JobResponseSets from queries and retrieves
Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Core/ctkDICOMJobResponseSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMJobResponseSet : public QObject
///@}

///@{
/// Task UID
/// Job UID
void setJobUID(const QString& jobUID);
QString jobUID() const;
///@}
Expand Down
10 changes: 4 additions & 6 deletions Libs/DICOM/Core/ctkDICOMQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ctkDICOMQueryPrivate
/// Add StudyInstanceUID and SeriesInstanceUID that may be further retrieved
void addStudyAndSeriesInstanceUID( const QString& studyInstanceUID, const QString& seriesInstanceUID );

/// Warning: releaseAssociation is not a thread safe method.
/// \warning: releaseAssociation is not a thread safe method.
/// If called concurrently from different threads DCMTK can crash.
/// Therefore use this method instead of calling directly SCU->releaseAssociation()
OFCondition releaseAssociation();
Expand Down Expand Up @@ -173,21 +173,19 @@ OFCondition ctkDICOMQueryPrivate::releaseAssociation()
{
OFCondition status = EC_IllegalCall;
if (!this->SCU)
{
{
return status;
}
}

this->AssociationMutex.lock();
QMutexLocker locker(&this->AssociationMutex);
if (this->AssociationClosing)
{
this->AssociationMutex.unlock();
return status;
}

this->AssociationClosing = true;
status = this->SCU->releaseAssociation();
this->AssociationClosing = false;
this->AssociationMutex.unlock();

return status;
}
Expand Down
8 changes: 6 additions & 2 deletions Libs/DICOM/Core/ctkDICOMQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMQuery : public QObject
Q_INVOKABLE QMap<QString,QVariant> filters()const;
///@}

/// operation is canceled?
/// Return true if the operation was canceled.
Q_INVOKABLE bool wasCanceled();

/// Query a remote DICOM Image Store SCP.
Expand Down Expand Up @@ -153,11 +153,15 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMQuery : public QObject
const QString& studyInstanceUID,
const QString& seriesInstanceUID);

///@{

/// Access the list of datasets from the last queryPatients, queryStudies,
/// querySeries and queryInstances methods.
Q_INVOKABLE QList<ctkDICOMJobResponseSet*> jobResponseSets() const;
QList<QSharedPointer<ctkDICOMJobResponseSet>> jobResponseSetsShared() const;
///@}

///@{
/// Reference job uid.
void setJobUID(const QString& jobUID);
QString jobUID() const;
///@}
Expand Down
2 changes: 2 additions & 0 deletions Libs/DICOM/Core/ctkDICOMQueryWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMQueryWorker : public ctkAbstractWorker
/// Cancel worker. This method is thread safe
void requestCancel() override;

///@{
/// Job.
/// These methods are not thread safe
void setJob(QSharedPointer<ctkAbstractJob> job) override;
using ctkAbstractWorker::setJob;
///@}

///@{
/// Querier.
Expand Down
6 changes: 2 additions & 4 deletions Libs/DICOM/Core/ctkDICOMRetrieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ctkDICOMRetrievePrivate: public QObject
ctkDICOMRetrievePrivate(ctkDICOMRetrieve& obj);
~ctkDICOMRetrievePrivate();

/// Warning: releaseAssociation is not a thread safe method.
/// \warning: releaseAssociation is not a thread safe method.
/// If called concurrently from different threads DCMTK can crash.
/// Therefore use this method instead of calling directly SCU->releaseAssociation()
OFCondition releaseAssociation();
Expand Down Expand Up @@ -323,17 +323,15 @@ OFCondition ctkDICOMRetrievePrivate::releaseAssociation()
return status;
}

this->AssociationMutex.lock();
QMutexLocker locker(&this->AssociationMutex);
if (this->AssociationClosing)
{
this->AssociationMutex.unlock();
return status;
}

this->AssociationClosing = true;
status = this->SCU->releaseAssociation();
this->AssociationClosing = false;
this->AssociationMutex.unlock();

return status;
}
Expand Down
6 changes: 5 additions & 1 deletion Libs/DICOM/Core/ctkDICOMRetrieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMRetrieve : public QObject
int connectionTimeout() const;
///@}

/// operation is canceled?
/// Return true if the operation was canceled.
Q_INVOKABLE bool wasCanceled();

///@{
Expand All @@ -128,6 +128,10 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMRetrieve : public QObject
Q_INVOKABLE void addJobResponseSet(ctkDICOMJobResponseSet& jobResponseSet);
void addJobResponseSet(QSharedPointer<ctkDICOMJobResponseSet> jobResponseSet);
void removeJobResponseSet(QSharedPointer<ctkDICOMJobResponseSet> jobResponseSet);
///@}

///@{
/// Reference job uid.
void setJobUID(const QString& jobUID);
QString jobUID() const;
///@}
Expand Down
2 changes: 2 additions & 0 deletions Libs/DICOM/Core/ctkDICOMRetrieveWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMRetrieveWorker : public ctkAbstractWorker
/// Cancel worker. This method is thread safe
void requestCancel() override;

///@{
/// Job.
/// These methods are not thread safe
void setJob(QSharedPointer<ctkAbstractJob> job) override;
using ctkAbstractWorker::setJob;
///@}

///@{
/// Retriever.
Expand Down
Loading

0 comments on commit 8a61e8a

Please sign in to comment.