From 2970e0c693dea088a1d91e188bb84c5cbb2ed486 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 31 May 2012 14:57:54 +0000 Subject: [PATCH] Added a ScopedLock typedef that can be used without requiring extra any #ifdefs --- include/cantera/base/FactoryBase.h | 5 - include/cantera/base/ct_thread.h | 51 ++++++++++ include/cantera/kinetics/FalloffFactory.h | 17 +--- include/cantera/kinetics/KineticsFactory.h | 17 +--- include/cantera/thermo/SpeciesThermoFactory.h | 6 +- include/cantera/thermo/ThermoFactory.h | 20 +--- include/cantera/transport/TransportFactory.h | 12 +-- include/cantera/zeroD/ReactorFactory.h | 18 +--- src/base/application.cpp | 95 ++++--------------- src/base/application.h | 13 +-- src/base/global.cpp | 5 +- src/base/units.h | 18 +--- src/kinetics/FalloffFactory.cpp | 5 +- src/kinetics/KineticsFactory.cpp | 4 +- src/thermo/SpeciesThermoFactory.cpp | 13 +-- src/thermo/ThermoFactory.cpp | 5 +- src/thermo/VPSSMgrFactory.cpp | 13 +-- src/thermo/VPSSMgrFactory.h | 9 +- src/transport/TransportFactory.cpp | 10 +- src/zeroD/ReactorFactory.cpp | 4 +- 20 files changed, 115 insertions(+), 225 deletions(-) create mode 100644 include/cantera/base/ct_thread.h diff --git a/include/cantera/base/FactoryBase.h b/include/cantera/base/FactoryBase.h index 6911baf38..5c2034261 100644 --- a/include/cantera/base/FactoryBase.h +++ b/include/cantera/base/FactoryBase.h @@ -7,14 +7,9 @@ #include -#if defined(THREAD_SAFE_CANTERA) -#include -#endif - namespace Cantera { - //! Base class for factories. /*! This class maintains a registry of * all factories that derive from it, and deletes them all when diff --git a/include/cantera/base/ct_thread.h b/include/cantera/base/ct_thread.h new file mode 100644 index 000000000..42b446409 --- /dev/null +++ b/include/cantera/base/ct_thread.h @@ -0,0 +1,51 @@ +/*! + * @file ct_thread.h + * Header file containing utilities used to ensure thread safety. + */ + +#ifndef CT_THREAD_H +#define CT_THREAD_H + +#include "config.h" + +#ifdef THREAD_SAFE_CANTERA +#include +#include + +#endif + +namespace Cantera { + +#ifdef THREAD_SAFE_CANTERA + +#if defined(BOOST_HAS_WINTHREADS) +typedef unsigned int cthreadId_t; +#elif defined(BOOST_HAS_PTHREADS) +typedef pthread_t cthreadId_t; +#endif + +class thread_equal +{ +public: + bool operator()(cthreadId_t L, cthreadId_t R) { +#if defined(BOOST_HAS_WINTHREADS) + return L == R; +#elif defined(BOOST_HAS_PTHREADS) + return pthread_equal(L, R); +#endif + } +}; + +typedef boost::mutex mutex_t; +typedef boost::mutex::scoped_lock ScopedLock; + +#else + +typedef int mutex_t; +typedef int ScopedLock; + +#endif // THREAD_SAFE_CANTERA + +} + +#endif diff --git a/include/cantera/kinetics/FalloffFactory.h b/include/cantera/kinetics/FalloffFactory.h index bbb288014..2fca6c487 100644 --- a/include/cantera/kinetics/FalloffFactory.h +++ b/include/cantera/kinetics/FalloffFactory.h @@ -12,10 +12,7 @@ #include "cantera/base/ct_defs.h" #include "reaction_defs.h" #include "cantera/base/FactoryBase.h" - -#if defined(THREAD_SAFE_CANTERA) -#include -#endif +#include "cantera/base/ct_thread.h" namespace Cantera { @@ -118,9 +115,7 @@ public: * to the existing factory is returned. */ static FalloffFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(falloff_mutex) ; -#endif + ScopedLock lock(falloff_mutex) ; if (!s_factory) { s_factory = new FalloffFactory; } @@ -128,9 +123,7 @@ public: } virtual void deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(falloff_mutex) ; -#endif + ScopedLock lock(falloff_mutex); if (s_factory) { delete s_factory; s_factory = 0; @@ -169,10 +162,8 @@ private: //! default constructor, which is defined as private FalloffFactory() {} -#if defined(THREAD_SAFE_CANTERA) //! Mutex for use when calling the factory - static boost::mutex falloff_mutex ; -#endif + static mutex_t falloff_mutex ; }; } diff --git a/include/cantera/kinetics/KineticsFactory.h b/include/cantera/kinetics/KineticsFactory.h index 131be41d9..6ce3a6be7 100644 --- a/include/cantera/kinetics/KineticsFactory.h +++ b/include/cantera/kinetics/KineticsFactory.h @@ -10,10 +10,7 @@ #include "Kinetics.h" #include "cantera/base/xml.h" #include "cantera/base/FactoryBase.h" - -#if defined(THREAD_SAFE_CANTERA) -#include -#endif +#include "cantera/base/ct_thread.h" namespace Cantera { @@ -39,9 +36,7 @@ class KineticsFactory : public FactoryBase public: static KineticsFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(kinetics_mutex) ; -#endif + ScopedLock lock(kinetics_mutex); if (!s_factory) { s_factory = new KineticsFactory; } @@ -54,9 +49,7 @@ public: } virtual void deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(kinetics_mutex) ; -#endif + ScopedLock lock(kinetics_mutex); if (s_factory) { delete s_factory ; s_factory = 0 ; @@ -75,9 +68,7 @@ private: static KineticsFactory* s_factory; KineticsFactory() {} -#if defined(THREAD_SAFE_CANTERA) - static boost::mutex kinetics_mutex ; -#endif + static mutex_t kinetics_mutex; }; diff --git a/include/cantera/thermo/SpeciesThermoFactory.h b/include/cantera/thermo/SpeciesThermoFactory.h index f6e511589..2a20f8f9e 100644 --- a/include/cantera/thermo/SpeciesThermoFactory.h +++ b/include/cantera/thermo/SpeciesThermoFactory.h @@ -13,7 +13,7 @@ #include "SpeciesThermo.h" #include "cantera/base/ctexceptions.h" #include "cantera/base/FactoryBase.h" - +#include "cantera/base/ct_thread.h" namespace Cantera { @@ -210,10 +210,8 @@ private: //! Pointer to the sole instance of this class, which is static static SpeciesThermoFactory* s_factory; -#if defined(THREAD_SAFE_CANTERA) //! Decl of the static mutex variable that locks the %SpeciesThermo factory singleton - static boost::mutex species_thermo_mutex; -#endif + static mutex_t species_thermo_mutex; //! Constructor. This is made private, so that only the static //! method factory() can instantiate the class. diff --git a/include/cantera/thermo/ThermoFactory.h b/include/cantera/thermo/ThermoFactory.h index 76e5f97e5..79720734e 100644 --- a/include/cantera/thermo/ThermoFactory.h +++ b/include/cantera/thermo/ThermoFactory.h @@ -12,11 +12,7 @@ #include "ThermoPhase.h" #include "cantera/base/xml.h" - -#if defined(THREAD_SAFE_CANTERA) -#include -#endif - +#include "cantera/base/ct_thread.h" #include "cantera/base/FactoryBase.h" namespace Cantera @@ -67,9 +63,7 @@ public: //! Static function that creates a static instance of the factory. static ThermoFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(thermo_mutex); -#endif + ScopedLock lock(thermo_mutex); if (!s_factory) { s_factory = new ThermoFactory; } @@ -78,9 +72,7 @@ public: //! delete the static instance of this factory virtual void deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(thermo_mutex); -#endif + ScopedLock lock(thermo_mutex); if (s_factory) { delete s_factory; s_factory = 0; @@ -114,12 +106,8 @@ private: //! Private constructors prevents usage ThermoFactory() {}; - -#if defined(THREAD_SAFE_CANTERA) //! Decl for locking mutex for thermo factory singleton - static boost::mutex thermo_mutex; -#endif - + static mutex_t thermo_mutex; }; //! Create a new thermo manager instance. diff --git a/include/cantera/transport/TransportFactory.h b/include/cantera/transport/TransportFactory.h index b0c711b14..5de0dd5fb 100644 --- a/include/cantera/transport/TransportFactory.h +++ b/include/cantera/transport/TransportFactory.h @@ -16,14 +16,12 @@ // Cantera includes #include "cantera/base/ct_defs.h" +#include "cantera/base/ct_thread.h" #include "TransportBase.h" #include "cantera/base/FactoryBase.h" //#include "LiquidTransportData.h" #include "LiquidTransportParams.h" -#if defined(THREAD_SAFE_CANTERA) -#include -#endif //====================================================================================================================== namespace Cantera { @@ -119,9 +117,7 @@ public: * @endcode */ static TransportFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(transport_mutex) ; -#endif + ScopedLock transportLock(transport_mutex); if (!s_factory) { s_factory = new TransportFactory(); } @@ -232,10 +228,8 @@ private: //! object allowed static TransportFactory* s_factory; -#if defined(THREAD_SAFE_CANTERA) //! Static instance of the mutex used to ensure the proper reading of the transport database - static boost::mutex transport_mutex; -#endif + static mutex_t transport_mutex; //! The constructor is private; use static method factory() to //! get a pointer to a factory instance diff --git a/include/cantera/zeroD/ReactorFactory.h b/include/cantera/zeroD/ReactorFactory.h index 9342bb1d7..c9d8dd823 100644 --- a/include/cantera/zeroD/ReactorFactory.h +++ b/include/cantera/zeroD/ReactorFactory.h @@ -9,10 +9,7 @@ #include "ReactorBase.h" #include "cantera/base/FactoryBase.h" - -#if defined(THREAD_SAFE_CANTERA) -#include -#endif +#include "cantera/base/ct_thread.h" namespace Cantera { @@ -23,9 +20,7 @@ class ReactorFactory : Cantera::FactoryBase public: static ReactorFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(reactor_mutex) ; -#endif + ScopedLock lock(reactor_mutex); if (!s_factory) { s_factory = new ReactorFactory; } @@ -33,9 +28,7 @@ public: } virtual void deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(reactor_mutex) ; -#endif + ScopedLock lock(reactor_mutex); if (s_factory) { delete s_factory; s_factory = 0; @@ -55,11 +48,8 @@ public: virtual ReactorBase* newReactor(std::string reactorType); private: - static ReactorFactory* s_factory; -#if defined(THREAD_SAFE_CANTERA) - static boost::mutex reactor_mutex ; -#endif + static mutex_t reactor_mutex; ReactorFactory() {} }; diff --git a/src/base/application.cpp b/src/base/application.cpp index 40ceddb89..b7f3b017b 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -25,83 +25,30 @@ namespace Cantera { // If running multiple threads in a cpp application, the Application class // is the only internal object that is single instance with static data. -// Synchronize access to those data structures Using macros to avoid -// polluting code with a lot of ifdef's #ifdef THREAD_SAFE_CANTERA +cthreadId_t getThisThreadId() +{ +#if defined(BOOST_HAS_WINTHREADS) + return ::GetCurrentThreadId(); +#elif defined(BOOST_HAS_PTHREADS) + return pthread_self(); +#endif +} +#endif //! Mutex for input directory access -static boost::mutex dir_mutex; +static mutex_t dir_mutex; //! Mutex for access to string messages -static boost::mutex msg_mutex; +static mutex_t msg_mutex; //! Mutex for creating singletons within the application object -static boost::mutex app_mutex; - -// Mutex for controlling access to the log file -//static boost::mutex log_mutex; +static mutex_t app_mutex; //! Mutex for controlling access to XML file storage -static boost::mutex xml_mutex; +static mutex_t xml_mutex; -//! Macro for locking input directory access -#define DIR_LOCK() boost::mutex::scoped_lock d_lock(dir_mutex) - -//! Macro for locking access to string messages -#define MSG_LOCK() boost::mutex::scoped_lock m_lock(msg_mutex) - -//! Macro for locking creating singletons in the application state -#define APP_LOCK() boost::mutex::scoped_lock a_lock(app_mutex) - -//! Macro for locking XML file writing -#define XML_LOCK() boost::mutex::scoped_lock x_lock(xml_mutex) - -#ifdef WITH_HTML_LOGS -//static boost::mutex html_mutex; // html logs -//#define HTML_LOCK() boost::mutex::scoped_lock h_lock(html_mutex) -#endif - -#if defined(BOOST_HAS_WINTHREADS) - -class thread_equal -{ -public: - bool operator()(cthreadId_t L, cthreadId_t R) { - return L == R ; - } -} ; -cthreadId_t getThisThreadId() -{ - return ::GetCurrentThreadId() ; -} -#elif defined(BOOST_HAS_PTHREADS) - -typedef pthread_t cthreadId_t ; -class thread_equal -{ -public: - bool operator()(cthreadId_t L, cthreadId_t R) { - return pthread_equal(L, R) ; - } -} ; -cthreadId_t getThisThreadId() -{ - return pthread_self() ; -} -#endif - -#else -#define DIR_LOCK() -#define MSG_LOCK() -#define APP_LOCK() -#define XML_LOCK() - -#ifdef WITH_HTML_LOGS -//#define HTML_LOCK() -#endif - -#endif Application::Messages::Messages() : errorMessage(0), @@ -359,7 +306,7 @@ void Application::Messages::write_logfile(std::string file) #ifdef THREAD_SAFE_CANTERA Application::Messages* Application::ThreadMessages::operator ->() { - MSG_LOCK() ; + ScopedLock msgLock(msg_mutex); cthreadId_t curId = getThisThreadId() ; threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; if (iter != m_threadMsgMap.end()) { @@ -372,7 +319,7 @@ Application::Messages* Application::ThreadMessages::operator ->() void Application::ThreadMessages::removeThreadMessages() { - MSG_LOCK() ; + ScopedLock msgLock(msg_mutex); cthreadId_t curId = getThisThreadId() ; threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; if (iter != m_threadMsgMap.end()) { @@ -407,7 +354,7 @@ Application::Application() : } Application* Application::Instance() { - APP_LOCK(); + ScopedLock appLock(app_mutex); if (Application::s_app == 0) { Application::s_app = new Application(); } @@ -425,7 +372,7 @@ Application::~Application() } void Application::ApplicationDestroy() { - APP_LOCK(); + ScopedLock appLock(app_mutex); if (Application::s_app != 0) { delete Application::s_app; Application::s_app = 0; @@ -442,7 +389,7 @@ void Application::thread_complete() XML_Node* Application::get_XML_File(std::string file, int debug) { - XML_LOCK(); + ScopedLock xmlLock(xml_mutex); std::string path = ""; path = findInputFile(file); #ifdef _WIN32 @@ -537,7 +484,7 @@ XML_Node* Application::get_XML_File(std::string file, int debug) void Application::close_XML_File(std::string file) { - XML_LOCK(); + ScopedLock xmlLock(xml_mutex); if (file == "all") { std::map::iterator b = xmlfiles.begin(), @@ -704,7 +651,7 @@ void Application::setDefaultDirectories() void Application::addDataDirectory(std::string dir) { - DIR_LOCK() ; + ScopedLock dirLock(dir_mutex); if (inputDirs.size() == 0) { setDefaultDirectories(); } @@ -723,7 +670,7 @@ void Application::addDataDirectory(std::string dir) std::string Application::findInputFile(std::string name) { - DIR_LOCK() ; + ScopedLock dirLock(dir_mutex); string::size_type islash = name.find('/'); string::size_type ibslash = name.find('\\'); string inname; diff --git a/src/base/application.h b/src/base/application.h index fa2e1befc..163777303 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -2,13 +2,9 @@ #define CT_BASE_APPLICATION_H #include "cantera/base/config.h" +#include "cantera/base/ct_thread.h" #include "cantera/base/logger.h" -#ifdef THREAD_SAFE_CANTERA -#include -#include -#endif - #include #include #include @@ -28,13 +24,6 @@ class XML_Node; * data is stored in the class Application. */ -#ifdef THREAD_SAFE_CANTERA -#if defined(BOOST_HAS_WINTHREADS) -typedef unsigned int cthreadId_t; -#elif defined(BOOST_HAS_PTHREADS) -typedef pthread_t cthreadId_t; -#endif -#endif //! Class to hold global data. /*! diff --git a/src/base/global.cpp b/src/base/global.cpp index d8a6af391..2b24e242d 100644 --- a/src/base/global.cpp +++ b/src/base/global.cpp @@ -117,10 +117,7 @@ void write_logfile(std::string file) // **************** Global Data **************** Unit* Unit::s_u = 0; - -#if defined(THREAD_SAFE_CANTERA) -boost::mutex Unit::units_mutex ; -#endif +mutex_t Unit::units_mutex; void appdelete() { diff --git a/src/base/units.h b/src/base/units.h index 36308261a..748a227d4 100644 --- a/src/base/units.h +++ b/src/base/units.h @@ -13,13 +13,10 @@ #include "cantera/base/ct_defs.h" #include "cantera/base/ctexceptions.h" +#include "cantera/base/ct_thread.h" #include -#if defined(THREAD_SAFE_CANTERA) -#include -#endif - namespace Cantera { @@ -34,9 +31,7 @@ public: //! Initialize the static Unit class. static Unit* units() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(units_mutex) ; -#endif + ScopedLock lock(units_mutex); if (!s_u) { s_u = new Unit; } @@ -48,9 +43,7 @@ public: * Note this can't be done in a destructor. */ static void deleteUnit() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(units_mutex) ; -#endif + ScopedLock lock(units_mutex); if (s_u) { delete s_u; s_u = 0; @@ -172,11 +165,8 @@ private: */ std::map m_act_u; -#if defined(THREAD_SAFE_CANTERA) //! Decl for static locker for Units singleton - static boost::mutex units_mutex; -#endif - + static mutex_t units_mutex; //! Units class constructor, containing the default mappings between //! strings and units. diff --git a/src/kinetics/FalloffFactory.cpp b/src/kinetics/FalloffFactory.cpp index 8e22c1aa3..c05c54092 100644 --- a/src/kinetics/FalloffFactory.cpp +++ b/src/kinetics/FalloffFactory.cpp @@ -13,10 +13,7 @@ namespace Cantera { FalloffFactory* FalloffFactory::s_factory = 0; -#if defined(THREAD_SAFE_CANTERA) -boost::mutex FalloffFactory::falloff_mutex ; -#endif - +mutex_t FalloffFactory::falloff_mutex; //! The 3-parameter Troe falloff parameterization. /*! diff --git a/src/kinetics/KineticsFactory.cpp b/src/kinetics/KineticsFactory.cpp index 98dd005a4..7a921f562 100644 --- a/src/kinetics/KineticsFactory.cpp +++ b/src/kinetics/KineticsFactory.cpp @@ -18,9 +18,7 @@ namespace Cantera { KineticsFactory* KineticsFactory::s_factory = 0; -#if defined(THREAD_SAFE_CANTERA) -boost::mutex KineticsFactory::kinetics_mutex ; -#endif +mutex_t KineticsFactory::kinetics_mutex; static int ntypes = 6; static string _types[] = {"none", "GasKinetics", "GRI30", "Interface", "Edge", "AqueousKinetics"}; diff --git a/src/thermo/SpeciesThermoFactory.cpp b/src/thermo/SpeciesThermoFactory.cpp index ddf5d31b8..1ad39bb80 100644 --- a/src/thermo/SpeciesThermoFactory.cpp +++ b/src/thermo/SpeciesThermoFactory.cpp @@ -35,10 +35,7 @@ namespace Cantera { SpeciesThermoFactory* SpeciesThermoFactory::s_factory = 0; - -#if defined(THREAD_SAFE_CANTERA) -boost::mutex SpeciesThermoFactory::species_thermo_mutex ; -#endif +mutex_t SpeciesThermoFactory::species_thermo_mutex; //! Examine the types of species thermo parameterizations, //! and return a flag indicating the type of reference state thermo manager @@ -115,9 +112,7 @@ static void getSpeciesThermoTypes(std::vector & spDataNodeList, */ SpeciesThermoFactory* SpeciesThermoFactory::factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(species_thermo_mutex); -#endif + ScopedLock lock(species_thermo_mutex); if (!s_factory) { s_factory = new SpeciesThermoFactory; } @@ -132,9 +127,7 @@ SpeciesThermoFactory* SpeciesThermoFactory::factory() */ void SpeciesThermoFactory::deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(species_thermo_mutex); -#endif + ScopedLock lock(species_thermo_mutex); if (s_factory) { delete s_factory; s_factory = 0; diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index ce3086947..dae88014d 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -61,9 +61,8 @@ namespace Cantera { ThermoFactory* ThermoFactory::s_factory = 0; -#if defined(THREAD_SAFE_CANTERA) -boost::mutex ThermoFactory::thermo_mutex; -#endif +mutex_t ThermoFactory::thermo_mutex; + //! Define the number of %ThermoPhase types for use in this factory routine /*! * @deprecated This entire structure could be replaced with a std::map diff --git a/src/thermo/VPSSMgrFactory.cpp b/src/thermo/VPSSMgrFactory.cpp index b7aa4f22f..bd08a0993 100644 --- a/src/thermo/VPSSMgrFactory.cpp +++ b/src/thermo/VPSSMgrFactory.cpp @@ -45,12 +45,8 @@ namespace Cantera VPSSMgrFactory* VPSSMgrFactory::s_factory = 0; -#if defined(THREAD_SAFE_CANTERA) -// Defn of the static mutex variable that locks the -// %VPSSMgr factory singleton -boost::mutex VPSSMgrFactory::vpss_species_thermo_mutex; -#endif - +// Defn of the static mutex variable that locks the %VPSSMgr factory singleton +mutex_t VPSSMgrFactory::vpss_species_thermo_mutex; //! Examine the types of species thermo parameterizations, and return a flag indicating the type of parameterization //! needed by the species. @@ -201,10 +197,7 @@ static void getVPSSMgrTypes(std::vector & spDataNodeList, */ void VPSSMgrFactory::deleteFactory() { - -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(vpss_species_thermo_mutex); -#endif + ScopedLock lock(vpss_species_thermo_mutex); if (s_factory) { delete s_factory; s_factory = 0; diff --git a/src/thermo/VPSSMgrFactory.h b/src/thermo/VPSSMgrFactory.h index bac93eb93..2b4c6680e 100644 --- a/src/thermo/VPSSMgrFactory.h +++ b/src/thermo/VPSSMgrFactory.h @@ -16,6 +16,7 @@ #include "cantera/thermo/SpeciesThermo.h" #include "cantera/base/ctexceptions.h" #include "cantera/base/FactoryBase.h" +#include "cantera/base/ct_thread.h" #include "cantera/thermo/VPSSMgr.h" namespace Cantera @@ -87,9 +88,7 @@ public: * instance. */ static VPSSMgrFactory* factory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(vpss_species_thermo_mutex); -#endif + ScopedLock lock(vpss_species_thermo_mutex); if (!s_factory) { s_factory = new VPSSMgrFactory; } @@ -156,11 +155,9 @@ private: //! pointer to the sole instance of this class static VPSSMgrFactory* s_factory; -#if defined(THREAD_SAFE_CANTERA) //! Decl of the static mutex variable that locks the //! %VPSSMgr factory singleton - static boost::mutex vpss_species_thermo_mutex; -#endif + static mutex_t vpss_species_thermo_mutex; //! Constructor. This is made private, so that only the static //! method factory() can instantiate the class. diff --git a/src/transport/TransportFactory.cpp b/src/transport/TransportFactory.cpp index e28febbd2..76c49ec2a 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -52,11 +52,8 @@ const doublereal FiveThirds = 5.0/3.0; //==================================================================================================================== TransportFactory* TransportFactory::s_factory = 0; -#if defined(THREAD_SAFE_CANTERA) // declaration of static storage for the mutex -boost::mutex TransportFactory::transport_mutex; -#endif - +mutex_t TransportFactory::transport_mutex; ////////////////////////// exceptions ///////////////////////// @@ -279,9 +276,7 @@ TransportFactory::~TransportFactory() // This static function deletes the statically allocated instance. void TransportFactory::deleteFactory() { -#if defined(THREAD_SAFE_CANTERA) - boost::mutex::scoped_lock lock(transport_mutex) ; -#endif + ScopedLock transportLock(transport_mutex); if (s_factory) { delete s_factory; s_factory = 0; @@ -685,7 +680,6 @@ void TransportFactory::setupLiquidTransport(std::ostream& flog, thermo_t* thermo void TransportFactory::initTransport(Transport* tran, thermo_t* thermo, int mode, int log_level) { - const std::vector & transport_database = thermo->speciesData(); GasTransportParams trParam; diff --git a/src/zeroD/ReactorFactory.cpp b/src/zeroD/ReactorFactory.cpp index 4b803fe5d..0edbb0a51 100644 --- a/src/zeroD/ReactorFactory.cpp +++ b/src/zeroD/ReactorFactory.cpp @@ -15,9 +15,7 @@ namespace Cantera { ReactorFactory* ReactorFactory::s_factory = 0; -#ifdef THREAD_SAFE_CANTERA -boost::mutex ReactorFactory::reactor_mutex ; -#endif +mutex_t ReactorFactory::reactor_mutex; static int ntypes = 4; static string _types[] = {"Reservoir", "Reactor", "ConstPressureReactor",