diff options
Diffstat (limited to 'boost/thread/executors/serial_executor.hpp')
-rw-r--r-- | boost/thread/executors/serial_executor.hpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/boost/thread/executors/serial_executor.hpp b/boost/thread/executors/serial_executor.hpp index dae1014b47..6f4266668f 100644 --- a/boost/thread/executors/serial_executor.hpp +++ b/boost/thread/executors/serial_executor.hpp @@ -12,7 +12,7 @@ #include <boost/thread/detail/config.hpp> #include <boost/thread/detail/delete.hpp> #include <boost/thread/detail/move.hpp> -#include <boost/thread/sync_queue.hpp> +#include <boost/thread/concurrent_queues/sync_queue.hpp> #include <boost/thread/executors/work.hpp> #include <boost/thread/executors/generic_executor_ref.hpp> #include <boost/thread/future.hpp> @@ -33,7 +33,7 @@ namespace executors typedef scoped_thread<> thread_t; /// the thread safe work queue - sync_queue<work > work_queue; + concurrent::sync_queue<work > work_queue; generic_executor_ref ex; thread_t thr; @@ -43,8 +43,13 @@ namespace executors try_executing_one_task(work& task, boost::promise<void> &p) : task(task), p(p) {} void operator()() { - task(); // if task() throws promise is not set but as the the program terminates and should terminate there is no need to use try-catch here. - p.set_value(); + try { + task(); + p.set_value(); + } catch (...) + { + p.set_exception(current_exception()); + } } }; public: @@ -52,7 +57,7 @@ namespace executors * \par Returns * The underlying executor wrapped on a generic executor reference. */ - generic_executor_ref underlying_executor() BOOST_NOEXCEPT { return ex; } + generic_executor_ref& underlying_executor() BOOST_NOEXCEPT { return ex; } /** * Effects: try to execute one task. @@ -64,27 +69,19 @@ namespace executors work task; try { - if (work_queue.try_pull_front(task) == queue_op_status::success) + if (work_queue.try_pull(task) == queue_op_status::success) { boost::promise<void> p; try_executing_one_task tmp(task,p); ex.submit(tmp); -// ex.submit([&task, &p]() -// { -// task(); // if task() throws promise is not set but as the the program terminates and should terminate there is no need to use try-catch here. -// p.set_value(); -// }); p.get_future().wait(); return true; } return false; } - catch (std::exception& ) - { - return false; - } catch (...) { + std::terminate(); return false; } } @@ -136,7 +133,7 @@ namespace executors */ ~serial_executor() { - // signal to all the worker thread that there will be no more submissions. + // signal to the worker thread that there will be no more submissions. close(); } @@ -173,18 +170,18 @@ namespace executors template <typename Closure> void submit(Closure & closure) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } #endif void submit(void (*closure)()) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } template <typename Closure> void submit(BOOST_THREAD_RV_REF(Closure) closure) { - work_queue.push_back(work(boost::forward<Closure>(closure))); + work_queue.push(work(boost::forward<Closure>(closure))); } /** |