Commit Graph

323 Commits

Author SHA1 Message Date
Oliver Kowalke
1ace8bbb36 make async_result::get() an interruption point 2016-01-31 18:14:24 +01:00
Oliver Kowalke
3ac9dde4d0 update asio integration example 2016-01-31 16:48:04 +01:00
Oliver Kowalke
284bdf6f78 fix asio integration - skip promise_handler 2016-01-31 16:14:14 +01:00
Oliver Kowalke
62b2a52857 some fixes for asio integration - promise problematic 2016-01-31 11:00:08 +01:00
Oliver Kowalke
51f4cb1a26 update asio integration in directory examples 2016-01-29 17:04:15 +01:00
Oliver Kowalke
3cfe41c01e fix asio/round_robin.hpp
block thread only in io_service::rune_one() if no fibers ready
2016-01-26 11:54:27 +01:00
Oliver Kowalke
dd661d4e5d attempt of better integration with asio 2016-01-25 21:48:18 +01:00
Oliver Kowalke
a4c2315c54 fix examples because autoreset_event was removed 2016-01-25 21:47:58 +01:00
Oliver Kowalke
172d5569a6 fix typo in comment of example work_sharing.cpp 2016-01-20 19:44:59 +01:00
Oliver Kowalke
f01cf1daff update migration example 2016-01-20 19:42:26 +01:00
Oliver Kowalke
34be91cb3c update docu migration 2016-01-17 21:08:29 +01:00
Oliver Kowalke
d541e88a4b update documentation 2015-12-29 15:04:13 +01:00
Oliver Kowalke
ff8537d153 re-enable example wait_stuff 2015-12-17 20:05:49 +01:00
Oliver Kowalke
b196c2d872 disable example wait_stuff from build 2015-12-14 20:45:46 +01:00
Oliver Kowalke
db180f08da relax to C++11 2015-12-12 23:19:33 +01:00
Oliver Kowalke
6034c1b09b reenable Nat's promise_handler impl 2015-12-05 15:14:54 +01:00
Oliver Kowalke
3319841788 use spinlock_lock+context instead of function<> 2015-12-03 17:57:00 +01:00
Oliver Kowalke
726d4d51b9 ++14 polishing 2015-12-01 21:07:11 +01:00
Oliver Kowalke
ca655a84d9 execute func + set active fiber inside context::resume() 2015-11-22 14:28:09 +01:00
Oliver Kowalke
a71e19ec4b fix work-stealing example 2015-11-11 07:18:32 +01:00
Oliver Kowalke
5973f6a262 add work-stealing example 2015-10-21 15:26:55 +02:00
Oliver Kowalke
f743b63bc0 replace context::attach()/detach() by context::migrate() 2015-10-21 15:25:12 +02:00
Oliver Kowalke
edd439233a fixups for asio examples 2015-10-17 14:41:53 +02:00
Oliver Kowalke
5345d810a8 asio: executed dummy fiber after sleep-timer expires 2015-10-14 13:43:14 +02:00
Oliver Kowalke
51c1a96c4d introduce attach/detach of context 2015-10-14 13:37:44 +02:00
Oliver Kowalke
7617b74e57 remove second unlinking from worker-queue in work-sharing example 2015-10-12 22:05:15 +02:00
Oliver Kowalke
c07115115c work sharing example: some modifications 2015-10-12 18:55:54 +02:00
Oliver Kowalke
0deb75a699 modify work-sharign example 2015-10-12 18:44:21 +02:00
Oliver Kowalke
380e8b30c1 use atomic coutner for remainng fibers
- instead of using scheduling_algorithm::has_ready_fibers() use
  a atomic counter as termination indication
- scheduling_algorithm::has_ready_fibers() returns true even if
  only main-context and dispatcher-context are ready -> false indication
  for work-sharing example
