Skip to content
This repository
Browse code

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

 - Fix all warnings that I can / ignore those caused by boost
  • Loading branch information...
commit 101225aa685c4eae61e0a98b4f810466a0bc2daa 1 parent feb344e
Jason Turner lefticus authored
9 include/chaiscript/chaiscript_threading.hpp
@@ -8,7 +8,16 @@
8 8 #define CHAISCRIPT_THREADING_HPP_
9 9
10 10 #ifndef CHAISCRIPT_NO_THREADS
  11 +
  12 +#ifdef __llvm__
  13 +#pragma clang diagnostic push
  14 +#pragma clang diagnostic ignored "-Wc++11-long-long"
  15 +#pragma clang diagnostic ignored "-Wshadow"
  16 +#endif
11 17 #include <boost/thread.hpp>
  18 +#ifdef __llvm__
  19 +#pragma clang diagnostic pop
  20 +#endif
12 21 #else
13 22 #pragma message ("ChaiScript is compiling without thread safety.")
14 23 #endif
12 include/chaiscript/dispatchkit/boxed_value.hpp
@@ -13,7 +13,19 @@
13 13
14 14 #include <map>
15 15 #include <boost/shared_ptr.hpp>
  16 +
  17 +#ifdef __llvm__
  18 +#pragma clang diagnostic push
  19 +#pragma clang diagnostic ignored "-Wshadow"
  20 +#pragma clang diagnostic ignored "-Wunused-parameter"
  21 +#endif
  22 +
16 23 #include <boost/make_shared.hpp>
  24 +
  25 +#ifdef __llvm__
  26 +#pragma clang diagnostic pop
  27 +#endif
  28 +
