2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-18 01:52:24 +00:00
Commit Graph

274 Commits

Author SHA1 Message Date
Nat Goodspeed
20a2f59913 Reimplement waiting_queue::move_to() using fiber_base** scan.
This simplifies unlinking from the queue.
2014-11-11 08:38:34 -05:00
Nat Goodspeed
2bffbddeaa Reimplement waiting_queue::push() using pointer-to-pointer trick.
Change waiting_queue::head_ from worker_fiber* to fiber_base* for uniformity
with worker_fiber::nxt_. This lets push() scan from head_ with a fiber_base**,
looking for the right insertion point. Insertion then becomes a couple
unconditional assignments.

Because push() always scans from head_, tail_ was actually never used. Remove
it.
2014-11-11 07:42:56 -05:00
Nat Goodspeed
12fe326c6f Simplify detail::fifo by making tail_ point to last link pointer.
Maintaining a singly-linked list is tricky when you walk it with a node*
pointer. But if you use a node** pointer starting at &head_ and advancing to
point to each &nxt_ pointer, you can coalesce the empty-list case into the
normal case.
2014-11-11 07:26:45 -05:00
Nat Goodspeed
402a4353f7 Define sched_algorithm methods on fiber_base*, not worker_fiber*.
Some reviewers disliked that to build a custom sched_algorithm subclass, you
must necessarily manipulate pointers to classes in the boost::fibers::detail
namespace. Redefine all such methods to use fiber_base* rather than
detail::worker_fiber*.

Hoist fiber_base* into boost::fibers namespace. We considered an opaque
typedef rather than fiber_base*, but in fact a sched_algorithm subclass may
need is_ready().

Moreover, a sched_algorithm subclass may well want to use an intrusive linked
list to queue fibers. Hoist worker_fiber::nxt_ pointer into fiber_base, and
remove worker_fiber::next() and next_reset() methods. This allows recasting
detail::fifo in terms of fiber_base*, therefore round_robin can be stated
almost entirely in terms of fiber_base* rather than worker_fiber*.

Recast fiber constructor taking worker_fiber* to take fiber_base* instead.
This constructor is used solely for fiber migration; with relevant functions
now returning fiber_base*, we think we no longer need fiber(worker_fiber*).
2014-11-10 21:19:28 -05:00
Nat Goodspeed
ed64ee77f8 Set fiber_properties::sched_algo_ every time through awakened().
Instead of setting a fiber_properties subclass's sched_algo_ back pointer once
at construction time, unconditionally set it every time that fiber becomes
READY (and is therefore passed to sched_algorithm::awakened()). This handles
the case in which that fiber migrates to a different thread with a different
sched_algorithm subclass instance.

Break out fiber_properties::notify() implementation to a separate .cpp
implementation file so it can bring in algorithm.hpp. We don't want
properties.hpp to depend on algorithm.hpp.
2014-11-10 19:59:29 -05:00
Nat Goodspeed
3128334364 Initial cut at supporting arbitrary user-coded scheduler properties.
Introduce fiber_properties class from which to derive a specific properties
class for a particular user-coded sched_algorithm subclass.

Add sched_algorithm::property_change(worker_fiber*, fiber_properties*) method
to allow a fiber_properties subclass method to notify the sched_algorithm
subclass of a change in a relevant property. This generalizes the present
priority() method.

Introduce sched_algorithm_with_properties<PROPS> template class from which to
derive a user-coded scheduler that uses fiber_properties subclass PROPS. Give
it ref-returning properties(fiber::id) and properties(worker_fiber*) methods.

Introduce fiber_properties* field in worker_fiber, and initialize it to 0.
Delete it when the worker_fiber is destroyed. Give it pointer-flavored access
methods. Normally this field will remain 0; but the first time the
worker_fiber is passed to a sched_algorithm_with_properties<PROPS> subclass,
its awakened() method will instantiate the relevant PROPS subclass.

Add ref-returning fiber::properties<PROPS>() method. Calling this method
presumes that the current thread's sched_algorithm is derived from
sched_algorithm_with_properties<PROPS>.

Also add this_fiber::properties<PROPS>() with the same restriction.

Add ref-returning fm_properties<PROPS>() functions to implement
fiber::properties<PROPS>() and this_fiber::properties<PROPS>().

Allow sched_algorithm_with_properties to extract the worker_fiber* from a
fiber::id (aka worker_fiber::id) so it can present public-facing
properties(id) method as well as properties(worker_fiber*) method.
(cherry picked from commit 18c7f2c13b9642826b42aa3f6fa0a6642fce9cbc)

Conflicts:
	include/boost/fiber/detail/worker_fiber.hpp
	include/boost/fiber/fiber_manager.hpp