2015-10-11 12:01:30 +02:00
Oliver Kowalke
d4c7232fa2 modify work-sharing example 2015-10-11 08:41:49 +02:00
Oliver Kowalke
ecab1c5ee6 work-sharing example 2015-10-10 21:51:14 +02:00
Oliver Kowalke
b032457397 asio examples added 2015-10-10 21:50:22 +02:00
Oliver Kowalke
ae67ee1694 asio's spawn() 2015-10-05 19:23:16 +02:00
Oliver Kowalke
5d71a4f8cd asio examples 2015-10-04 20:08:21 +02:00
Oliver Kowalke
5357f7038e scheduling-algorithm handles empty ready-queue
- if dispatcher-context detects empty ready-queue
  the scheduler has to be suspended till signaled or
  timeout reached
2015-10-03 09:35:47 +02:00
Oliver Kowalke
275ae3b981 add additional examples 2015-09-30 17:38:44 +02:00
Oliver Kowalke
48d652adab add example wait_stuff 2015-09-29 20:27:33 +02:00
Oliver Kowalke
6d24450d40 example futures_mt removed 2015-09-29 20:26:35 +02:00
Oliver Kowalke
253d981f52 examples added 2015-09-29 17:55:46 +02:00
Oliver Kowalke
d0cb6e6756 some examples 2015-09-22 21:10:14 +02:00
Oliver Kowalke
eafeaaae01 remove examples and tests 2015-09-16 19:12:57 +02:00
Oliver Kowalke
8c4dda107c support signaling a fiber from another thread
- for this first version lockfree::queue<> is used
- maybe Dimitry Byukov's mpsc intrusive queue is better suited
2015-09-13 09:20:35 +02:00
Oliver Kowalke
070606d2d1 disable asio examples
- interaction with external event-loops not implemented
2015-09-11 20:45:54 +02:00
Oliver Kowalke
abd1ff524c fixes for signaling interruption and wait 2015-09-11 18:42:16 +02:00
Oliver Kowalke
e44a41b71e add output 'done' at the end of examples 2015-09-11 18:41:46 +02:00
Oliver Kowalke
2173200c14 example simple 2015-09-10 18:07:41 +02:00
Nat Goodspeed
c9bd8360b4 Merge branch 'develop' of http://github.com/olk/boost-fiber into develop 2015-09-09 21:47:46 -04:00
Nat Goodspeed
2b6135364e Make awakened() unconditionally insert fiber.
There was a bug when the ready queue wasn't empty, but there was no
lower-priority fiber already in the queue. In that case the fiber wouldn't be
inserted. We want the loop just to advance the iterator, but to perform the
insert regardless of where the iterator ends up. (With this logic, empty() is
no longer a special case.)

Restore the ~Verbose() message.
2015-09-09 21:46:35 -04:00
Oliver Kowalke
513204a75e add termination output to example simple.cpp 2015-09-09 21:11:02 +02:00
Nat Goodspeed
268922a9e6 Merge branch 'develop' of http://github.com/olk/boost-fiber into develop 2015-09-09 13:51:50 -04:00
Oliver Kowalke
c89410dfd8 uses intrusive::list<> isntread hand-written queues 2015-09-09 19:22:54 +02:00
Oliver Kowalke
e4fc7e7736 restore simple example 2015-09-08 21:35:46 +02:00
Oliver Kowalke
2cd1d39f12 fix clang compiler error regarding missing typename 2015-09-08 18:58:36 +02:00
Nat Goodspeed
6702d7cb9c Merge branch 'develop' of http://github.com/olk/boost-fiber into develop 2015-09-08 06:21:33 -04:00
Oliver Kowalke
5854743a0a force segfault in work-sharing example 2015-09-07 22:24:20 +02:00
Oliver Kowalke
3200e419d2 increase amount of fibers and threads 2015-09-07 20:58:22 +02:00
Nat Goodspeed
f28b6fc497 Update shared_ready_queue::main_fiber comments. 2015-09-07 14:55:30 -04:00
Nat Goodspeed
6cf8f4627f Update work_sharing to never share a thread's main fiber.
Instead, when the main fiber is passed to awakened(), stash it in a separate
slot and make pick_next() return it only when the shared queue is empty.