17 29 #include <boost/any.hpp>
18 30 #include <boost/function.hpp>
19 31 #include <boost/ref.hpp>
12 include/chaiscript/dispatchkit/exception_specification.hpp
@@ -17,6 +17,8 @@ namespace chaiscript
17 17 {
18 18 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0;
19 19
  20 + virtual ~Exception_Handler_Base() {}
  21 +
20 22 protected:
21 23 template<typename T>
22 24 void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
@@ -28,6 +30,8 @@ namespace chaiscript
28 30 template<typename T1>
29 31 struct Exception_Handler_Impl1 : Exception_Handler_Base
30 32 {
  33 + virtual ~Exception_Handler_Impl1() {}
  34 +
31 35 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
32 36 {
33 37 throw_type<T1>(bv, t_engine);
@@ -36,6 +40,8 @@ namespace chaiscript
36 40 template<typename T1, typename T2>
37 41 struct Exception_Handler_Impl2 : Exception_Handler_Base
38 42 {
  43 + virtual ~Exception_Handler_Impl2() {}
  44 +
39 45 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
40 46 {
41 47 throw_type<T1>(bv, t_engine);
@@ -46,6 +52,8 @@ namespace chaiscript
46 52 template<typename T1, typename T2, typename T3>
47 53 struct Exception_Handler_Impl3 : Exception_Handler_Base
48 54 {
  55 + virtual ~Exception_Handler_Impl3() {}
  56 +
49 57 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
50 58 {
51 59 throw_type<T1>(bv, t_engine);
@@ -56,6 +64,8 @@ namespace chaiscript
56 64 template<typename T1, typename T2, typename T3, typename T4>
57 65 struct Exception_Handler_Impl4 : Exception_Handler_Base
58 66 {
  67 + virtual ~Exception_Handler_Impl4() {}
  68 +
59 69 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
60 70 {
61 71 throw_type<T1>(bv, t_engine);
@@ -67,6 +77,8 @@ namespace chaiscript
67 77 template<typename T1, typename T2, typename T3, typename T4, typename T5>
68 78 struct Exception_Handler_Impl5 : Exception_Handler_Base
69 79 {
  80 + virtual ~Exception_Handler_Impl5() {}
  81 +
70 82 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
71 83 {
72 84 throw_type<T1>(bv, t_engine);
21 include/chaiscript/dispatchkit/proxy_functions_detail.hpp
@@ -86,9 +86,16 @@ namespace chaiscript
86 86 * if any unboxing fails the execution of the function fails and
87 87 * the bad_boxed_cast is passed up to the caller.
88 88 */
  89 +#ifdef __llvm__
  90 +#pragma clang diagnostic push
  91 +#pragma clang diagnostic ignored "-Wunused-parameter"
  92 +#endif
89 93 template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
90 94 Ret call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f,
91   - const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, ))
  95 + const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions & BOOST_PP_IF(n, t_conversions, BOOST_PP_EMPTY))
  96 +#ifdef __llvm__
  97 +#pragma clang diagnostic pop
  98 +#endif
92 99 {
93 100 if (params.size() != n)
94 101 {
@@ -103,9 +110,17 @@ namespace chaiscript
103 110 * Proxy_Function_Impl object. This function is primarly used to prevent
104 111 * registration of two functions with the exact same signatures
105 112 */
106   - template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
  113 +
  114 +#ifdef __llvm__
  115 +#pragma clang diagnostic push
  116 +#pragma clang diagnostic ignored "-Wunused-parameter"
  117 +#endif
  118 + template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
107 119 bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)),
108   - const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, ), const Dynamic_Cast_Conversions &t_conversions)
  120 + const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, BOOST_PP_EMPTY), const Dynamic_Cast_Conversions &t_conversions)
  121 +#ifdef __llvm__
  122 +#pragma clang diagnostic pop
  123 +#endif
109 124 {
110 125 try {
111 126 (void)t_conversions;
11 include/chaiscript/language/chaiscript_engine.hpp
@@ -420,19 +420,20 @@ namespace chaiscript
420 420 try {
421 421 const std::string appendedpath = m_usepaths[i] + t_filename;
422 422
423   - chaiscript::detail::threading::lock_guard<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
424   - chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
  423 + chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
  424 + chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
425 425
426 426 if (m_used_files.count(appendedpath) == 0)
427 427 {
428   - m_used_files.insert(appendedpath);
429 428 l2.unlock();
430 429 eval_file(appendedpath);
431   - }
  430 + l2.lock();
  431 + m_used_files.insert(appendedpath);
  432 + }
432 433
433 434 return; // return, we loaded it, or it was already loaded
434 435 } catch (const exception::file_not_found_error &) {
435   - if (i == m_usepaths.size() - 1)
  436 + if (i == m_usepaths.size() - 1)
436 437 {
437 438 throw exception::file_not_found_error(t_filename);
438 439 }
11 samples/example.cpp
@@ -9,7 +9,18 @@
9 9 #include <chaiscript/chaiscript.hpp>
10 10 #include <chaiscript/dispatchkit/function_call.hpp>
11 11 #include <boost/function.hpp>
  12 +
  13 +#ifdef __llvm__
  14 +#pragma clang diagnostic push
  15 +#pragma clang diagnostic ignored "-Wunused-parameter"
  16 +#endif
  17 +
12 18 #include <boost/date_time/posix_time/posix_time.hpp>
  19 +
  20 +#ifdef __llvm__
  21 +#pragma clang diagnostic pop
  22 +#endif
  23 +
13 24 #include <boost/regex.hpp>
14 25
15 26 void log(const std::string &msg)
11 src/reflection.cpp
@@ -42,6 +42,12 @@ chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t
42 42 }
43 43
44 44
  45 +#ifdef __llvm__
  46 +#pragma clang diagnostic push
  47 +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
  48 +#endif
  49 +
  50 +
45 51 CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection()
46 52 {
47 53 chaiscript::ModulePtr m(new chaiscript::Module());
@@ -90,6 +96,11 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
90 96 return m;
91 97 }
92 98
  99 +#ifdef __llvm__
  100 +#pragma clang diagnostic pop
  101 +#endif
  102 +
  103 +
93 104
94 105 #ifdef BOOST_MSVC
95 106 #pragma warning(pop)
8 src/stl_extra.cpp
@@ -10,11 +10,19 @@
10 10 #pragma warning(disable : 4190)
11 11 #endif
12 12
  13 +#ifdef __llvm__
  14 +#pragma clang diagnostic push
  15 +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
  16 +#endif
  17 +
13 18 CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extra()
14 19 {
15 20 return chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List");
16 21 }
17 22
  23 +#ifdef __llvm__
  24 +#pragma clang diagnostic pop
  25 +#endif
18 26
19 27 #ifdef BOOST_MSVC
20 28 #pragma warning(pop)
8 src/test_module.cpp
@@ -49,6 +49,10 @@ int *get_new_int()
49 49 #pragma warning(disable : 4190)
50 50 #endif
51 51
  52 +#ifdef __llvm__
  53 +#pragma clang diagnostic push
  54 +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
  55 +#endif
52 56
53 57 CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_module()
54 58 {
@@ -86,6 +90,10 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
86 90 }
87 91
88 92
  93 +#ifdef __llvm__
  94 +#pragma clang diagnostic pop
  95 +#endif
  96 +
89 97 #ifdef BOOST_MSVC
90 98 #pragma warning(pop)
91 99 #endif
27 unittests/multithreaded_test.cpp
@@ -25,13 +25,17 @@ int expected_value(int num_iters)
25 25
26 26 void do_work(chaiscript::ChaiScript &c, int id)
27 27 {
28   - std::stringstream ss;
29   - ss << "MyVar" << rand();
30   - c.add(chaiscript::var(5), ss.str());
31   - ss.str("");
32   - ss << id;
33   - c.use("multithreaded_work.inc");
34   - c("do_chai_work(4000, " + ss.str() + ");");
  28 + try{
  29 + std::stringstream ss;
  30 + ss << "MyVar" << rand();
  31 + c.add(chaiscript::var(5), ss.str());
  32 + ss.str("");
  33 + ss << id;
  34 + c.use("multithreaded_work.inc");
  35 + c("do_chai_work(4000, " + ss.str() + ");");
  36 + } catch (const std::exception &e) {
  37 + std::cout << "exception: " << e.what() << " thread: " << id;
  38 + }
35 39 }
36 40
37 41 int main()
@@ -65,20 +69,17 @@ int main()
65 69
66 70 chaiscript::ChaiScript chai(modulepaths,usepaths);
67 71
68   - std::vector<boost::shared_ptr<boost::thread> > threads;
  72 + boost::thread_group threads;
69 73
70 74 // Ensure at least two, but say only 7 on an 8 core processor
71 75 int num_threads = std::max<unsigned int>(boost::thread::hardware_concurrency() - 1, 2u);
72 76
73 77 for (int i = 0; i < num_threads; ++i)
74 78 {
75   - threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(do_work, boost::ref(chai), i))));
  79 + threads.create_thread(boost::bind(&do_work, boost::ref(chai), i));
76 80 }
77 81
78   - for (int i = 0; i < num_threads; ++i)
79   - {
80   - threads[i]->join();
81   - }
  82 + threads.join_all();
82 83
83 84
84 85 for (int i = 0; i < num_threads; ++i)

0 comments on commit 101225a

Please sign in to comment.
Something went wrong with that request. Please try again.