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_HPP
0010 #define BOOST_THREAD_EXECUTORS_EXECUTOR_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/detail/delete.hpp>
0016 #include <boost/thread/detail/move.hpp>
0017 #include <boost/thread/executors/work.hpp>
0018 
0019 #include <boost/config/abi_prefix.hpp>
0020 
0021 namespace boost
0022 {
0023   namespace executors
0024   {
0025   class executor
0026   {
0027   public:
0028     /// type-erasure to store the works to do
0029     typedef  executors::work work;
0030 
0031     /// executor is not copyable.
0032     BOOST_THREAD_NO_COPYABLE(executor)
0033     executor() {}
0034 
0035     /**
0036      * \par Effects
0037      * Destroys the executor.
0038      *
0039      * \par Synchronization
0040      * The completion of all the closures happen before the completion of the executor destructor.
0041      */
0042     virtual ~executor() {}
0043 
0044     /**
0045      * \par Effects
0046      * Close the \c executor for submissions.
0047      * The worker threads will work until there is no more closures to run.
0048      */
0049     virtual void close() = 0;
0050 
0051     /**
0052      * \par Returns
0053      * Whether the pool is closed for submissions.
0054      */
0055     virtual bool closed() = 0;
0056 
0057     /**
0058      * \par Effects
0059      * The specified closure will be scheduled for execution at some point in the future.
0060      * If invoked closure throws an exception the executor will call std::terminate, as is the case with threads.
0061      *
0062      * \par Synchronization
0063      * Ccompletion of closure on a particular thread happens before destruction of thread's thread local variables.
0064      *
0065      * \par Throws
0066      * \c sync_queue_is_closed if the thread pool is closed.
0067      * Whatever exception that can be throw while storing the closure.
0068      */
0069     virtual void submit(BOOST_THREAD_RV_REF(work) closure) = 0;
0070 //    virtual void submit(work& closure) = 0;
0071 
0072     /**
0073      * \par Requires
0074      * \c Closure is a model of Callable(void()) and a model of CopyConstructible/MoveConstructible.
0075      *
0076      * \par Effects
0077      * The specified closure will be scheduled for execution at some point in the future.
0078      * If invoked closure throws an exception the thread pool will call std::terminate, as is the case with threads.
0079      *
0080      * \par Synchronization
0081      * Completion of closure on a particular thread happens before destruction of thread's thread local variables.
0082      *
0083      * \par Throws
0084      * \c sync_queue_is_closed if the thread pool is closed.
0085      * Whatever exception that can be throw while storing the closure.
0086      */
0087 
0088 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0089     template <typename Closure>
0090     void submit(Closure & closure)
0091     {
0092       work w ((closure));
0093       submit(boost::move(w));
0094     }
0095 #endif
0096     void submit(void (*closure)())
0097     {
0098       work w ((closure));
0099       submit(boost::move(w));
0100     }
0101 
0102     template <typename Closure>
0103     void submit(BOOST_THREAD_FWD_REF(Closure) closure)
0104     {
0105       //submit(work(boost::forward<Closure>(closure)));
0106       work w((boost::forward<Closure>(closure)));
0107       submit(boost::move(w));
0108     }
0109 
0110     /**
0111      * \par Effects
0112      * Try to execute one task.
0113      *
0114      * \par Returns
0115      * Whether a task has been executed.
0116      *
0117      * \par Throws
0118      * Whatever the current task constructor throws or the task() throws.
0119      */
0120     virtual bool try_executing_one() = 0;
0121 
0122     /**
0123      * \par Requires
0124      * This must be called from an scheduled task.
0125      *
0126      * \par Effects
0127      * Reschedule functions until pred()
0128      */
0129     template <typename Pred>
0130     bool reschedule_until(Pred const& pred)
0131     {
0132       do {
0133         //schedule_one_or_yield();
0134         if ( ! try_executing_one())
0135         {
0136           return false;
0137         }
0138       } while (! pred());
0139       return true;
0140     }
0141   };
0142 
0143   }
0144   using executors::executor;
0145 }
0146 
0147 #include <boost/config/abi_suffix.hpp>
0148 
0149 #endif
0150 #endif