Update ready_fibers() to include a non-empty main_fiber slot.
2015-09-07 14:50:55 -04:00
Oliver Kowalke
6499bb07e7 fiber_context renamed to context 2015-09-07 17:23:59 +02:00
Oliver Kowalke
7f97616aa2 Merge branch 'ws' into develop 2015-09-07 17:07:59 +02:00
Oliver Kowalke
4dc5aaab59 add example of work-sharing 2015-09-07 11:53:13 +02:00
Oliver Kowalke
bc044fbed2 stuff 2015-09-06 21:36:06 +02:00
Nat Goodspeed
d653cbdcc6 Finish proofreading pass.
Add a note to the condition_variable::wait_for(..., pred) overload.

fiber_specific_ptr::reset() has no default argument.

Remove mention of launch policy deferred, since no API accepts a launch
policy argument.

Copy construction or copy assignment of a shared_future leaves other.valid()
unchanged. It won't be 'true' unless it was 'true' before.

Mention that [shared_]future::get_exception_ptr() does not invalidate.

Note that 'blocks' and 'suspends' are used interchangeably.

Add some cross-references; add link to std::allocator_arg_t. Clarify the
cross-reference to the paragraph describing BOOST_FIBERS_NO_ATOMICS.

Reformat some overly-long source lines.
2015-09-03 09:16:09 -04:00
Nat Goodspeed
bcdb555821 Use std::shared_ptr and std::make_shared for promise_handler.
Publish promise_handler::promise_ptr and use it in asio_handler_invoke() for
consistency.
2015-09-03 08:47:25 -04:00
Oliver Kowalke
be3d67a109 add end marker to example priority 2015-09-02 20:29:09 +02:00
Oliver Kowalke
52c03cb5fd fix merge error 2015-09-02 19:56:26 +02:00
Oliver Kowalke
ba35ac6de2 update documentation 2015-09-02 19:43:33 +02:00
Oliver Kowalke
a173c047a6 update documentation 2015-09-02 19:41:08 +02:00
Nat Goodspeed
37a0490bbd Fix bug in this_fiber::properties<>().
When the running thread's main fiber calls this_fiber::properties<>() without
yet having passed through sched_algorithm_with_properties::awakened(), which
is what actually instantiates the fiber_properties subclass, you could end up
without a properties instance. Fortunately there's an easy workaround: call
yield().

Remove that workaround from examples/priority.cpp.
2015-09-01 20:21:13 -04:00
Nat Goodspeed
aeaef6510f Reverse advice about when to set the properties for a new fiber.
Change which example code we show for this_fiber::properties<>() and
fiber::properties<>().
2015-09-01 19:55:33 -04:00
Nat Goodspeed
11b06c25dd Fix bug in priority_scheduler::property_change().
The complex logic to make a single pass through the ready queue to find the
old location and also the new insertion point was unfortunately error-prone.
Recast it as two separate passes: a simple search loop to find and unlink the
fiber_context*, then a call to awakened() to reinsert it in the correct place.
2015-09-01 19:16:47 -04:00
Oliver Kowalke
82143be5aa update documentation + formating 2015-09-01 17:32:07 +02:00
Oliver Kowalke
fefffd37eb update documentation 2015-09-01 17:17:38 +02:00
Oliver Kowalke
5f6df41bc7 first part of formating example wait_stuff 2015-08-31 21:53:47 +02:00
Nat Goodspeed
e3bb470376 Fill in section on adapting to nonblocking I/O. 2015-08-31 11:29:26 -04:00
Nat Goodspeed
2ed2bb4827 Add when_all_members() description. 2015-08-31 10:38:40 -04:00
Nat Goodspeed
f15fccb4b9 Add wait_all_collect_errors() description. 2015-08-31 10:08:31 -04:00
Nat Goodspeed
cc8acb1fee Add wait_all_until_error(), wait_all_until_error_source() description. 2015-08-31 10:00:38 -04:00
Nat Goodspeed
56191d5190 Add wait_all_values(), wait_all_values_source() description. 2015-08-31 08:15:06 -04:00
Nat Goodspeed
5cb215f741 Add wait_all_simple() description. 2015-08-30 20:49:45 -04:00
Nat Goodspeed
53127efe42 Add wait_first_value_het() description. 2015-08-30 19:56:40 -04:00
Nat Goodspeed
ec251c3c02 Add wait_first_success() description. 2015-08-30 19:28:44 -04:00
Nat Goodspeed
bed11fe0a1 Add wait_first_outcome() description. 2015-08-30 18:42:50 -04:00
Nat Goodspeed
2c36b37122 Answered my own question about exception in detached fiber. 2015-08-30 17:41:20 -04:00
Nat Goodspeed
34ec067a1f Add QuickBook markup for wait_first_value() section. 2015-08-29 21:34:55 -04:00
Nat Goodspeed
a8debb9201 Add first when_any passage (wait_first_simple())... work in progress. 2015-08-29 19:42:53 -04:00
Nat Goodspeed
ad1d3d118a Introduce wait_all_members_get() to restore asynchrony.
Passing the futures from the argument-pack functions through a function-call
boundary forces the runtime to perform all the async() calls _first,_ then
make a separate pass through the futures to obtain results.
2015-08-29 14:17:45 -04:00
Nat Goodspeed
9c1b412f7e Naive implementation of wait_all_members() is in fact synchronous. 2015-08-29 14:05:23 -04:00
Nat Goodspeed
f384143d04 Add wait_all_collect_errors() plus example usage. 2015-08-29 13:26:52 -04:00
Nat Goodspeed
5e30a4647b Add wait_all_until_error(), wait_all_until_error_source(), plus examples. 2015-08-29 13:10:01 -04:00
Nat Goodspeed
9c7a0b7bc5 Add wait_all_values(), wait_all_values_source(), plus example usage. 2015-08-29 12:35:25 -04:00
Nat Goodspeed
e9a234d06b Intersperse example calling code with implementations.
Introduce Runner and Example classes to collect and ultimately run lambdas
illustrating use of each different wait_something() variant.

