diff --git a/.travis.yml b/.travis.yml index 9410cd6be..e72bcd1cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: cpp before_script: - sudo apt-get update -qq - - sudo apt-get install -y python-dev python-numpy-dev gfortran libsundials-serial-dev liblapack-dev libblas-dev libboost-thread-dev + - sudo apt-get install -y python-dev python-numpy-dev gfortran libsundials-serial-dev liblapack-dev libblas-dev - wget https://github.com/msabramo/cython/releases/download/0.19.1/Cython-0.19.1-cp27-none-linux_x86_64.whl - sudo pip install Cython-0.19.1-cp27-none-linux_x86_64.whl - rm -f cantera.conf script: - - scons build VERBOSE=y python_package=full python3_package=n blas_lapack_libs=lapack,blas build_thread_safe=y optimize=n + - scons build VERBOSE=y python_package=full python3_package=n blas_lapack_libs=lapack,blas optimize=n - scons test diff --git a/SConstruct b/SConstruct index 87898737b..ff8afe007 100644 --- a/SConstruct +++ b/SConstruct @@ -529,32 +529,10 @@ config_options = [ ('extra_lib_dirs', 'Additional directories to search for libraries (colon-separated list).', ''), - BoolVariable( - 'build_thread_safe', - """Cantera can be built so that it is thread safe. Doing so requires - using procedures from the Boost library, so if you want thread - safety then you need to get and install Boost (http://www.boost.org) - if you don't have it. This is turned off by default, in which case - Boost is not required to build Cantera.""", - False), PathVariable( 'boost_inc_dir', 'Location of the Boost header files.', defaults.boostIncDir, PathVariable.PathAccept), - PathVariable( - 'boost_lib_dir', - 'Directory containing the Boost.Thread library.', - defaults.boostLibDir, PathVariable.PathAccept), - ('boost_thread_lib', - """A comma-separated list containing the names of the libraries needed to - link to Boost.Thread. Autodetection will be attempted if this is left - blank.""", - ''), - ('boost_windows_libs', - """Comma-separated list containing the names of the Boost libraries - required to link Cantera programs on Windows. These libraries will be - copied to the Cantera installation directory.""", - 'thread,system,date_time,chrono'), # default is correct for Boost 1.54 BoolVariable( 'build_with_f2c', """For external procedures written in Fortran 77, both the @@ -695,9 +673,6 @@ if env['CC'] == 'cl': if env['boost_inc_dir']: env.Append(CPPPATH=env['boost_inc_dir']) -if env['boost_lib_dir']: - env.Append(LIBPATH=[env['boost_lib_dir']]) - if env['blas_lapack_dir']: env.Append(LIBPATH=[env['blas_lapack_dir']]) @@ -922,39 +897,6 @@ env['F77FLAGS'] = env['F90FLAGS'] = env['F95FLAGS'] = env['F03FLAGS'] = env['FOR env['FORTRANMODDIR'] = '${TARGET.dir}' -env['boost_libs'] = [] -if env['build_thread_safe']: - env['use_boost_libs'] = True - - # Figure out what needs to be linked for Boost Thread support. Varies with - # OS and Boost version. - boost_ok = False - if env['boost_thread_lib']: - boost_lib_choices = [env['boost_thread_lib'].split(',')] - else: - boost_lib_choices = [[''], ['boost_system'], - ['boost_thread', 'boost_system']] - for bt in boost_lib_choices: - header= "#define BOOST_ALL_NO_LIB\n#include " - call = "boost::mutex foo; boost::mutex::scoped_lock bar(foo);" - - ans = SCons.Conftest.CheckLib(context, - [bt[0]], - header=header, - language='C++', - call=call, - extra_libs=bt[1:] if len(bt)>1 else None, - autoadd=False) - if not ans: - boost_ok = True - print 'Linking Boost.Thread with the following libraries: {0}'.format( - ', '.join(bt) or '') - if bt[0] and env.subst('$CXX') != 'cl': - env['boost_libs'] = bt - break -else: - env['use_boost_libs'] = False - env = conf.Finish() if env['VERBOSE']: @@ -1262,7 +1204,6 @@ cdefine('LAPACK_FTN_STRING_LEN_AT_END', 'lapack_ftn_string_len_at_end') cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore') cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower') -cdefine('THREAD_SAFE_CANTERA', 'build_thread_safe') if not env['HAS_MATH_H_ERF']: if env['HAS_BOOST_MATH']: @@ -1349,14 +1290,6 @@ if addInstallActions: # Data files install('$inst_datadir', mglob(env, 'build/data', 'cti', 'xml')) - # Copy external libaries for Windows installations - if env['CC'] == 'cl' and env['use_boost_libs']: - boost_suffix = '-vc%s-mt-%s.lib' % (env['MSVC_VERSION'].replace('.',''), - env['BOOST_LIB_VERSION']) - for lib in env['boost_windows_libs'].split(','): - install('$inst_libdir', - '$boost_lib_dir/libboost_{0}{1}'.format(lib, boost_suffix)) - # Copy sundials library and header files if env['install_sundials']: for subdir in ['cvode','cvodes','ida','idas','kinsol','nvector','sundials']: @@ -1392,9 +1325,6 @@ if not env['build_with_f2c']: linkLibs.extend(env['FORTRANSYSLIBS']) linkSharedLibs.append(env['FORTRANSYSLIBS']) -linkLibs.extend(env['boost_libs']) -linkSharedLibs.extend(env['boost_libs']) - # Store the list of needed static link libraries in the environment env['cantera_libs'] = linkLibs env['cantera_shared_libs'] = linkSharedLibs diff --git a/doc/sphinx/compiling.rst b/doc/sphinx/compiling.rst index 1154de901..8a9b6b977 100644 --- a/doc/sphinx/compiling.rst +++ b/doc/sphinx/compiling.rst @@ -429,11 +429,6 @@ Other Required Software * Known to work with version 1.54; Expected to work with versions >= 1.41 * Only the "header-only" portions of Boost are required. Cantera does not currently depend on any of the compiled Boost libraries. - * The compiled Boost.Thread library is required to build a thread-safe version - of Cantera (using the ``build_thread_safe`` option to SCons. - * Pre-built Binaries for Windows are available from http://boost.teeks99.com/ . - Make sure to download the file corresponding to your architecture and - Visual Studio version. Optional Programs ----------------- diff --git a/doc/sphinx/scons-options.txt b/doc/sphinx/scons-options.txt index 1d6345cd8..06c24bce7 100644 --- a/doc/sphinx/scons-options.txt +++ b/doc/sphinx/scons-options.txt @@ -292,34 +292,10 @@ running 'scons build'. The format of this file is: list). - default: '' -* build_thread_safe: [ yes | no ] - Cantera can be built so that it is thread safe. Doing so requires - using procedures from the Boost library, so if you want thread - safety then you need to get and install Boost (http://www.boost.org) - if you don't have it. This is turned off by default, in which case - Boost is not required to build Cantera. - - default: 'no' - * boost_inc_dir: [ /path/to/boost_inc_dir ] Location of the Boost header files. - default: '' -* boost_lib_dir: [ /path/to/boost_lib_dir ] - Directory containing the Boost.Thread library. - - default: '' - -* boost_thread_lib: [ string ] - A comma-separated list containing the names of the libraries needed - to link to Boost.Thread. Autodetection will be attempted if this is - left blank. - - default: '' - -* boost_windows_libs: [ string ] - Comma-separated list containing the names of the Boost libraries - required to link Cantera programs on Windows. These libraries will - be copied to the Cantera installation directory. - - default: 'thread,system,date_time,chrono' - * build_with_f2c: [ yes | no ] For external procedures written in Fortran 77, both the original F77 source code and C source code generated by the 'f2c' program are diff --git a/include/cantera/base/FactoryBase.h b/include/cantera/base/FactoryBase.h index 1a5b09e07..d133b9d3b 100644 --- a/include/cantera/base/FactoryBase.h +++ b/include/cantera/base/FactoryBase.h @@ -6,6 +6,7 @@ #define CT_FACTORY_BASE #include +#include namespace Cantera { diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index 018a83ced..6b1f978ba 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -94,9 +94,6 @@ typedef int ftnlen; // Fortran hidden string length type // present to support conversions %(HAS_NO_PYTHON)s -//--------------------- compile options ---------------------------- -%(THREAD_SAFE_CANTERA)s - //-------------- Optional Cantera Capabilities ---------------------- // Enable Sundials to use an external BLAS/LAPACK library if it was diff --git a/include/cantera/base/ct_thread.h b/include/cantera/base/ct_thread.h deleted file mode 100644 index 040c013b2..000000000 --- a/include/cantera/base/ct_thread.h +++ /dev/null @@ -1,56 +0,0 @@ -/*! - * @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; - -class ScopedLock -{ -public: - explicit ScopedLock(const int m) : m_(m) {} - int m_; -}; - -#endif // THREAD_SAFE_CANTERA - -} - -#endif diff --git a/include/cantera/kinetics/FalloffFactory.h b/include/cantera/kinetics/FalloffFactory.h index 503710381..6fba790ba 100644 --- a/include/cantera/kinetics/FalloffFactory.h +++ b/include/cantera/kinetics/FalloffFactory.h @@ -10,7 +10,6 @@ #define CT_NEWFALLOFF_H #include "cantera/base/FactoryBase.h" -#include "cantera/base/ct_thread.h" #include "cantera/kinetics/Falloff.h" namespace Cantera @@ -35,7 +34,7 @@ public: * on all subsequent calls, a pointer to the existing factory is returned. */ static FalloffFactory* factory() { - ScopedLock lock(falloff_mutex); + std::unique_lock lock(falloff_mutex); if (!s_factory) { s_factory = new FalloffFactory; } @@ -43,7 +42,7 @@ public: } virtual void deleteFactory() { - ScopedLock lock(falloff_mutex); + std::unique_lock lock(falloff_mutex); delete s_factory; s_factory = 0; } @@ -68,7 +67,7 @@ private: FalloffFactory() {} //! Mutex for use when calling the factory - static mutex_t falloff_mutex; + static std::mutex falloff_mutex; }; //! @copydoc FalloffFactory::newFalloff diff --git a/include/cantera/kinetics/KineticsFactory.h b/include/cantera/kinetics/KineticsFactory.h index 094e2474f..92bf2b152 100644 --- a/include/cantera/kinetics/KineticsFactory.h +++ b/include/cantera/kinetics/KineticsFactory.h @@ -9,7 +9,6 @@ #include "Kinetics.h" #include "cantera/base/FactoryBase.h" -#include "cantera/base/ct_thread.h" namespace Cantera { @@ -30,7 +29,7 @@ class KineticsFactory : public FactoryBase { public: static KineticsFactory* factory() { - ScopedLock lock(kinetics_mutex); + std::unique_lock lock(kinetics_mutex); if (!s_factory) { s_factory = new KineticsFactory; } @@ -38,7 +37,7 @@ public: } virtual void deleteFactory() { - ScopedLock lock(kinetics_mutex); + std::unique_lock lock(kinetics_mutex); delete s_factory; s_factory = 0; } @@ -72,7 +71,7 @@ public: private: static KineticsFactory* s_factory; KineticsFactory() {} - static mutex_t kinetics_mutex; + static std::mutex kinetics_mutex; }; /** diff --git a/include/cantera/thermo/ThermoFactory.h b/include/cantera/thermo/ThermoFactory.h index fc042b80d..5eb5cacd7 100644 --- a/include/cantera/thermo/ThermoFactory.h +++ b/include/cantera/thermo/ThermoFactory.h @@ -10,7 +10,6 @@ #include "ThermoPhase.h" #include "cantera/base/xml.h" -#include "cantera/base/ct_thread.h" #include "cantera/base/FactoryBase.h" namespace Cantera @@ -55,7 +54,7 @@ class ThermoFactory : public FactoryBase public: //! Static function that creates a static instance of the factory. static ThermoFactory* factory() { - ScopedLock lock(thermo_mutex); + std::unique_lock lock(thermo_mutex); if (!s_factory) { s_factory = new ThermoFactory; } @@ -64,7 +63,7 @@ public: //! delete the static instance of this factory virtual void deleteFactory() { - ScopedLock lock(thermo_mutex); + std::unique_lock lock(thermo_mutex); delete s_factory; s_factory = 0; } @@ -88,7 +87,7 @@ private: ThermoFactory() {}; //! Decl for locking mutex for thermo factory singleton - static mutex_t thermo_mutex; + static std::mutex thermo_mutex; }; //! Create a new thermo manager instance. diff --git a/include/cantera/transport/TransportFactory.h b/include/cantera/transport/TransportFactory.h index 7311bf199..092b22935 100644 --- a/include/cantera/transport/TransportFactory.h +++ b/include/cantera/transport/TransportFactory.h @@ -9,7 +9,6 @@ #define CT_TRANSPORTFACTORY_H // Cantera includes -#include "cantera/base/ct_thread.h" #include "TransportBase.h" #include "cantera/base/FactoryBase.h" #include "LiquidTransportParams.h" @@ -43,7 +42,7 @@ public: * @endcode */ static TransportFactory* factory() { - ScopedLock transportLock(transport_mutex); + std::unique_lock transportLock(transport_mutex); if (!s_factory) { s_factory = new TransportFactory(); } @@ -137,7 +136,7 @@ private: static TransportFactory* s_factory; //! Static instance of the mutex used to ensure the proper reading of the transport database - static mutex_t transport_mutex; + static std::mutex 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 cd0686354..0d06dfaba 100644 --- a/include/cantera/zeroD/ReactorFactory.h +++ b/include/cantera/zeroD/ReactorFactory.h @@ -8,7 +8,6 @@ #include "ReactorBase.h" #include "cantera/base/FactoryBase.h" -#include "cantera/base/ct_thread.h" namespace Cantera { @@ -17,7 +16,7 @@ class ReactorFactory : FactoryBase { public: static ReactorFactory* factory() { - ScopedLock lock(reactor_mutex); + std::unique_lock lock(reactor_mutex); if (!s_factory) { s_factory = new ReactorFactory; } @@ -25,7 +24,7 @@ public: } virtual void deleteFactory() { - ScopedLock lock(reactor_mutex); + std::unique_lock lock(reactor_mutex); delete s_factory; s_factory = 0; } @@ -39,7 +38,7 @@ public: private: static ReactorFactory* s_factory; - static mutex_t reactor_mutex; + static std::mutex reactor_mutex; ReactorFactory() {} }; diff --git a/platform/posix/Cantera.mak.in b/platform/posix/Cantera.mak.in index 320d201e9..25ae07b2c 100644 --- a/platform/posix/Cantera.mak.in +++ b/platform/posix/Cantera.mak.in @@ -51,7 +51,6 @@ CANTERA_SYSLIBS=@mak_syslibs@ ############################################################################### CANTERA_BOOST_INCLUDES=@mak_boost_include@ -CANTERA_BOOST_LIBS=@mak_boost_libdir@ @mak_boost_libs@ ############################################################################### # CVODE/SUNDIALS LINKAGE @@ -80,8 +79,7 @@ CANTERA_DEFINES = -DCANTERA_VERSION=@cantera_version@ CANTERA_LIBS=$(CANTERA_CORE_LIBS) \ $(CANTERA_EXTRA_LIBDIRS) $(CANTERA_SUNDIALS_LIBS) \ - $(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_BOOST_LIBS) \ - $(CANTERA_SYSLIBS) + $(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_SYSLIBS) CANTERA_TOTAL_LIBS=$(CANTERA_LIBS) @@ -90,8 +88,7 @@ CANTERA_TOTAL_LIBS_DEP= $(CANTERA_CORE_LIBS_DEP) \ CANTERA_FORTRAN_LIBS=$(CANTERA_CORE_FTN) \ $(CANTERA_EXTRA_LIBDIRS) $(CANTERA_SUNDIALS_LIBS) \ - $(CANTERA_BLAS_LAPACK_LIBS) \ - $(CANTERA_BOOST_LIBS) $(CANTERA_FORTRAN_SYSLIBS) + $(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_FORTRAN_SYSLIBS) ############################################################################### # END diff --git a/platform/posix/SConscript b/platform/posix/SConscript index 3fb6f7fa5..360dc9377 100644 --- a/platform/posix/SConscript +++ b/platform/posix/SConscript @@ -68,15 +68,6 @@ if localenv['boost_inc_dir']: else: localenv['mak_boost_include'] = '' -if localenv['boost_lib_dir'] and localenv['use_boost_libs']: - localenv['mak_boost_libdir'] = '-L' + localenv['boost_lib_dir'] - pc_libdirs.append(localenv['boost_lib_dir']) -else: - localenv['mak_boost_libdir'] = '' - -localenv['mak_boost_libs'] = ' '.join('-l%s' % s for s in localenv['boost_libs']) -pc_libs += localenv['boost_libs'] - # Handle BLAS/LAPACK linkage localenv['mak_blas_lapack_libs'] = ' '.join('-l%s' % s for s in localenv['blas_lapack_libs']) diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index 31ef1bb4c..59982464e 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -45,8 +45,7 @@ for subdir, name, extensions in samples: incdirs = (localenv['ct_incroot'], localenv['sundials_include'], localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs']) libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir'], localenv['boost_lib_dir']) + - tuple(localenv['extra_lib_dirs'])) + localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = (debug_link_flag, localenv['thread_flags']) localenv['tmpl_compiler_flags'] = repr(compilerFlags) localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS']) diff --git a/samples/f77/SConscript b/samples/f77/SConscript index 5f33be124..02bf6cfd8 100644 --- a/samples/f77/SConscript +++ b/samples/f77/SConscript @@ -22,8 +22,7 @@ incdirs = (localenv['ct_incroot'], localenv['sundials_include'], localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs']) libs = ['cantera_fortran'] + localenv['cantera_libs'] + ['stdc++'] libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir'], localenv['boost_lib_dir']) + - tuple(localenv['extra_lib_dirs'])) + localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags']) mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak') diff --git a/samples/f90/SConscript b/samples/f90/SConscript index e2fbf55a5..7ffee1dea 100644 --- a/samples/f90/SConscript +++ b/samples/f90/SConscript @@ -16,8 +16,7 @@ for programName, sources in samples: incdirs = [pjoin(localenv['ct_incroot'], 'cantera')] + localenv['extra_inc_dirs'] libs = ['cantera_fortran'] + localenv['cantera_libs'] + ['stdc++'] libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir'], localenv['boost_lib_dir']) + - tuple(localenv['extra_lib_dirs'])) + localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags']) mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak') diff --git a/src/SConscript b/src/SConscript index 2c1f2e57b..6fa2e158a 100644 --- a/src/SConscript +++ b/src/SConscript @@ -62,9 +62,6 @@ if localenv['OS'] in ('Darwin', 'Windows', 'Cygwin'): if localenv['blas_lapack_libs']: localenv.Append(LIBS=localenv['blas_lapack_libs'], LIBPATH=localenv['blas_lapack_dir']) - if localenv['boost_libs']: - localenv.Append(LIBS=localenv['boost_libs'], - LIBPATH=localenv['boost_lib_dir']) # Build the Cantera shared library if localenv['layout'] != 'debian': diff --git a/src/base/ValueCache.cpp b/src/base/ValueCache.cpp index f071b2e77..fd7b89416 100644 --- a/src/base/ValueCache.cpp +++ b/src/base/ValueCache.cpp @@ -3,11 +3,11 @@ */ #include "cantera/base/ValueCache.h" -#include "cantera/base/ct_thread.h" +#include namespace { -Cantera::mutex_t id_mutex; +std::mutex id_mutex; } namespace Cantera @@ -17,7 +17,7 @@ int ValueCache::m_last_id = 0; int ValueCache::getId() { - ScopedLock lock(id_mutex); + std::unique_lock lock(id_mutex); return ++m_last_id; } diff --git a/src/base/application.cpp b/src/base/application.cpp index 05f46ec93..d3f5407bd 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -7,6 +7,7 @@ #include #include +#include using std::string; using std::endl; @@ -24,29 +25,14 @@ using std::endl; 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. - -#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 mutex_t dir_mutex; +static std::mutex dir_mutex; //! Mutex for creating singletons within the application object -static mutex_t app_mutex; +static std::mutex app_mutex; //! Mutex for controlling access to XML file storage -static mutex_t xml_mutex; +static std::mutex xml_mutex; static int get_modified_time(const std::string& path) { #ifdef _WIN32 @@ -119,15 +105,13 @@ void Application::Messages::writelogendl() logwriter->writeendl(); } -#ifdef THREAD_SAFE_CANTERA - //! Mutex for access to string messages -static mutex_t msg_mutex; +static std::mutex msg_mutex; Application::Messages* Application::ThreadMessages::operator ->() { - ScopedLock msgLock(msg_mutex); - cthreadId_t curId = getThisThreadId(); + std::unique_lock msgLock(msg_mutex); + std::thread::id curId = std::this_thread::get_id(); auto iter = m_threadMsgMap.find(curId); if (iter != m_threadMsgMap.end()) { return iter->second.get(); @@ -139,33 +123,26 @@ Application::Messages* Application::ThreadMessages::operator ->() void Application::ThreadMessages::removeThreadMessages() { - ScopedLock msgLock(msg_mutex); - cthreadId_t curId = getThisThreadId(); + std::unique_lock msgLock(msg_mutex); + std::thread::id curId = std::this_thread::get_id(); auto iter = m_threadMsgMap.find(curId); if (iter != m_threadMsgMap.end()) { m_threadMsgMap.erase(iter); } } -#endif // THREAD_SAFE_CANTERA Application::Application() : m_suppress_deprecation_warnings(false) { -#if !defined( THREAD_SAFE_CANTERA ) - pMessenger = std::unique_ptr(new Messages()); -#endif - // install a default logwriter that writes to standard // output / standard error setDefaultDirectories(); -#if defined(THREAD_SAFE_CANTERA) Unit::units(); -#endif } Application* Application::Instance() { - ScopedLock appLock(app_mutex); + std::unique_lock appLock(app_mutex); if (Application::s_app == 0) { Application::s_app = new Application(); } @@ -183,7 +160,7 @@ Application::~Application() void Application::ApplicationDestroy() { - ScopedLock appLock(app_mutex); + std::unique_lock appLock(app_mutex); if (Application::s_app != 0) { delete Application::s_app; Application::s_app = 0; @@ -203,14 +180,12 @@ void Application::warn_deprecated(const std::string& method, void Application::thread_complete() { -#if defined(THREAD_SAFE_CANTERA) pMessenger.removeThreadMessages(); -#endif } XML_Node* Application::get_XML_File(const std::string& file, int debug) { - ScopedLock xmlLock(xml_mutex); + std::unique_lock xmlLock(xml_mutex); std::string path = ""; path = findInputFile(file); int mtime = get_modified_time(path); @@ -256,7 +231,7 @@ XML_Node* Application::get_XML_File(const std::string& file, int debug) XML_Node* Application::get_XML_from_string(const std::string& text) { - ScopedLock xmlLock(xml_mutex); + std::unique_lock xmlLock(xml_mutex); std::pair& entry = xmlfiles[text]; if (entry.first) { // Return existing cached XML tree @@ -276,7 +251,7 @@ XML_Node* Application::get_XML_from_string(const std::string& text) void Application::close_XML_File(const std::string& file) { - ScopedLock xmlLock(xml_mutex); + std::unique_lock xmlLock(xml_mutex); if (file == "all") { for (const auto& f : xmlfiles) { f.second.first->unlock(); @@ -444,7 +419,7 @@ void Application::setDefaultDirectories() void Application::addDataDirectory(const std::string& dir) { - ScopedLock dirLock(dir_mutex); + std::unique_lock dirLock(dir_mutex); if (inputDirs.empty()) { setDefaultDirectories(); } @@ -462,7 +437,7 @@ void Application::addDataDirectory(const std::string& dir) std::string Application::findInputFile(const std::string& name) { - ScopedLock dirLock(dir_mutex); + std::unique_lock 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 6731c15e5..176e74583 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -3,10 +3,10 @@ #define CT_BASE_APPLICATION_H #include "cantera/base/config.h" -#include "cantera/base/ct_thread.h" #include "cantera/base/logger.h" #include +#include namespace Cantera { @@ -154,9 +154,8 @@ protected: std::unique_ptr logwriter; }; -#ifdef THREAD_SAFE_CANTERA //! Typedef for thread specific messages - typedef boost::shared_ptr< Messages > pMessages_t; + typedef shared_ptr pMessages_t; //! Class that stores thread messages for each thread, and retrieves them //! based on the thread id. @@ -176,13 +175,12 @@ protected: void removeThreadMessages(); //! Typedef for map between a thread and the message - typedef std::map< cthreadId_t, pMessages_t > threadMsgMap_t; + typedef std::map threadMsgMap_t; private: //! Thread Msg Map threadMsgMap_t m_threadMsgMap; }; -#endif protected: //! Constructor for class sets up the initial conditions @@ -383,11 +381,7 @@ protected: bool m_suppress_deprecation_warnings; -#if defined(THREAD_SAFE_CANTERA) ThreadMessages pMessenger; -#else - std::unique_ptr pMessenger; -#endif private: //! Pointer to the single Application instance diff --git a/src/base/global.cpp b/src/base/global.cpp index 63db0fdb0..ab5eeb4ce 100644 --- a/src/base/global.cpp +++ b/src/base/global.cpp @@ -61,7 +61,7 @@ void suppress_deprecation_warnings() // **************** Global Data **************** Unit* Unit::s_u = 0; -mutex_t Unit::units_mutex; +std::mutex Unit::units_mutex; void appdelete() { diff --git a/src/base/units.h b/src/base/units.h index d143b3eee..e0a18af14 100644 --- a/src/base/units.h +++ b/src/base/units.h @@ -13,7 +13,7 @@ #include "cantera/base/ct_defs.h" #include "cantera/base/ctexceptions.h" -#include "cantera/base/ct_thread.h" +#include namespace Cantera { @@ -27,7 +27,7 @@ class Unit public: //! Initialize the static Unit class. static Unit* units() { - ScopedLock lock(units_mutex); + std::unique_lock lock(units_mutex); if (!s_u) { s_u = new Unit; } @@ -39,7 +39,7 @@ public: * Note this can't be done in a destructor. */ static void deleteUnit() { - ScopedLock lock(units_mutex); + std::unique_lock lock(units_mutex); delete s_u; s_u = 0; } @@ -156,7 +156,7 @@ private: std::map m_act_u; //! Decl for static locker for Units singleton - static mutex_t units_mutex; + static std::mutex 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 ccb11b423..b40fdc242 100644 --- a/src/kinetics/FalloffFactory.cpp +++ b/src/kinetics/FalloffFactory.cpp @@ -10,7 +10,7 @@ namespace Cantera { FalloffFactory* FalloffFactory::s_factory = 0; -mutex_t FalloffFactory::falloff_mutex; +std::mutex FalloffFactory::falloff_mutex; Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c) { diff --git a/src/kinetics/KineticsFactory.cpp b/src/kinetics/KineticsFactory.cpp index 2b8a505fd..3a9534f0e 100644 --- a/src/kinetics/KineticsFactory.cpp +++ b/src/kinetics/KineticsFactory.cpp @@ -17,7 +17,7 @@ namespace Cantera { KineticsFactory* KineticsFactory::s_factory = 0; -mutex_t KineticsFactory::kinetics_mutex; +std::mutex KineticsFactory::kinetics_mutex; Kinetics* KineticsFactory::newKinetics(XML_Node& phaseData, vector th) diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 24abb53c6..4092b0225 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -55,7 +55,7 @@ namespace Cantera { ThermoFactory* ThermoFactory::s_factory = 0; -mutex_t ThermoFactory::thermo_mutex; +std::mutex ThermoFactory::thermo_mutex; //! Define the number of ThermoPhase types for use in this factory routine static int ntypes = 27; diff --git a/src/thermo/VPSSMgrFactory.cpp b/src/thermo/VPSSMgrFactory.cpp index ead0cccdf..118c99007 100644 --- a/src/thermo/VPSSMgrFactory.cpp +++ b/src/thermo/VPSSMgrFactory.cpp @@ -32,7 +32,7 @@ namespace Cantera VPSSMgrFactory* VPSSMgrFactory::s_factory = 0; // Defn of the static mutex variable that locks the VPSSMgr factory singleton -mutex_t VPSSMgrFactory::vpss_species_thermo_mutex; +std::mutex 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. @@ -171,7 +171,7 @@ static void getVPSSMgrTypes(std::vector & spDataNodeList, void VPSSMgrFactory::deleteFactory() { - ScopedLock lock(vpss_species_thermo_mutex); + std::unique_lock lock(vpss_species_thermo_mutex); delete s_factory; s_factory = 0; } diff --git a/src/thermo/VPSSMgrFactory.h b/src/thermo/VPSSMgrFactory.h index 808fad9a6..9ea0a4f1d 100644 --- a/src/thermo/VPSSMgrFactory.h +++ b/src/thermo/VPSSMgrFactory.h @@ -15,7 +15,6 @@ #include "cantera/base/ctexceptions.h" #include "cantera/base/FactoryBase.h" -#include "cantera/base/ct_thread.h" #include "cantera/thermo/VPSSMgr.h" namespace Cantera @@ -78,7 +77,7 @@ public: * instance. */ static VPSSMgrFactory* factory() { - ScopedLock lock(vpss_species_thermo_mutex); + std::unique_lock lock(vpss_species_thermo_mutex); if (!s_factory) { s_factory = new VPSSMgrFactory; } @@ -137,7 +136,7 @@ private: //! Decl of the static mutex variable that locks the //! VPSSMgr factory singleton - static mutex_t vpss_species_thermo_mutex; + static std::mutex 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 135e30704..e684fd06a 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -25,7 +25,7 @@ namespace Cantera TransportFactory* TransportFactory::s_factory = 0; // declaration of static storage for the mutex -mutex_t TransportFactory::transport_mutex; +std::mutex TransportFactory::transport_mutex; //! Exception thrown if an error is encountered while reading the transport database class TransportDBError : public CanteraError @@ -91,7 +91,7 @@ TransportFactory::TransportFactory() void TransportFactory::deleteFactory() { - ScopedLock transportLock(transport_mutex); + std::unique_lock transportLock(transport_mutex); delete s_factory; s_factory = 0; } diff --git a/src/zeroD/ReactorFactory.cpp b/src/zeroD/ReactorFactory.cpp index bafdf456d..d25ef9439 100644 --- a/src/zeroD/ReactorFactory.cpp +++ b/src/zeroD/ReactorFactory.cpp @@ -16,7 +16,7 @@ namespace Cantera { ReactorFactory* ReactorFactory::s_factory = 0; -mutex_t ReactorFactory::reactor_mutex; +std::mutex ReactorFactory::reactor_mutex; static int ntypes = 6; static string _types[] = {"Reservoir", "Reactor", "ConstPressureReactor",