Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:01:11

0001 // Copyright (C) 2013,2014 Vicente J. Botet Escriba
0002 //
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 // 2013/09 Vicente J. Botet Escriba
0007 //    Adapt to boost from CCIA C++11 implementation
0008 
0009 #ifndef BOOST_THREAD_EXECUTORS_EXECUTOR_ADAPTOR_HPP
0010 #define BOOST_THREAD_EXECUTORS_EXECUTOR_ADAPTOR_HPP
0011 
0012 #include <boost/thread/detail/config.hpp>
0013 #if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION && defined BOOST_THREAD_PROVIDES_EXECUTORS && defined BOOST_THREAD_USES_MOVE
0014 
0015 #include <boost/thread/executors/executor.hpp>
0016 
0017 #include <boost/config/abi_prefix.hpp>
0018 
0019 namespace boost
0020 {
0021 namespace executors
0022 {
0023   /**
0024    * Polymorphic adaptor of a model of Executor to an executor.
0025    */
0026   template <typename Executor>
0027   class executor_adaptor : public executor
0028   {
0029     Executor ex;
0030   public:
0031     /// type-erasure to store the works to do
0032     typedef  executor::work work;
0033 
0034     /// executor is not copyable.
0035     BOOST_THREAD_NO_COPYABLE(executor_adaptor)
0036 
0037     /**
0038      * executor_adaptor constructor
0039      */
0040 #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0041     template <typename ...Args>
0042     executor_adaptor(BOOST_THREAD_RV_REF(Args) ... args) : ex(boost::forward<Args>(args)...) {}
0043 #else
0044     /**
0045      * executor_adaptor constructor
0046      */
0047     executor_adaptor() : ex() {}
0048 
0049     template <typename A1>
0050     executor_adaptor(
0051         BOOST_THREAD_FWD_REF(A1) a1
0052         ) :
0053       ex(
0054           boost::forward<A1>(a1)
0055           ) {}
0056     template <typename A1, typename A2>
0057     executor_adaptor(
0058         BOOST_THREAD_FWD_REF(A1) a1,
0059         BOOST_THREAD_FWD_REF(A2) a2
0060         ) :
0061       ex(
0062           boost::forward<A1>(a1),
0063           boost::forward<A2>(a2)
0064           ) {}
0065     template <typename A1, typename A2, typename A3>
0066     executor_adaptor(
0067         BOOST_THREAD_FWD_REF(A1) a1,
0068         BOOST_THREAD_FWD_REF(A2) a2,
0069         BOOST_THREAD_FWD_REF(A3) a3
0070         ) :
0071       ex(
0072           boost::forward<A1>(a1),
0073           boost::forward<A2>(a2),
0074           boost::forward<A3>(a3)
0075           ) {}
0076 #endif
0077     Executor& underlying_executor() { return ex; }
0078 
0079     /**
0080      * \b Effects: close the \c executor for submissions.
0081      * The worker threads will work until there is no more closures to run.
0082      */
0083     void close() { ex.close(); }
0084 
0085     /**
0086      * \b Returns: whether the pool is closed for submissions.
0087      */
0088     bool closed() { return ex.closed(); }
0089 
0090     /**
0091      * \b Effects: The specified closure will be scheduled for execution at some point in the future.
0092      * If invoked closure throws an exception the executor will call std::terminate, as is the case with threads.
0093      *
0094      * \b Synchronization: completion of closure on a particular thread happens before destruction of thread's thread local variables.
0095      *
0096      * \b Throws: \c sync_queue_is_closed if the thread pool is closed.
0097      * Whatever exception that can be throw while storing the closure.
0098      */
0099     void submit(BOOST_THREAD_RV_REF(work) closure)  {
0100       return ex.submit(boost::move(closure));
0101     }
0102 
0103 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0104     template <typename Closure>
0105     void submit(Closure & closure)
0106     {
0107       submit(work(closure));
0108     }
0109 #endif
0110     void submit(void (*closure)())
0111     {
0112       submit(work(closure));
0113     }
0114 
0115     template <typename Closure>
0116     void submit(BOOST_THREAD_FWD_REF(Closure) closure)
0117     {
0118       //submit(work(boost::forward<Closure>(closure)));
0119       work w((boost::forward<Closure>(closure)));
0120       submit(boost::move(w));
0121     }
0122 
0123     /**
0124      * Effects: try to execute one task.
0125      * Returns: whether a task has been executed.
0126      * Throws: whatever the current task constructor throws or the task() throws.
0127      */
0128     bool try_executing_one() { return ex.try_executing_one(); }
0129 
0130   };
0131 }
0132 using executors::executor_adaptor;
0133 }
0134 
0135 #include <boost/config/abi_suffix.hpp>
0136 
0137 #endif
0138 #endif