Move Verbose up to the top for use by Runner. Similarly, move sleeper() for
use by those lambdas.

The body of main() then reduces to a Runner::run() call.
2015-08-29 09:08:20 -04:00
Nat Goodspeed
02eb362de5 wait_all_simple() can no longer share wait_first_simple_impl().
Now that wait_first_simple() is again based on Done (a bool protected by a
condition variable) rather than a barrier(2), have to introduce
wait_all_simple_impl() to manage the barrier.
2015-08-29 08:35:46 -04:00
Nat Goodspeed
ab32dbe34a Revert "Remove Done wrapper: fibers::barrier encapsulates that for us."
This reverts commit 59a3afd209, reinstating the
Done wrapper.

While it is true that a barrier(2) will wake up when the second fiber calls
wait(), it then _resets._ This means that the _third_ fiber will wait() for
the fourth, and so on. If an odd number of fibers binds that barrier, the last
of them will hang until shutdown.

We want Done.wait() to wake up on the first notify() call, and for every
subsequent notify() call to be a no-op. Apparently Done is the correct
mechanism after all.
2015-08-29 08:25:40 -04:00
Nat Goodspeed
0c25c3a179 Add wait_all_simple(). Surprisingly like wait_first_simple()! 2015-08-29 02:49:48 +00:00
Nat Goodspeed
59a3afd209 Remove Done wrapper: fibers::barrier encapsulates that for us.
You can wait on a barrier(2) to wait for exactly one more fiber to reach it --
exactly what we need for wait_first_simple().
2015-08-29 02:34:33 +00:00
Nat Goodspeed
fc8a7c612b Add wait_first_value_het() and example usage. 2015-08-29 02:27:16 +00:00
Nat Goodspeed
18ff2286ef Rename wait_any_blah() to wait_first_blah().
Generalize sleeper() task function to be able to return different types.
2015-08-29 02:07:39 +00:00
Nat Goodspeed
37f413c357 Snapshot of wait_stuff.cpp: several wait_any() variants working.
We now have:

wait_any_value(): for when passed functions cannot throw exceptions;

wait_first_outcome(): get earliest result/exception;

