Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:37:22

0001 
0002 //          Copyright Oliver Kowalke 2017.
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //    (See accompanying file LICENSE_1_0.txt or copy at
0005 //          http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_FIBERS_NUMA_ALGO_WORK_STEALING_H
0009 #define BOOST_FIBERS_NUMA_ALGO_WORK_STEALING_H
0010 
0011 #include <condition_variable>
0012 #include <chrono>
0013 #include <cstddef>
0014 #include <cstdint>
0015 #include <mutex>
0016 #include <vector>
0017 
0018 #include <boost/config.hpp>
0019 #include <boost/intrusive_ptr.hpp>
0020 
0021 #include <boost/fiber/algo/algorithm.hpp>
0022 #include <boost/fiber/context.hpp>
0023 #include <boost/fiber/detail/config.hpp>
0024 #include <boost/fiber/detail/context_spinlock_queue.hpp>
0025 #include <boost/fiber/detail/context_spmc_queue.hpp>
0026 #include <boost/fiber/numa/pin_thread.hpp>
0027 #include <boost/fiber/numa/topology.hpp>
0028 #include <boost/fiber/scheduler.hpp>
0029 
0030 #ifdef BOOST_HAS_ABI_HEADERS
0031 #  include BOOST_ABI_PREFIX
0032 #endif
0033 
0034 namespace boost {
0035 namespace fibers {
0036 namespace numa {
0037 namespace algo {
0038 
0039 class BOOST_FIBERS_DECL work_stealing : public boost::fibers::algo::algorithm {
0040 private:
0041     static std::vector< intrusive_ptr< work_stealing > >    schedulers_;
0042 
0043     std::uint32_t                                           cpu_id_;
0044     std::vector< std::uint32_t >                            local_cpus_;
0045     std::vector< std::uint32_t >                            remote_cpus_;
0046 #ifdef BOOST_FIBERS_USE_SPMC_QUEUE
0047     detail::context_spmc_queue                              rqueue_{};
0048 #else
0049     detail::context_spinlock_queue                          rqueue_{};
0050 #endif
0051     std::mutex                                              mtx_{};
0052     std::condition_variable                                 cnd_{};
0053     bool                                                    flag_{ false };
0054     bool                                                    suspend_;
0055 
0056     static void init_( std::vector< boost::fibers::numa::node > const&,
0057                        std::vector< intrusive_ptr< work_stealing > > &);
0058 
0059 public:
0060     work_stealing( std::uint32_t, std::uint32_t,
0061                    std::vector< boost::fibers::numa::node > const&,
0062                    bool = false);
0063 
0064     work_stealing( work_stealing const&) = delete;
0065     work_stealing( work_stealing &&) = delete;
0066 
0067     work_stealing & operator=( work_stealing const&) = delete;
0068     work_stealing & operator=( work_stealing &&) = delete;
0069 
0070     virtual void awakened( context *) noexcept;
0071 
0072     virtual context * pick_next() noexcept;
0073 
0074     virtual context * steal() noexcept {
0075         return rqueue_.steal();
0076     }
0077 
0078     virtual bool has_ready_fibers() const noexcept {
0079         return ! rqueue_.empty();
0080     }
0081 
0082     virtual void suspend_until( std::chrono::steady_clock::time_point const&) noexcept;
0083 
0084     virtual void notify() noexcept;
0085 };
0086 
0087 }}}}
0088 
0089 #ifdef BOOST_HAS_ABI_HEADERS
0090 #  include BOOST_ABI_SUFFIX
0091 #endif
0092 
0093 #endif // BOOST_FIBERS_NUMA_ALGO_WORK_STEALING_H