2014-11-08 11:03:51 -05:00
Oliver Kowalke
5910ac9eff remove 'break' from qaiting_queue
- break prevents asio exmples from working
2014-09-18 20:37:55 +02:00
Vincent Lee
c6cdd4a988 fix deque erase, the end() iterator cannot be used as erase position. 2014-09-15 18:04:36 +08:00
Oliver Kowalke
e48252837f accept any clock type for lock_until() etc. 2014-09-05 17:55:16 +02:00
Oliver Kowalke
2d4a919faa fix errors because of -pedantic 2014-08-23 14:20:01 +02:00
Oliver Kowalke
0aaff7cb6d fix queues::push(9 for MSVC 2014-08-23 13:40:42 +02:00
Oliver Kowalke
6c1229af0d call forward() and move() with namespace boost 2014-08-21 20:22:10 +02:00
Oliver Kowalke
64ea436557 inline functions for full-specialized tempaltes 2014-08-21 17:34:23 +02:00
Oliver Kowalke
00944ddf6a update using chrono-clocks 2014-08-20 17:37:47 +02:00
olk
539660d132 Merge pull request #19 from niXman/develop
preprocessor inline macro replaced
2014-08-17 22:04:54 +02:00
niXman
13bbaf0ced preprocessor inline macro replaced 2014-08-17 22:56:42 +03:00
Oliver Kowalke
5ede204812 optimize calling high_resolution_clock::now() 2014-08-17 20:28:40 +02:00
Oliver Kowalke
f615b5f6fc fix bind() using variadric args 2014-07-29 18:13:39 +02:00
Oliver Kowalke
20e6bb78ca optimize trampoline() - store fiber-fn only once 2014-07-29 18:13:05 +02:00
Oliver Kowalke
19c66aa610 sech_algorithm in separat file 2014-07-21 20:04:24 +02:00
Oliver Kowalke
4a2162f83b fixes for unbounded_queue<> 2014-07-20 11:10:48 +02:00
Oliver Kowalke
e077960c14 fixes for bounded_queue<> 2014-07-20 11:10:32 +02:00
Nat Goodspeed
59fd8ed319 Expressions with side effects in BOOST_ASSERT() fail in release builds. :-P
Also suppress a few 'unused variable' warnings.
2014-07-18 11:05:30 -04:00
Nat Goodspeed
9e21b43221 Move new node_type allocations before locking mtx_. 2014-07-18 08:29:10 -04:00
Nat Goodspeed
d7035722b4 Pass unique_lock down to push_() and push_wait_until_().
Earlier refactoring moved the unique_lock instantiation back to public
methods, though it was referenced in private methods. Pass it into those
methods.
2014-07-17 16:53:20 -04:00
Nat Goodspeed
b01cc1f224 Reintroduce pthread_key_create() implementation for Mac thread_local_ptr.
At some point the original implementation seems to have gotten lost?
2014-07-17 15:02:04 -04:00
Nat Goodspeed
9e81e970d9 Move lock acquisition from private back to public methods.
Oliver pointed out the thread-safe-interface pattern:
http://www.cs.wustl.edu/~schmidt/PDF/locking-patterns.pdf
2014-07-17 09:40:20 -04:00
Nat Goodspeed
0bde483bd2 Refactor bounded_queue<T> implementation to reduce redundancy.
Introduce private push_(), try_push_(), push_wait_until_() helper methods:
each of push(), try_push() and push_wait_until() has two signatures for
value_type const& versus value_type&&, but the code paths are identical once
we have a new node_type in hand. Moreover, extract processing common to all
into private push_and_notify_() method. (This fixes an inconsistency in push()
exception behavior.)

Extract common processing from pop(), value_pop(), try_pop() and
pop_wait_until() to private value_pop_() method. This retains a node_type::ptr
to the old head node until return time, unifying the code paths between its
return-by-value and assign-through-reference callers. (This fixes an
inconsistency in try_pop() exception behavior.)
2014-07-16 12:06:37 -04:00
Oliver Kowalke
2b421d41f8 fix for MSVC 2014-07-15 22:28:41 +02:00
Oliver Kowalke
22850775ca variadric tempalte args 2014-07-15 20:33:14 +02:00
Oliver Kowalke
7ef27d66d6 fix typename for MSVC 2014-07-13 20:46:47 +02:00
Oliver Kowalke
07f394a1b4 fixes for MSVC 2014-07-13 20:35:15 +02:00
Oliver Kowalke
161e9c73fc some fixes for MSVC 2014-07-13 17:13:51 +02:00
Oliver Kowalke
cf43ddd8b9 add function type for MSVC 2014-07-12 21:56:08 +02:00
Oliver Kowalke
a0eca3c1d9 using BOOST_RV_REF consitent 2014-07-12 11:50:57 +02:00
Oliver Kowalke
cdb855cbf8 define BOOST_FIBERS_USE_VARIADIC_FIBER 2014-07-10 19:46:31 +02:00
Oliver Kowalke
cff7bc7ea5 move conver_tp() to separate file 2014-07-10 19:45:54 +02:00
Oliver Kowalke
7ef6302f86 arbitrary clock::time_point conforming to chrono clock concept allowed 2014-07-08 17:41:59 +02:00
Oliver Kowalke
8df4a56564 use high_resolution_clock 2014-07-07 20:32:56 +02:00
Oliver Kowalke
5cf28979a5 queues should support value_pop() 2014-07-07 17:40:53 +02:00
Oliver Kowalke
05256654da reduce redundancy of try_lock()/lock() in mutex 2014-07-05 11:09:40 +02:00
Oliver Kowalke
19388c3674 explict test of intrusive_ptr against NULL 2014-07-05 10:03:40 +02:00
Oliver Kowalke
e972219e69 use explicit-operator-bool macro instead of safe_bool 2014-07-04 18:32:40 +02:00
Oliver Kowalke
a9f52d3007 add future<>::get_exception_ptr() 2014-06-29 14:13:33 +02:00
Oliver Kowalke
b936512136 remove mutex::scoped_lock by unique_lock< mutex > 2014-06-29 13:31:01 +02:00
Oliver Kowalke
a2d3eba716 fix migrating a fiber between threads 2014-06-26 19:01:49 +02:00
Oliver Kowalke
bf51216237 re-organize precondition for worker_fiber::resume() 2014-06-25 18:23:23 +02:00
Oliver Kowalke
b4b9dbea77 some fixes 2014-06-24 19:49:14 +02:00
Oliver Kowalke
dfeb4ff290 changes to support fier migration
- still not correct
2014-06-23 20:15:02 +02:00
Oliver Kowalke
6b5e6aef22 use TLS for pointer to fiber manager 2014-06-22 20:34:43 +02:00