wait_first_success(): get first non-exception result.
2015-08-28 15:16:48 -04:00
Nat Goodspeed
76ae45d6c2 Merge branch 'develop' of github.com:nat-goodspeed/boost-fiber into develop 2015-08-26 13:18:25 -04:00
Nat Goodspeed
7af7bd2520 Merge branch 'develop' of http://github.com/olk/boost-fiber into develop 2015-08-26 13:10:31 -04:00
Oliver Kowalke
2601e72673 let sched_algo_ be managed by unique_ptr 2015-08-26 18:59:18 +02:00
Nat Goodspeed
8cce2bb668 Merge branch 'develop' of http://github.com/olk/boost-fiber into develop 2015-08-26 11:56:11 -04:00
Oliver Kowalke
1546533700 examples: priority_scheduler must live long enought
- ~fiber_manager() calls sched_algorithm::pick_next()
- therefore priority_scheudler must live long enough in order to
  be called by ~fiber_manager()
2015-08-26 17:50:12 +02:00
Nat Goodspeed
0f7b6ae71c Add notes that echo_client.cpp and echo_client2.cpp are borrowed from asio.
The casual reader, on encountering these in the Fiber examples directory,
might otherwise assume they're intended to illustrate something about the
Fiber library.
2015-08-25 13:07:35 -04:00
Nat Goodspeed
c52a914906 Add examples/when_stuff.cpp illustrating when_any_simple().
when_any_simple() is "simple" in the sense that we don't care about return
values or possible exceptions -- we only want to know when the shortest
subtask completes.

This source is a work in progress. We intend to add more cases.
2015-08-25 10:13:25 -04:00
Oliver Kowalke
73d38028c4 code re-formating of asio examples 2015-08-24 20:08:56 +02:00
Oliver Kowalke
aa79e05d25 fix code format in examples 2015-08-24 19:52:00 +02:00
Nat Goodspeed
1e3e2b8887 Add callbacks.qbk about interfacing Fiber with async callbacks.
This covers both generic callbacks (adapt_callbacks.cpp,
adapt_method_calls.cpp) and custom Asio completion tokens (yield.hpp,
promise_completion_token.hpp, detail/yield.hpp, detail/promise_handler.hpp).
Mark up the relevant source files to provide code snippets for callbacks.qbk.
2015-08-24 09:28:16 -04:00
Nat Goodspeed
685ba8f16f Add examples/adapt_nonblocking.cpp.
This illustrates how Fiber can ease the problem of wrapping retries for
nonblocking I/O in an event-driven program.
2015-08-23 17:20:49 -04:00
Nat Goodspeed
68044bb349 Don't embed semantically meaningful function calls in assert(). 2015-08-23 17:15:30 -04:00
Nat Goodspeed
550aae5029 Add examples/adapt_method_calls.cpp.
This illustrates how to interface a synchronous Fiber function with an async
API whose notification consists of an abstract base class with virtual
success/error methods.
2015-08-23 11:53:33 -04:00
Nat Goodspeed
7beab5b285 Add examples/adapt_callbacks.cpp.
This illustrates a few different ways of using promise and future to interface
between an asynchronous callback and the Fiber library.
2015-08-23 11:17:10 -04:00
Nat Goodspeed
f3213aae54 use_future.hpp and yield.hpp no longer need handler_invoke_hook.hpp. 2015-08-22 14:43:16 -04:00
Nat Goodspeed
53d4f4b166 Reimplement boost::fibers::asio::yield with promise/future.
In essence, yield_t et al. become very like use_future_t et al. The only real
difference is the async_result return type and get() method. Factor out common
functionality into promise_completion_token and promise_handler.

Remove the boost::fibers::asio::spawn() function and its basic_yield_context
infrastructure. Fix up all existing references in example source code.
2015-08-22 14:22:20 -04:00
Nat Goodspeed
99db8d50a8 Add section about integration with another main loop.
Asio integration may be a much larger topic, per email.
2015-08-19 06:18:08 -04:00
Oliver Kowalke
2855e5128a fix asio stuff 2015-08-18 17:46:14 +02:00
Nat Goodspeed
fd9f16776a Flesh out Customization section with step-by-step directions.
Mark up examples/priority.cpp with code snippets for use in Customization.

