diff --git a/SConstruct b/SConstruct index a7b2c4897..cc067c378 100644 --- a/SConstruct +++ b/SConstruct @@ -699,6 +699,9 @@ 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['use_sundials'] == 'default' and (env['sundials_include'] or env['sundials_libdir'])): env['use_sundials'] = 'y' @@ -1002,7 +1005,7 @@ env['config_h_target'] = config_h if env['build_thread_safe']: env['use_boost_libs'] = True - env['boost_libs'] = env['boost_thread_lib'] + env['boost_libs'] = [env['boost_thread_lib']] else: env['use_boost_libs'] = False env['boost_libs'] = [] diff --git a/src/base/application.cpp b/src/base/application.cpp index 894fd5c8d..aab5df274 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -4,6 +4,7 @@ #include "cantera/base/ctml.h" #include "cantera/base/stringUtils.h" #include "cantera/base/xml.h" +#include "units.h" #include #include @@ -20,6 +21,8 @@ using std::endl; #pragma comment(lib, "advapi32") #endif +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 @@ -27,8 +30,6 @@ using std::endl; #ifdef THREAD_SAFE_CANTERA -#include -#include //! Mutex for input directory access static boost::mutex dir_mutex; @@ -62,7 +63,7 @@ static boost::mutex xml_mutex; #endif #if defined(BOOST_HAS_WINTHREADS) -typedef unsigned int cthreadId_t ; + class thread_equal { public: @@ -116,8 +117,6 @@ cthreadId_t getThisThreadId() #endif -namespace Cantera { - Application::Messages::Messages() : errorMessage(0), errorRoutine(0), @@ -371,6 +370,31 @@ void Application::Messages::write_logfile(std::string file) #endif // WITH_HTML_LOGS +#ifdef THREAD_SAFE_CANTERA +Application::Messages* Application::ThreadMessages::operator ->() +{ + MSG_LOCK() ; + cthreadId_t curId = getThisThreadId() ; + threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; + if (iter != m_threadMsgMap.end()) { + return (iter->second.get()) ; + } + pMessages_t pMsgs(new Messages()) ; + m_threadMsgMap.insert(std::pair< cthreadId_t, pMessages_t >(curId, pMsgs)) ; + return pMsgs.get() ; +} + +void Application::ThreadMessages::removeThreadMessages() +{ + MSG_LOCK() ; + cthreadId_t curId = getThisThreadId() ; + threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; + if (iter != m_threadMsgMap.end()) { + m_threadMsgMap.erase(iter) ; + } +} +#endif // THREAD_SAFE_CANTERA + Application::Application() : inputDirs(0), stop_on_error(false), diff --git a/src/base/application.h b/src/base/application.h index 3b2dae26b..eb7002901 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -4,6 +4,11 @@ #include "cantera/base/config.h" #include "cantera/base/logger.h" +#ifdef THREAD_SAFE_CANTERA +#include +#include +#endif + #include #include #include @@ -23,6 +28,16 @@ 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; +#elif defined(BOOST_HAS_MPTASKS) +typedef MPTaskID cthreadId_t; +#endif + +#endif //! Class to hold global data. /*! @@ -309,43 +324,25 @@ protected: //! Typedef for thread specific messages typedef boost::shared_ptr< Messages > pMessages_t ; - //! Typedef for map between a thread and the message - typedef std::map< cthreadId_t, pMessages_t > threadMsgMap_t ; - //! Class that stores thread messages for each thread, and retrieves them //! based on the thread id. class ThreadMessages { public: //! Constructor - ThreadMessages() { - } + ThreadMessages() {} //! Provide a pointer deferencing overloaded operator /*! * @return returns a pointer to Messages */ - Messages* operator->() { - MSG_LOCK() ; - cthreadId_t curId = getThisThreadId() ; - threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; - if (iter != m_threadMsgMap.end()) { - return (iter->second.get()) ; - } - pMessages_t pMsgs(new Messages()) ; - m_threadMsgMap.insert(std::pair< cthreadId_t, pMessages_t >(curId, pMsgs)) ; - return pMsgs.get() ; - } + Messages* operator->(); //! Remove a local thread message - void removeThreadMessages() { - MSG_LOCK() ; - cthreadId_t curId = getThisThreadId() ; - threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId) ; - if (iter != m_threadMsgMap.end()) { - m_threadMsgMap.erase(iter) ; - } - } + void removeThreadMessages(); + + //! Typedef for map between a thread and the message + typedef std::map< cthreadId_t, pMessages_t > threadMsgMap_t ; private: //! Thread Msg Map