Unverified Commit 169714eb authored by Summer Stapleton's avatar Summer Stapleton Committed by GitHub
Browse files

Merge pull request #345 from ihumphrey-usgs/ipceBundleWindow_5206

Ipce bundle window speed up JigsawSetupDialog load
parents 8e02baf5 c46c59ad
Loading
Loading
Loading
Loading
+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"
@@ -7,6 +11,8 @@
#include "FileName.h"

namespace Isis {
  QMutex ObservationNumber::m_mutex;

  /**
  * Create an empty SerialNumber object.
  */
@@ -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"));

+22 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@

#include <string>

#include <QMutex>

#include "SerialNumber.h"
#include "SerialNumberList.h"

@@ -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:
@@ -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

+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"
@@ -11,6 +14,8 @@
#include "FileName.h"

namespace Isis {
  QMutex SerialNumber::m_mutex;

  /**
  * Create an empty SerialNumber object.
  */
@@ -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"));

+21 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@

#include <string>

#include <QMutex>

#include "SerialNumberList.h"

namespace Isis {
@@ -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:
@@ -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

+19 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <geos/io/WKTWriter.h>

#include "Angle.h"
#include "Camera.h"
#include "Cube.h"
#include "CubeAttribute.h"
#include "DisplayProperties.h"
@@ -53,7 +54,11 @@ namespace Isis {

    m_fileName = imageFileName;

    m_observationNumber = ObservationNumber::Compose(*(cube()));
    m_serialNumber = SerialNumber::Compose(*(cube()));
    
    cube();
    m_cameraType = m_cube->camera()->GetCameraType();

    initCamStats();

@@ -88,6 +93,10 @@ namespace Isis {
    m_lineResolution = Null;
    m_sampleResolution = Null;

    m_cameraType = m_cube->camera()->GetCameraType();
    m_observationNumber = ObservationNumber::Compose(*(cube()));
    m_serialNumber = SerialNumber::Compose(*(cube()));

    initCamStats();

    try {
@@ -282,6 +291,16 @@ namespace Isis {
  }


  /**
   * @brief Get the camera type for this Image.
   * 
   * @return Camera::CameraType Returns the camera type for this Image.
   */
  Camera::CameraType Image::cameraType() const {
    return m_cameraType;
  }


  /**
   * @brief Get the display (GUI) properties (information) associated with this image.
   * @return @b (ImageDisplayProperties *) Returns a poniter to an ImageDisplayProperties
@@ -317,9 +336,6 @@ namespace Isis {
   * @return QString A string representation of the observation number of the cube.
   */
  QString Image::observationNumber() {
    if (m_observationNumber.isEmpty()) {
      m_observationNumber = ObservationNumber::Compose(*(cube()));
    }
    return m_observationNumber;
  }

@@ -329,9 +345,6 @@ namespace Isis {
   * @return @b QString  A string representation of the serial number of the cube.
   */
  QString Image::serialNumber() {
    if (m_serialNumber.isEmpty()) {
      m_serialNumber = SerialNumber::Compose(*(cube()));
    } 
    return m_serialNumber;
  }

Loading