Also clarify the effect of changing wait_interval().
2015-08-16 16:38:21 -04:00
Nat Goodspeed
28cbce1256 Eliminate opaque fiber_properties::back_ptr typedef.
It's more straightforward to use the underlying type: fiber_context*.
2015-08-14 16:10:42 -04:00
Nat Goodspeed
0d5ad2adbd Add ready_fibers() override for examples/priority.cpp. 2015-07-31 17:29:33 -04:00
Nat Goodspeed
15a17ca35d Introduce sched_algorithm_with_properties<>::awakened() overload.
sched_algorithm_with_properties<> must intercept awakened() calls before
forwarding control to the subclass override. That pretty much requires two
different virtual methods: one for sched_algorithm subclasses WITHOUT
properties, the other for sched_algorithm_with_properties subclasses.
Originally we used a different name (awakened_props()), but that was
bothersome. It makes more sense to use a different awakened() overload
instead, one that passes in the relevant properties object.

Fix examples/priority.cpp accordingly.

Also delegate instantiation of a new properties object to new_properties()
virtual method. Overriding this method allows you to customize allocation,
instead of sched_algorithm_with_properties<> unconditionally putting the new
properties object on the heap. Validate the new_properties() return value.
2015-06-21 22:39:00 -04:00
Oliver Kowalke
3c7084e359 fix call of execution_context::operator() * exampe priority 2015-05-14 12:11:37 +02:00
Nat Goodspeed
25ccb85d19 Initialize int priority_ properly to 0, not nullptr. 2015-05-13 08:37:32 -04:00
Nat Goodspeed
9c4cdf3438 Desk-checking pass through fiber_properties source code. 2015-05-10 23:35:15 -04:00
Nat Goodspeed
1bec058e77 Move priority.cpp example program to main examples directory.
Since the library no longer supports C++03, the examples/cpp03 subdirectory
has gone away, along with the cpp11 subdirectory.
2015-05-10 22:59:38 -04:00
Nat Goodspeed
2687814477 Merge branch 'develop' of github.com:olk/boost-fiber into sched-props-dev
Resolved conflicts:
	doc/condition_variables.qbk
	examples/cpp03/migration/workstealing_round_robin.cpp
	examples/cpp03/migration/workstealing_round_robin.hpp
	include/boost/fiber/algorithm.hpp
	include/boost/fiber/bounded_queue.hpp
	include/boost/fiber/detail/fiber_base.hpp
	include/boost/fiber/detail/fifo.hpp
	include/boost/fiber/detail/waiting_queue.hpp
	include/boost/fiber/detail/worker_fiber.hpp
	include/boost/fiber/fiber.hpp
	include/boost/fiber/fiber_manager.hpp
	include/boost/fiber/fixedsize_stack.hpp
	include/boost/fiber/operations.hpp
	include/boost/fiber/round_robin.hpp
	include/boost/fiber/unbounded_queue.hpp
	src/detail/worker_fiber.cpp
	src/fiber.cpp
	src/fiber_manager.cpp
	src/round_robin.cpp
