diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index 80d73ea2e..e45a332e1 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -683,29 +683,22 @@ CameraConstantsStore::CameraConstantsStore() { } -static CameraConstantsStore *global_instance; - -void CameraConstantsStore::initCameraConstants(Glib::ustring baseDir, Glib::ustring userSettingsDir) +void CameraConstantsStore::init(Glib::ustring baseDir, Glib::ustring userSettingsDir) { - if (global_instance) { - // should only be called once during init. - abort(); - } - - global_instance = new CameraConstantsStore(); - global_instance->parse_camera_constants_file(Glib::build_filename(baseDir, "camconst.json")); + parse_camera_constants_file(Glib::build_filename(baseDir, "camconst.json")); Glib::ustring userFile(Glib::build_filename(userSettingsDir, "camconst.json")); if (safe_file_test(userFile, Glib::FILE_TEST_EXISTS)) { - global_instance->parse_camera_constants_file(userFile); + parse_camera_constants_file(userFile); } } CameraConstantsStore * CameraConstantsStore::getInstance(void) { - return global_instance; + static CameraConstantsStore instance_; + return &instance_; } CameraConst * diff --git a/rtengine/camconst.h b/rtengine/camconst.h index a591f09fe..b57c3fee9 100644 --- a/rtengine/camconst.h +++ b/rtengine/camconst.h @@ -54,7 +54,7 @@ private: bool parse_camera_constants_file(Glib::ustring filename); public: - static void initCameraConstants(Glib::ustring baseDir, Glib::ustring userSettingsDir); + void init(Glib::ustring baseDir, Glib::ustring userSettingsDir); static CameraConstantsStore *getInstance(void); CameraConst *get(const char make[], const char model[]); }; diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index 9b3d852fc..9dd01330b 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -1691,18 +1691,8 @@ void DCPProfile::step2ApplyTile(float *rc, float *gc, float *bc, int width, int // Generates as singleton DCPStore* DCPStore::getInstance() { - static DCPStore* instance_ = 0; - - if ( instance_ == 0 ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == 0 ) { - instance_ = new DCPStore(); - } - } - - return instance_; + static DCPStore instance_; + return &instance_; } // Reads all profiles from the given profiles dir diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 195da3fe3..bad4e8dfa 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -192,18 +192,8 @@ ICCStore::makeStdGammaProfile(cmsHPROFILE iprof) ICCStore* ICCStore::getInstance(void) { - static ICCStore* instance_ = 0; - - if ( instance_ == 0 ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == 0 ) { - instance_ = new ICCStore(); - } - } - - return instance_; + static ICCStore instance_; + return &instance_; } ICCStore::ICCStore () diff --git a/rtengine/init.cc b/rtengine/init.cc index acedd844f..9fa5c48ee 100644 --- a/rtengine/init.cc +++ b/rtengine/init.cc @@ -46,7 +46,7 @@ int init (const Settings* s, Glib::ustring baseDir, Glib::ustring userSettingsDi dcpStore->init (baseDir + "/dcpprofiles"); - CameraConstantsStore::initCameraConstants (baseDir, userSettingsDir); + CameraConstantsStore::getInstance ()->init (baseDir, userSettingsDir); profileStore.init (); ProcParams::init (); Color::init (); diff --git a/rtengine/lcp.cc b/rtengine/lcp.cc index da042711a..903e54a0a 100644 --- a/rtengine/lcp.cc +++ b/rtengine/lcp.cc @@ -781,18 +781,8 @@ void XMLCALL LCPProfile::XmlEndHandler(void *pLCPProfile, const char *el) // Generates as singleton LCPStore* LCPStore::getInstance() { - static LCPStore* instance_ = 0; - - if ( instance_ == 0 ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == 0 ) { - instance_ = new LCPStore(); - } - } - - return instance_; + static LCPStore instance_; + return &instance_; } LCPProfile* LCPStore::getProfile (Glib::ustring filename) diff --git a/rtgui/cachemanager.cc b/rtgui/cachemanager.cc index 3d3702176..0b88ea5f4 100644 --- a/rtgui/cachemanager.cc +++ b/rtgui/cachemanager.cc @@ -30,18 +30,8 @@ CacheManager* CacheManager::getInstance(void) { - static CacheManager* instance_ = 0; - - if ( instance_ == 0 ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == 0 ) { - instance_ = new CacheManager(); - } - } - - return instance_; + static CacheManager instance_; + return &instance_; } void CacheManager::init () diff --git a/rtgui/editwindow.cc b/rtgui/editwindow.cc index 3b99f57e5..88bd2aee4 100644 --- a/rtgui/editwindow.cc +++ b/rtgui/editwindow.cc @@ -24,8 +24,6 @@ #include "rtimage.h" #include "threadutils.h" -static EditWindow* editWnd = NULL; - // Check if the system has more than one display and option is set bool EditWindow::isMultiDisplayEnabled() { @@ -35,29 +33,26 @@ bool EditWindow::isMultiDisplayEnabled() // Should only be created once, auto-creates window on correct display EditWindow* EditWindow::getInstance(RTWindow* p) { + struct EditWindowInstance + { + EditWindow editWnd; - if (editWnd == NULL) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( editWnd == 0 ) { - editWnd = new EditWindow(p); - + EditWindowInstance(RTWindow* p) : editWnd(p) + { // Determine the other display and maximize the window on that const Glib::RefPtr< Gdk::Window >& wnd = p->get_window(); int monNo = p->get_screen()->get_monitor_at_window (wnd); Gdk::Rectangle lMonitorRect; - editWnd->get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect); - editWnd->move(lMonitorRect.get_x(), lMonitorRect.get_y()); - editWnd->maximize(); - editWnd->show(); - } else { - editWnd->show_all(); + editWnd.get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect); + editWnd.move(lMonitorRect.get_x(), lMonitorRect.get_y()); + editWnd.maximize(); } - } + }; - return editWnd; + static EditWindowInstance instance_(p); + instance_.editWnd.show_all(); + return &instance_.editWnd; } EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false) diff --git a/rtgui/extprog.cc b/rtgui/extprog.cc index 8e0ab225f..b6ef31255 100644 --- a/rtgui/extprog.cc +++ b/rtgui/extprog.cc @@ -74,18 +74,8 @@ bool ExtProgAction::Execute(std::vector fileNames) // Generates as singleton ExtProgStore* ExtProgStore::getInstance() { - static ExtProgStore* instance_ = 0; - - if ( instance_ == 0 ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == 0 ) { - instance_ = new ExtProgStore(); - } - } - - return instance_; + static ExtProgStore instance_; + return &instance_; } ExtProgStore::~ExtProgStore() diff --git a/rtgui/previewloader.cc b/rtgui/previewloader.cc index 3fe1897ba..dd090a95e 100644 --- a/rtgui/previewloader.cc +++ b/rtgui/previewloader.cc @@ -168,19 +168,8 @@ PreviewLoader::PreviewLoader(): PreviewLoader* PreviewLoader::getInstance(void) { - // this will not be deleted... - static PreviewLoader* instance_ = NULL; - - if ( instance_ == NULL ) { - static MyMutex smutex_; - MyMutex::MyLock lock(smutex_); - - if ( instance_ == NULL ) { - instance_ = new PreviewLoader(); - } - } - - return instance_; + static PreviewLoader instance_; + return &instance_; } void PreviewLoader::add(int dir_id, const Glib::ustring& dir_entry, PreviewLoaderListener* l) diff --git a/rtgui/thumbimageupdater.cc b/rtgui/thumbimageupdater.cc index 3f5861677..29160236e 100644 --- a/rtgui/thumbimageupdater.cc +++ b/rtgui/thumbimageupdater.cc @@ -192,14 +192,8 @@ public: ThumbImageUpdater* ThumbImageUpdater::getInstance(void) { - // this will not be deleted... - static ThumbImageUpdater* instance_ = 0; - - if ( instance_ == 0 ) { - instance_ = new ThumbImageUpdater(); - } - - return instance_; + static ThumbImageUpdater instance_; + return &instance_; } ThumbImageUpdater::ThumbImageUpdater():