1 // Copyright (C) 2013,2014 Vicente J. Botet Escriba
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // 2013/09 Vicente J. Botet Escriba
7 // Adapt to boost from CCIA C++11 implementation
9 #ifndef BOOST_THREAD_EXECUTORS_EXECUTOR_HPP
10 #define BOOST_THREAD_EXECUTORS_EXECUTOR_HPP
12 #include <boost/thread/detail/config.hpp>
14 #include <boost/thread/detail/delete.hpp>
15 #include <boost/thread/detail/move.hpp>
16 #include <boost/thread/executors/work.hpp>
18 #include <boost/config/abi_prefix.hpp>
27 /// type-erasure to store the works to do
28 typedef executors::work work;
30 /// executor is not copyable.
31 BOOST_THREAD_NO_COPYABLE(executor)
36 * Destroys the executor.
38 * \par Synchronization
39 * The completion of all the closures happen before the completion of the executor destructor.
41 virtual ~executor() {}
45 * Close the \c executor for submissions.
46 * The worker threads will work until there is no more closures to run.
48 virtual void close() = 0;
52 * Whether the pool is closed for submissions.
54 virtual bool closed() = 0;
58 * The specified closure will be scheduled for execution at some point in the future.
59 * If invoked closure throws an exception the executor will call std::terminate, as is the case with threads.
61 * \par Synchronization
62 * Ccompletion of closure on a particular thread happens before destruction of thread's thread local variables.
65 * \c sync_queue_is_closed if the thread pool is closed.
66 * Whatever exception that can be throw while storing the closure.
68 virtual void submit(BOOST_THREAD_RV_REF(work) closure) = 0;
69 // virtual void submit(work& closure) = 0;
73 * \c Closure is a model of Callable(void()) and a model of CopyConstructible/MoveConstructible.
76 * The specified closure will be scheduled for execution at some point in the future.
77 * If invoked closure throws an exception the thread pool will call std::terminate, as is the case with threads.
79 * \par Synchronization
80 * Completion of closure on a particular thread happens before destruction of thread's thread local variables.
83 * \c sync_queue_is_closed if the thread pool is closed.
84 * Whatever exception that can be throw while storing the closure.
87 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
88 template <typename Closure>
89 void submit(Closure & closure)
92 submit(boost::move(w));
95 void submit(void (*closure)())
98 submit(boost::move(w));
101 template <typename Closure>
102 void submit(BOOST_THREAD_FWD_REF(Closure) closure)
104 //submit(work(boost::forward<Closure>(closure)));
105 work w((boost::forward<Closure>(closure)));
106 submit(boost::move(w));
111 * Try to execute one task.
114 * Whether a task has been executed.
117 * Whatever the current task constructor throws or the task() throws.
119 virtual bool try_executing_one() = 0;
123 * This must be called from an scheduled task.
126 * Reschedule functions until pred()
128 template <typename Pred>
129 bool reschedule_until(Pred const& pred)
132 //schedule_one_or_yield();
133 if ( ! try_executing_one())
143 using executors::executor;
146 #include <boost/config/abi_suffix.hpp>