From 64c372d059f0ed300ab657fa2451954ba176cf4a Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sat, 2 Nov 2013 16:56:24 +0100 Subject: [PATCH] add thread_affinity() to fiber's public interface --- doc/fiber.qbk | 24 +++++++++++++++++++++++- include/boost/fiber/fiber.hpp | 4 ++++ src/fiber.cpp | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/fiber.qbk b/doc/fiber.qbk index 5828c6e1..cb2df755 100644 --- a/doc/fiber.qbk +++ b/doc/fiber.qbk @@ -259,9 +259,11 @@ operators on __fiber_id__ yield a total order for every non-equal __fiber_id__. id get_id() const noexcept; int priority() const noexcept; - void priority( int) noexcept; + bool thread_affinity() const noexcept; + void thread_affinity( bool) noexcept; + void detach() noexcept; void join(); @@ -434,6 +436,26 @@ interruption enabled.]] [[Throws:] [Nothing]] ] +[heading Member function `thread_affinity( bool)`] + + void thread_affinity( bool) noexcept; + +[variablelist +[[Effects:] [If `*this` refers to a fiber of execution, set its thread affinity.]] +[[Throws:] [Nothing]] +[[Note:] [A value of `false` prevents migrating the fiber to another scheduler +running in a different thread.]] +] + +[heading Member function `thread_affinity()`] + + bool thread_affinity() const noexcept; + +[variablelist +[[Effects:] [If `*this` refers to a fiber of execution, return its thread affinity.]] +[[Throws:] [Nothing]] +] + [heading Member function `operator safe_bool()`] operator safe_bool() const noexcept; diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 295763b7..485ef85a 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -361,6 +361,10 @@ public: void priority( int) BOOST_NOEXCEPT; + bool thread_affinity() const BOOST_NOEXCEPT; + + void thread_affinity( bool) BOOST_NOEXCEPT; + void detach() BOOST_NOEXCEPT; void join(); diff --git a/src/fiber.cpp b/src/fiber.cpp index 407a1b18..977899e6 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -42,6 +42,22 @@ fiber::priority( int prio) BOOST_NOEXCEPT detail::scheduler::instance()->priority( impl_, prio); } +bool +fiber::thread_affinity() const BOOST_NOEXCEPT +{ + BOOST_ASSERT( impl_); + + return impl_->thread_affinity(); +} + +void +fiber::thread_affinity( bool req) BOOST_NOEXCEPT +{ + BOOST_ASSERT( impl_); + + impl_->thread_affinity( req); +} + void fiber::join() {