- Fix legit threading issue which shows itself on clang / macos mostly

- Fix all warnings that I can / ignore those caused by boost
This commit is contained in:
Jason Turner
2013-05-26 22:47:23 -06:00
parent feb344e744
commit 101225aa68
10 changed files with 109 additions and 21 deletions

View File

@@ -8,7 +8,16 @@
#define CHAISCRIPT_THREADING_HPP_ #define CHAISCRIPT_THREADING_HPP_
#ifndef CHAISCRIPT_NO_THREADS #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 <boost/thread.hpp> #include <boost/thread.hpp>
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#else #else
#pragma message ("ChaiScript is compiling without thread safety.") #pragma message ("ChaiScript is compiling without thread safety.")
#endif #endif

View File

@@ -13,7 +13,19 @@
#include <map> #include <map>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#include <boost/any.hpp> #include <boost/any.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>

View File

@@ -17,6 +17,8 @@ namespace chaiscript
{ {
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0; virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0;
virtual ~Exception_Handler_Base() {}
protected: protected:
template<typename T> template<typename T>
void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine) void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
@@ -28,6 +30,8 @@ namespace chaiscript
template<typename T1> template<typename T1>
struct Exception_Handler_Impl1 : Exception_Handler_Base struct Exception_Handler_Impl1 : Exception_Handler_Base
{ {
virtual ~Exception_Handler_Impl1() {}
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
{ {
throw_type<T1>(bv, t_engine); throw_type<T1>(bv, t_engine);
@@ -36,6 +40,8 @@ namespace chaiscript
template<typename T1, typename T2> template<typename T1, typename T2>
struct Exception_Handler_Impl2 : Exception_Handler_Base struct Exception_Handler_Impl2 : Exception_Handler_Base
{ {
virtual ~Exception_Handler_Impl2() {}
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
{ {
throw_type<T1>(bv, t_engine); throw_type<T1>(bv, t_engine);
@@ -46,6 +52,8 @@ namespace chaiscript
template<typename T1, typename T2, typename T3> template<typename T1, typename T2, typename T3>
struct Exception_Handler_Impl3 : Exception_Handler_Base struct Exception_Handler_Impl3 : Exception_Handler_Base
{ {
virtual ~Exception_Handler_Impl3() {}
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
{ {
throw_type<T1>(bv, t_engine); throw_type<T1>(bv, t_engine);
@@ -56,6 +64,8 @@ namespace chaiscript
template<typename T1, typename T2, typename T3, typename T4> template<typename T1, typename T2, typename T3, typename T4>
struct Exception_Handler_Impl4 : Exception_Handler_Base struct Exception_Handler_Impl4 : Exception_Handler_Base
{ {
virtual ~Exception_Handler_Impl4() {}
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
{ {
throw_type<T1>(bv, t_engine); throw_type<T1>(bv, t_engine);
@@ -67,6 +77,8 @@ namespace chaiscript
template<typename T1, typename T2, typename T3, typename T4, typename T5> template<typename T1, typename T2, typename T3, typename T4, typename T5>
struct Exception_Handler_Impl5 : Exception_Handler_Base struct Exception_Handler_Impl5 : Exception_Handler_Base
{ {
virtual ~Exception_Handler_Impl5() {}
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
{ {
throw_type<T1>(bv, t_engine); throw_type<T1>(bv, t_engine);

View File

@@ -86,9 +86,16 @@ namespace chaiscript
* if any unboxing fails the execution of the function fails and * if any unboxing fails the execution of the function fails and
* the bad_boxed_cast is passed up to the caller. * the bad_boxed_cast is passed up to the caller.
*/ */
#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)> template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
Ret call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f, Ret call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f,
const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, )) const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, BOOST_PP_EMPTY))
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
{ {
if (params.size() != n) if (params.size() != n)
{ {
@@ -103,9 +110,17 @@ namespace chaiscript
* Proxy_Function_Impl object. This function is primarly used to prevent * Proxy_Function_Impl object. This function is primarly used to prevent
* registration of two functions with the exact same signatures * registration of two functions with the exact same signatures
*/ */
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)), bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)),
const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, ), const Dynamic_Cast_Conversions &t_conversions) const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, BOOST_PP_EMPTY), const Dynamic_Cast_Conversions &t_conversions)
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
{ {
try { try {
(void)t_conversions; (void)t_conversions;

View File

@@ -420,19 +420,20 @@ namespace chaiscript
try { try {
const std::string appendedpath = m_usepaths[i] + t_filename; const std::string appendedpath = m_usepaths[i] + t_filename;
chaiscript::detail::threading::lock_guard<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex); chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex); chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
if (m_used_files.count(appendedpath) == 0) if (m_used_files.count(appendedpath) == 0)
{ {
m_used_files.insert(appendedpath);
l2.unlock(); l2.unlock();
eval_file(appendedpath); eval_file(appendedpath);
} l2.lock();
m_used_files.insert(appendedpath);
}
return; // return, we loaded it, or it was already loaded return; // return, we loaded it, or it was already loaded
} catch (const exception::file_not_found_error &) { } 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); throw exception::file_not_found_error(t_filename);
} }

View File

@@ -9,7 +9,18 @@
#include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript.hpp>
#include <chaiscript/dispatchkit/function_call.hpp> #include <chaiscript/dispatchkit/function_call.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#ifdef __llvm__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#include <boost/regex.hpp> #include <boost/regex.hpp>
void log(const std::string &msg) void log(const std::string &msg)

View File

@@ -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_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection()
{ {
chaiscript::ModulePtr m(new chaiscript::Module()); chaiscript::ModulePtr m(new chaiscript::Module());
@@ -90,6 +96,11 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
return m; return m;
} }
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning(pop) #pragma warning(pop)

View File

@@ -10,11 +10,19 @@
#pragma warning(disable : 4190) #pragma warning(disable : 4190)
#endif #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() CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extra()
{ {
return chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List"); return chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List");
} }
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning(pop) #pragma warning(pop)

View File

@@ -49,6 +49,10 @@ int *get_new_int()
#pragma warning(disable : 4190) #pragma warning(disable : 4190)
#endif #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() 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 #ifdef BOOST_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif

View File

@@ -25,13 +25,17 @@ int expected_value(int num_iters)
void do_work(chaiscript::ChaiScript &c, int id) void do_work(chaiscript::ChaiScript &c, int id)
{ {
std::stringstream ss; try{
ss << "MyVar" << rand(); std::stringstream ss;
c.add(chaiscript::var(5), ss.str()); ss << "MyVar" << rand();
ss.str(""); c.add(chaiscript::var(5), ss.str());
ss << id; ss.str("");
c.use("multithreaded_work.inc"); ss << id;
c("do_chai_work(4000, " + ss.str() + ");"); 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() int main()
@@ -65,20 +69,17 @@ int main()
chaiscript::ChaiScript chai(modulepaths,usepaths); chaiscript::ChaiScript chai(modulepaths,usepaths);
std::vector<boost::shared_ptr<boost::thread> > threads; boost::thread_group threads;
// Ensure at least two, but say only 7 on an 8 core processor // Ensure at least two, but say only 7 on an 8 core processor
int num_threads = std::max<unsigned int>(boost::thread::hardware_concurrency() - 1, 2u); int num_threads = std::max<unsigned int>(boost::thread::hardware_concurrency() - 1, 2u);
for (int i = 0; i < num_threads; ++i) for (int i = 0; i < num_threads; ++i)
{ {
threads.push_back(boost::shared_ptr<boost::thread>(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.join_all();
{
threads[i]->join();
}
for (int i = 0; i < num_threads; ++i) for (int i = 0; i < num_threads; ++i)