diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index 22c3301..f0be3f0 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -8,7 +8,16 @@ #define CHAISCRIPT_THREADING_HPP_ #ifndef CHAISCRIPT_NO_THREADS + +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wc++11-long-long" +#pragma clang diagnostic ignored "-Wshadow" +#endif #include +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif #else #pragma message ("ChaiScript is compiling without thread safety.") #endif diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 59f777e..14e0530 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -13,7 +13,19 @@ #include #include + +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wshadow" +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif + #include + +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif + #include #include #include diff --git a/include/chaiscript/dispatchkit/exception_specification.hpp b/include/chaiscript/dispatchkit/exception_specification.hpp index 7770d11..b1fa687 100644 --- a/include/chaiscript/dispatchkit/exception_specification.hpp +++ b/include/chaiscript/dispatchkit/exception_specification.hpp @@ -17,6 +17,8 @@ namespace chaiscript { virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0; + virtual ~Exception_Handler_Base() {} + protected: template void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine) @@ -28,6 +30,8 @@ namespace chaiscript template struct Exception_Handler_Impl1 : Exception_Handler_Base { + virtual ~Exception_Handler_Impl1() {} + virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) { throw_type(bv, t_engine); @@ -36,6 +40,8 @@ namespace chaiscript template struct Exception_Handler_Impl2 : Exception_Handler_Base { + virtual ~Exception_Handler_Impl2() {} + virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) { throw_type(bv, t_engine); @@ -46,6 +52,8 @@ namespace chaiscript template struct Exception_Handler_Impl3 : Exception_Handler_Base { + virtual ~Exception_Handler_Impl3() {} + virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) { throw_type(bv, t_engine); @@ -56,6 +64,8 @@ namespace chaiscript template struct Exception_Handler_Impl4 : Exception_Handler_Base { + virtual ~Exception_Handler_Impl4() {} + virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) { throw_type(bv, t_engine); @@ -67,6 +77,8 @@ namespace chaiscript template struct Exception_Handler_Impl5 : Exception_Handler_Base { + virtual ~Exception_Handler_Impl5() {} + virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) { throw_type(bv, t_engine); diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 7ae0955..fb7980a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -86,9 +86,16 @@ namespace chaiscript * if any unboxing fails the execution of the function fails and * the bad_boxed_cast is passed up to the caller. */ +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif template Ret call_func(const boost::function &f, - const std::vector ¶ms, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, )) + const std::vector ¶ms, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, BOOST_PP_EMPTY)) +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif { if (params.size() != n) { @@ -103,9 +110,17 @@ namespace chaiscript * Proxy_Function_Impl object. This function is primarly used to prevent * registration of two functions with the exact same signatures */ - template + +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif + template bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)), - const std::vector & BOOST_PP_IF(n, params, ), const Dynamic_Cast_Conversions &t_conversions) + const std::vector & BOOST_PP_IF(n, params, BOOST_PP_EMPTY), const Dynamic_Cast_Conversions &t_conversions) +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif { try { (void)t_conversions; diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index b21cfd2..32d9e32 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -420,19 +420,20 @@ namespace chaiscript try { const std::string appendedpath = m_usepaths[i] + t_filename; - chaiscript::detail::threading::lock_guard l(m_use_mutex); - chaiscript::detail::threading::shared_lock l2(m_mutex); + chaiscript::detail::threading::unique_lock l(m_use_mutex); + chaiscript::detail::threading::unique_lock l2(m_mutex); if (m_used_files.count(appendedpath) == 0) { - m_used_files.insert(appendedpath); l2.unlock(); eval_file(appendedpath); - } + l2.lock(); + m_used_files.insert(appendedpath); + } return; // return, we loaded it, or it was already loaded } catch (const exception::file_not_found_error &) { - if (i == m_usepaths.size() - 1) + if (i == m_usepaths.size() - 1) { throw exception::file_not_found_error(t_filename); } diff --git a/samples/example.cpp b/samples/example.cpp index 0164638..086f60d 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -9,7 +9,18 @@ #include #include #include + +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#endif + #include + +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif + #include void log(const std::string &msg) diff --git a/src/reflection.cpp b/src/reflection.cpp index 2027c47..71408e2 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -42,6 +42,12 @@ chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t } +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + + CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection() { chaiscript::ModulePtr m(new chaiscript::Module()); @@ -90,6 +96,11 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect return m; } +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif + + #ifdef BOOST_MSVC #pragma warning(pop) diff --git a/src/stl_extra.cpp b/src/stl_extra.cpp index 59a542a..2045fe9 100644 --- a/src/stl_extra.cpp +++ b/src/stl_extra.cpp @@ -10,11 +10,19 @@ #pragma warning(disable : 4190) #endif +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extra() { return chaiscript::bootstrap::standard_library::list_type >("List"); } +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif #ifdef BOOST_MSVC #pragma warning(pop) diff --git a/src/test_module.cpp b/src/test_module.cpp index 313d29a..df68b58 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -49,6 +49,10 @@ int *get_new_int() #pragma warning(disable : 4190) #endif +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_module() { @@ -86,6 +90,10 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo } +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif + #ifdef BOOST_MSVC #pragma warning(pop) #endif diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 0814bb6..731a4ff 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -25,13 +25,17 @@ int expected_value(int num_iters) void do_work(chaiscript::ChaiScript &c, int id) { - std::stringstream ss; - ss << "MyVar" << rand(); - c.add(chaiscript::var(5), ss.str()); - ss.str(""); - ss << id; - c.use("multithreaded_work.inc"); - c("do_chai_work(4000, " + ss.str() + ");"); + try{ + std::stringstream ss; + ss << "MyVar" << rand(); + c.add(chaiscript::var(5), ss.str()); + ss.str(""); + ss << id; + c.use("multithreaded_work.inc"); + c("do_chai_work(4000, " + ss.str() + ");"); + } catch (const std::exception &e) { + std::cout << "exception: " << e.what() << " thread: " << id; + } } int main() @@ -65,20 +69,17 @@ int main() chaiscript::ChaiScript chai(modulepaths,usepaths); - std::vector > threads; + boost::thread_group threads; // Ensure at least two, but say only 7 on an 8 core processor int num_threads = std::max(boost::thread::hardware_concurrency() - 1, 2u); for (int i = 0; i < num_threads; ++i) { - threads.push_back(boost::shared_ptr(new boost::thread(boost::bind(do_work, boost::ref(chai), i)))); + threads.create_thread(boost::bind(&do_work, boost::ref(chai), i)); } - for (int i = 0; i < num_threads; ++i) - { - threads[i]->join(); - } + threads.join_all(); for (int i = 0; i < num_threads; ++i)