Loading isis/src/base/objs/ObservationNumber/ObservationNumber.cpp +13 −0 Original line number Diff line number Diff line #include "ObservationNumber.h" #include <QMutex> #include <QMutexLocker> #include "IException.h" #include "Pvl.h" #include "Cube.h" Loading @@ -7,6 +11,8 @@ #include "FileName.h" namespace Isis { QMutex ObservationNumber::m_mutex; /** * Create an empty SerialNumber object. */ Loading Loading @@ -70,9 +76,16 @@ namespace Isis { /** * Get Groups by translating from correct Translation table * * This method is thread-safe. * * @param label A pvl formatted label to be used to generate the serial number */ PvlGroup ObservationNumber::FindObservationTranslation(Pvl &label) { // Immediately lock the static mutex so multiple threads don't collide on the static variables // inside of this method. This locker auto-locks upon construction and unlocks the mutex when // it is destroyed (when this method finishes). QMutexLocker lock(&m_mutex); Pvl outLabel; static PvlGroup dataDir(Preference::Preferences().findGroup("DataDirectory")); Loading isis/src/base/objs/ObservationNumber/ObservationNumber.h +22 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <string> #include <QMutex> #include "SerialNumber.h" #include "SerialNumberList.h" Loading Loading @@ -56,6 +58,20 @@ namespace Isis { * * @history 2008-05-09 Steven Lambright - Optimized the * FindObservationTranslation method * @history 2018-07-11 Ian Humphrey - Made FindObservationTranslation thread-safe. Added a * static mutex for the FindObservationTranslation() method. This * faciliates adding a QString observationNumber member to the Image * class and calling ObservationNumber::Compose() within the Image * constructors. When qmos or ipce opens a list of images, it uses an * ImageReader, which uses a QtConcurrent mapped function to load its * images. Since the FindObservationTranslation() method declares its * static local variables within in, this could cause thread collisions * on these static variables when ObservationNumbers are being composed * for the Images being conucrrently opened by ImageReader. Added a * QMutexLoccker to the FindObservationTranslation() method to auto-lock * and unlock the mutex, which prevents multiple threads from colliding * on the static variables. References #5206. * */ class ObservationNumber : public Isis::SerialNumber { public: Loading @@ -75,6 +91,12 @@ namespace Isis { static PvlGroup FindObservationTranslation(Pvl &label); /** * Static mutex for preventing threads from colliding on the static variables in * FindObservationTranslation(). */ static QMutex m_mutex; }; // End of Class }; // End of namespace Loading Loading
isis/src/base/objs/ObservationNumber/ObservationNumber.cpp +13 −0 Original line number Diff line number Diff line #include "ObservationNumber.h" #include <QMutex> #include <QMutexLocker> #include "IException.h" #include "Pvl.h" #include "Cube.h" Loading @@ -7,6 +11,8 @@ #include "FileName.h" namespace Isis { QMutex ObservationNumber::m_mutex; /** * Create an empty SerialNumber object. */ Loading Loading @@ -70,9 +76,16 @@ namespace Isis { /** * Get Groups by translating from correct Translation table * * This method is thread-safe. * * @param label A pvl formatted label to be used to generate the serial number */ PvlGroup ObservationNumber::FindObservationTranslation(Pvl &label) { // Immediately lock the static mutex so multiple threads don't collide on the static variables // inside of this method. This locker auto-locks upon construction and unlocks the mutex when // it is destroyed (when this method finishes). QMutexLocker lock(&m_mutex); Pvl outLabel; static PvlGroup dataDir(Preference::Preferences().findGroup("DataDirectory")); Loading
isis/src/base/objs/ObservationNumber/ObservationNumber.h +22 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <string> #include <QMutex> #include "SerialNumber.h" #include "SerialNumberList.h" Loading Loading @@ -56,6 +58,20 @@ namespace Isis { * * @history 2008-05-09 Steven Lambright - Optimized the * FindObservationTranslation method * @history 2018-07-11 Ian Humphrey - Made FindObservationTranslation thread-safe. Added a * static mutex for the FindObservationTranslation() method. This * faciliates adding a QString observationNumber member to the Image * class and calling ObservationNumber::Compose() within the Image * constructors. When qmos or ipce opens a list of images, it uses an * ImageReader, which uses a QtConcurrent mapped function to load its * images. Since the FindObservationTranslation() method declares its * static local variables within in, this could cause thread collisions * on these static variables when ObservationNumbers are being composed * for the Images being conucrrently opened by ImageReader. Added a * QMutexLoccker to the FindObservationTranslation() method to auto-lock * and unlock the mutex, which prevents multiple threads from colliding * on the static variables. References #5206. * */ class ObservationNumber : public Isis::SerialNumber { public: Loading @@ -75,6 +91,12 @@ namespace Isis { static PvlGroup FindObservationTranslation(Pvl &label); /** * Static mutex for preventing threads from colliding on the static variables in * FindObservationTranslation(). */ static QMutex m_mutex; }; // End of Class }; // End of namespace Loading