2015-05-10 22:03:35 -04:00
Oliver Kowalke
f7f0dacc03 Update segmented_stack.cpp 2015-02-19 13:31:56 +01:00
Oliver Kowalke
e91e016fe8 Update segmented_stack.cpp 2015-02-19 08:37:12 +01:00
Oliver Kowalke
4d6403102b Update segmented_stack.cpp 2015-02-19 08:23:41 +01:00
Oliver Kowalke
ec2d9c6021 add asio examples 2015-02-12 16:29:01 +01:00
Oliver Kowalke
ee0b84240d remove asio examples 2015-02-10 18:45:26 +01:00
Oliver Kowalke
8cfec6deed some fixes for asio exmaples - not compiling 2015-02-10 18:40:40 +01:00
Oliver Kowalke
502581e1e1 remove example fiber-migration 2015-02-10 17:38:44 +01:00
Oliver Kowalke
aa337b07f7 move 'fm_' - free functions into fiber_manager 2015-02-08 16:02:22 +01:00
Oliver Kowalke
13bf486fea update stack-allocators 2015-02-06 18:29:26 +01:00
Oliver Kowalke
d1d7ad7aa0 use recursive-mutex in fiber-migration example 2015-01-19 18:13:51 +01:00
Oliver Kowalke
27c0a78d36 allocate fiber_context on stack 2015-01-13 14:57:32 +01:00
Oliver Kowalke
37747ece0d use fibers::mutext instead std::mutex in workstealing example 2015-01-05 19:58:07 +01:00
Oliver Kowalke
0fda6d1f88 remove some warnings 2015-01-04 13:13:15 +01:00
Oliver Kowalke
3b332c17ee variadric arguments 2015-01-01 14:40:39 +01:00
Oliver Kowalke
584dcdceee allocate/deallocate fiber_base via allocator 2014-12-29 17:38:01 +01:00
Oliver Kowalke
f6c7ab7826 rename (un)bounded_queue -> (un)bounded_channel + use allocator 2014-12-28 21:30:14 +01:00
Oliver Kowalke
44326ebdd3 remove priority 2014-12-28 08:35:44 +01:00
Oliver Kowalke
e9e8ec1b85 fix examples 2014-12-27 21:17:13 +01:00
Oliver Kowalke
2f19be6d67 use C++11 2014-12-27 19:07:42 +01:00
Nat Goodspeed
b5a75be2a0 Add priority.cpp example program.
This illustrates use of a sched_algorithm_with_properties<PROPS> subclass that
defines, and supports, a priority property. The example includes a (somewhat
contrived) case in which a fiber must be moved within the scheduler's ready
queue due to a priority change.
2014-11-19 10:47:06 -05:00
Nat Goodspeed
cb7b5ddd25 Introduce sched_algorithm_with_properties::awakened_props() method.
Every sched_algorithm_with_properties<PROPS> subclass awakened() call must
ensure that control reaches sched_algorithm_with_properties<PROPS>::awakened()
_before_ any logic in the subclass method attempts to access properties. This
turns out to be all too easy to forget.

So instead, advise subclasses to overrride new awakened_props() method. Base-
class method sets things up and then calls awakened_props(). Moreover, when
the compiler supports it, sched_algorithm_with_properties<PROPS>::awakened()
is now marked 'final' to remind subclass authors to override awakened_props()
instead.
2014-11-19 10:40:31 -05:00
Nat Goodspeed
f1a34d297f Remove 'priority' for every fiber, and its support methods.
Priority is another property that's only relevant for future sched_algorithm
implementations. We don't even have an example yet. It's a good candidate for
moving to a specific fiber_properties subclass for that specific
sched_algorithm implementation.
2014-11-11 18:00:18 -05:00
Nat Goodspeed
757d692cae Re-add thread_affinity specific to workstealing_round_robin.
thread_affinity is a good example of a property relevant only to a particular
sched_algorithm implementation. In examples/cpp03/migration, introduce an
'affinity' subclass of fiber_properties with a thread_affinity data
member.

Derive workstealing_round_robin from sched_algorithm_with_properties<affinity>
and, as required by that base class, forward awakened() calls to base-class
awakened() method.

Reimplement workstealing_round_robin's queue from a std::deque to a "by hand"
intrusive singly-linked list so we can efficiently remove an arbitrary item.
Make steal() method, instead of always popping the last item, scan the list to
find the last item willing to migrate (! thread_affinity).

From examples/cpp03/migration/workstealing_round_robin.hpp, an example of a
user-supplied sched_algorithm implementation, remove all boost/fiber/detail
 #includes. These should no longer be needed.

Change sched_algorithm_with_properties::properties(worker_fiber*) method to
accept fiber_base* instead. The original signature was introduced when every
sched_algorithm implementation necessarily manipulated worker_fiber* pointers.
Now we're intentionally avoiding the need.

For the same reason, introduce a fiber_properties::back_ptr typedef so
subclasses can opaquely pass such pointers through their own constructor to
the base-class constructor.
2014-11-11 16:15:25 -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