mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-12 12:02:54 +00:00
- Change some doc references from 'algorithm' to 'sched_algorithm'. - Initial cut at supporting arbitrary user-coded scheduler properties. - Set fiber_properties::sched_algo_ every time through awakened(). - Define sched_algorithm methods on fiber_base*, not worker_fiber*. - Simplify detail::fifo by making tail_ point to last link pointer. - Reimplement waiting_queue::push() using pointer-to-pointer trick. - Reimplement waiting_queue::move_to() using fiber_base** scan. - Make bounded_queue::tail_ a ptr* to simplify appending new nodes. - Make unbounded_queue::tail_ a ptr* to simplify linking new nodes. - Remove thread_affinity flag and access methods. - Re-add thread_affinity specific to workstealing_round_robin. - Remove 'priority' for every fiber, and its support methods.
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
// Copyright Oliver Kowalke 2013.
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
#ifndef WORKSTEALING_ROUND_ROBIN_H
|
|
#define WORKSTEALING_ROUND_ROBIN_H
|
|
|
|
#include <deque>
|
|
|
|
#include <boost/config.hpp>
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <boost/fiber/fiber.hpp>
|
|
#include <boost/fiber/properties.hpp>
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_PREFIX
|
|
#endif
|
|
|
|
# if defined(BOOST_MSVC)
|
|
# pragma warning(push)
|
|
# pragma warning(disable:4251 4275)
|
|
# endif
|
|
|
|
struct affinity: public boost::fibers::fiber_properties
|
|
{
|
|
affinity(boost::fibers::fiber_properties::back_ptr p):
|
|
fiber_properties(p),
|
|
// By default, assume a given fiber CAN migrate to another thread.
|
|
thread_affinity(false)
|
|
{}
|
|
|
|
bool thread_affinity;
|
|
};
|
|
|
|
class workstealing_round_robin :
|
|
public boost::fibers::sched_algorithm_with_properties<affinity>
|
|
{
|
|
private:
|
|
boost::mutex mtx_;
|
|
|
|
// We should package these as a queue class. Better yet, we should
|
|
// refactor one of our existing (intrusive) queue classes to support the
|
|
// required operations generically. But for now...
|
|
boost::fibers::fiber_base *rhead_, **rtail_;
|
|
|
|
public:
|
|
workstealing_round_robin();
|
|
|
|
virtual void awakened( boost::fibers::fiber_base *);
|
|
|
|
virtual boost::fibers::fiber_base * pick_next();
|
|
|
|
boost::fibers::fiber steal();
|
|
};
|
|
|
|
# if defined(BOOST_MSVC)
|
|
# pragma warning(pop)
|
|
# endif
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_SUFFIX
|
|
#endif
|
|
|
|
#endif // WORKSTEALING_ROUND_ROBIN_H
|