Merge branch 'master' into ChaiScript_5_0_CPP_11

Conflicts:
	include/chaiscript/chaiscript_threading.hpp
	include/chaiscript/dispatchkit/boxed_value.hpp
	include/chaiscript/dispatchkit/proxy_functions_detail.hpp
	samples/example.cpp
	src/test_module.cpp
	unittests/multithreaded_test.cpp
This commit is contained in:
Jason Turner
2013-05-27 08:48:59 -06:00
7 changed files with 58 additions and 13 deletions

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

@@ -483,14 +483,15 @@ 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

View File

@@ -44,6 +44,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());
@@ -98,6 +104,11 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
return m; return m;
} }
#ifdef __llvm__
#pragma clang diagnostic pop
#endif
#ifdef CHAISCRIPT_MSVC #ifdef CHAISCRIPT_MSVC
#pragma warning(pop) #pragma warning(pop)

View File

@@ -11,11 +11,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 CHAISCRIPT_MSVC #ifdef CHAISCRIPT_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 CHAISCRIPT_MSVC #ifdef CHAISCRIPT_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif

View File

@@ -24,6 +24,7 @@ int expected_value(int num_iters)
void do_work(chaiscript::ChaiScript &c, int id) void do_work(chaiscript::ChaiScript &c, int id)
{ {
try{
std::stringstream ss; std::stringstream ss;
ss << "MyVar" << rand(); ss << "MyVar" << rand();
c.add(chaiscript::var(5), ss.str()); c.add(chaiscript::var(5), ss.str());
@@ -31,6 +32,9 @@ void do_work(chaiscript::ChaiScript &c, int id)
ss << id; ss << id;
c.use("multithreaded_work.inc"); c.use("multithreaded_work.inc");
c("do_chai_work(4000, " + ss.str() + ");"); c("do_chai_work(4000, " + ss.str() + ");");
} catch (const std::exception &e) {
std::cout << "exception: " << e.what() << " thread: " << id;
}
} }
int main() int main()
@@ -80,6 +84,7 @@ int main()
} }
for (int i = 0; i < num_threads; ++i) for (int i = 0; i < num_threads; ++i)
{ {
std::stringstream ss; std::stringstream ss;