Loading isis/src/base/objs/SerialNumber/SerialNumber.cpp +12 −0 Original line number Diff line number Diff line #include <map> #include <QMutex> #include <QMutexLocker> #include "SerialNumber.h" #include "ObservationNumber.h" #include "SerialNumberList.h" Loading @@ -11,6 +14,8 @@ #include "FileName.h" namespace Isis { QMutex SerialNumber::m_mutex; /** * Create an empty SerialNumber object. */ Loading Loading @@ -85,10 +90,17 @@ 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 SerialNumber::FindSerialTranslation(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/SerialNumber/SerialNumber.h +21 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <string> #include <QMutex> #include "SerialNumberList.h" namespace Isis { Loading Loading @@ -81,6 +83,19 @@ namespace Isis { * @history 2008-05-09 Steven Lambright Optimized the FindSerialTranslation * method * @history 2008-05-18 Steven Lambright Fixed documentation * @history 2018-07-11 Ian Humphrey - Made FindSerialTranslation() thread-safe. Added a static * mutex for the FindSerialTranslation() method. This facilitates adding * a QString serialNumber member to the Image class and calling * SerialNumber::Compose() within the Image constructors. When qmos or * ipce opens a list of images, it uses an ImageReader, which uses a * QtConcurrent mapped function call to load its images with multiple * threads. Since the FindSerialTranslation() method declares static * local variables within it, this would cause thread collisions on the * static variables when SerialNumbers are being composed for the Images * being conurrently opened by the ImageReader. Added a QMutexLocker to * the FindSerialTranslation() method to auto-lock and unlock the mutex, * which prevents multiple threads from colliding on the static * variables. Fixes #5206. */ class SerialNumber { public: Loading @@ -104,6 +119,12 @@ namespace Isis { static PvlGroup FindSerialTranslation(Pvl &label); /** * Static mutex for preventing threads from colliding on the static variables in * SerialNumber::FindSerialTranslation(). */ static QMutex m_mutex; }; // End of Class }; // End of namespace Loading Loading
isis/src/base/objs/SerialNumber/SerialNumber.cpp +12 −0 Original line number Diff line number Diff line #include <map> #include <QMutex> #include <QMutexLocker> #include "SerialNumber.h" #include "ObservationNumber.h" #include "SerialNumberList.h" Loading @@ -11,6 +14,8 @@ #include "FileName.h" namespace Isis { QMutex SerialNumber::m_mutex; /** * Create an empty SerialNumber object. */ Loading Loading @@ -85,10 +90,17 @@ 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 SerialNumber::FindSerialTranslation(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/SerialNumber/SerialNumber.h +21 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <string> #include <QMutex> #include "SerialNumberList.h" namespace Isis { Loading Loading @@ -81,6 +83,19 @@ namespace Isis { * @history 2008-05-09 Steven Lambright Optimized the FindSerialTranslation * method * @history 2008-05-18 Steven Lambright Fixed documentation * @history 2018-07-11 Ian Humphrey - Made FindSerialTranslation() thread-safe. Added a static * mutex for the FindSerialTranslation() method. This facilitates adding * a QString serialNumber member to the Image class and calling * SerialNumber::Compose() within the Image constructors. When qmos or * ipce opens a list of images, it uses an ImageReader, which uses a * QtConcurrent mapped function call to load its images with multiple * threads. Since the FindSerialTranslation() method declares static * local variables within it, this would cause thread collisions on the * static variables when SerialNumbers are being composed for the Images * being conurrently opened by the ImageReader. Added a QMutexLocker to * the FindSerialTranslation() method to auto-lock and unlock the mutex, * which prevents multiple threads from colliding on the static * variables. Fixes #5206. */ class SerialNumber { public: Loading @@ -104,6 +119,12 @@ namespace Isis { static PvlGroup FindSerialTranslation(Pvl &label); /** * Static mutex for preventing threads from colliding on the static variables in * SerialNumber::FindSerialTranslation(). */ static QMutex m_mutex; }; // End of Class }; // End of namespace Loading