Use locks/mutexes from the standard library instead of Boost.Thread

This eliminates the need to link against any of the compiled Boost libraries,
and means that we can always build in thread-safe mode
This commit is contained in:
Ray Speth 2015-10-09 18:24:54 -04:00
parent a03f370cfd
commit f9375e1a09
30 changed files with 59 additions and 271 deletions

View file

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

View file

@ -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 <boost/thread/thread.hpp>"
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 '<none>')
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

View file

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

View file

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

View file

@ -6,6 +6,7 @@
#define CT_FACTORY_BASE
#include <vector>
#include <mutex>
namespace Cantera
{

View file

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

View file

@ -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 <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#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

View file

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

View file

@ -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<std::mutex> 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<std::mutex> 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;
};
/**

View file

@ -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<std::mutex> 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<std::mutex> 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.

View file

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

View file

@ -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<std::mutex> 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<std::mutex> 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() {}
};

View file

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

View file

@ -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'])

View file

@ -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'])

View file

@ -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')

View file

@ -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')

View file

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

View file

@ -3,11 +3,11 @@
*/
#include "cantera/base/ValueCache.h"
#include "cantera/base/ct_thread.h"
#include <mutex>
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<std::mutex> lock(id_mutex);
return ++m_last_id;
}

View file

@ -7,6 +7,7 @@
#include <fstream>
#include <sstream>
#include <mutex>
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<std::mutex> 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<std::mutex> 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<Messages>(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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> xmlLock(xml_mutex);
std::pair<XML_Node*, int>& 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<std::mutex> 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<std::mutex> 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<std::mutex> dirLock(dir_mutex);
string::size_type islash = name.find('/');
string::size_type ibslash = name.find('\\');
string inname;

View file

@ -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 <set>
#include <thread>
namespace Cantera
{
@ -154,9 +154,8 @@ protected:
std::unique_ptr<Logger> logwriter;
};
#ifdef THREAD_SAFE_CANTERA
//! Typedef for thread specific messages
typedef boost::shared_ptr< Messages > pMessages_t;
typedef shared_ptr<Messages> 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<std::thread::id, pMessages_t> 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<Messages> pMessenger;
#endif
private:
//! Pointer to the single Application instance

View file

@ -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()
{

View file

@ -13,7 +13,7 @@
#include "cantera/base/ct_defs.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/base/ct_thread.h"
#include <mutex>
namespace Cantera
{
@ -27,7 +27,7 @@ class Unit
public:
//! Initialize the static Unit class.
static Unit* units() {
ScopedLock lock(units_mutex);
std::unique_lock<std::mutex> 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<std::mutex> lock(units_mutex);
delete s_u;
s_u = 0;
}
@ -156,7 +156,7 @@ private:
std::map<std::string, doublereal> 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.

View file

@ -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)
{

View file

@ -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<ThermoPhase*> th)

View file

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

View file

@ -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<XML_Node*> & spDataNodeList,
void VPSSMgrFactory::deleteFactory()
{
ScopedLock lock(vpss_species_thermo_mutex);
std::unique_lock<std::mutex> lock(vpss_species_thermo_mutex);
delete s_factory;
s_factory = 0;
}

View file

@ -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<std::mutex> 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.

View file

@ -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<std::mutex> transportLock(transport_mutex);
delete s_factory;
s_factory = 0;
}

View file

@ -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",