Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:03:03

0001 // Copyright (C) 2014 Ian Forbed
0002 // Copyright (C) 2014 Vicente J. Botet Escriba
0003 //
0004 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_THREAD_EXECUTORS_DETAIL_PRIORITY_EXECUTOR_BASE_HPP
0009 #define BOOST_THREAD_EXECUTORS_DETAIL_PRIORITY_EXECUTOR_BASE_HPP
0010 
0011 #include <boost/atomic.hpp>
0012 #include <boost/function.hpp>
0013 #include <boost/thread/thread.hpp>
0014 #include <boost/thread/concurrent_queues/sync_timed_queue.hpp>
0015 #include <boost/thread/executors/work.hpp>
0016 
0017 namespace boost
0018 {
0019 namespace executors
0020 {
0021 namespace detail
0022 {
0023   template <class Queue>
0024   class priority_executor_base
0025   {
0026   public:
0027     //typedef boost::function<void()> work;
0028     typedef executors::work_pq work;
0029   protected:
0030     typedef Queue queue_type;
0031     queue_type _workq;
0032 
0033     priority_executor_base() {}
0034   public:
0035 
0036     ~priority_executor_base()
0037     {
0038       if(!closed())
0039       {
0040         this->close();
0041       }
0042     }
0043 
0044     void close()
0045     {
0046       _workq.close();
0047     }
0048 
0049     bool closed()
0050     {
0051       return _workq.closed();
0052     }
0053 
0054     void loop()
0055     {
0056       try
0057       {
0058         for(;;)
0059         {
0060           try {
0061             work task;
0062             queue_op_status st = _workq.wait_pull(task);
0063             if (st == queue_op_status::closed) return;
0064             task();
0065           }
0066           catch (boost::thread_interrupted&)
0067           {
0068             return;
0069           }
0070         }
0071       }
0072       catch (...)
0073       {
0074         std::terminate();
0075         return;
0076       }
0077     }
0078   }; //end class
0079 
0080 } //end detail namespace
0081 } //end executors namespace
0082 } //end boost namespace
0083 #endif