Commit Graph

323 Commits

Author SHA1 Message Date
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
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
1c3b447716 some fixes 2014-09-26 17:57:53 +02:00
Oliver Kowalke
7483a729aa some fixes 2014-09-25 18:52:04 +02:00
Oliver Kowalke
7fb469cd10 some fixes 2014-09-24 19:18:44 +02:00
Oliver Kowalke
ae1ebd7b01 Revert "optimize the example for asio loop"
This reverts commit 61a8a8ea89.
2014-09-18 19:25:58 +02:00
Vincent Lee
61a8a8ea89 optimize the example for asio loop 2014-09-15 18:14:15 +08:00
Oliver Kowalke
c005bb2c8f doc update 2014-09-09 20:40:26 +02:00
Oliver Kowalke
0948d577dc fix examples 2014-08-23 14:09:21 +02:00
Oliver Kowalke
4b604ff93a test for multiple definitions 2014-08-21 17:28:28 +02:00
Oliver Kowalke
e24f27c75c fix publish-subscriber example 2014-08-21 17:27:53 +02:00
Oliver Kowalke
ef6c16e934 optimized server app in publish-subscribe example 2014-08-17 20:41:31 +02:00
Oliver Kowalke
22850775ca variadric tempalte args 2014-07-15 20:33:14 +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
5cf28979a5 queues should support value_pop() 2014-07-07 17:40:53 +02:00
Oliver Kowalke
b936512136 remove mutex::scoped_lock by unique_lock< mutex > 2014-06-29 13:31:01 +02:00
Oliver Kowalke
7116c7ff03 use fm_<xyz> functions in asio intregration files 2014-06-29 13:30:40 +02:00
Oliver Kowalke
e72e388843 enable other examples 2014-06-29 13:24:52 +02:00
Oliver Kowalke
d2eea37b53 use mutex + deque as ready-queue in example work-stealing 2014-06-23 18:05:06 +02:00
Oliver Kowalke
026003bb65 use the free fm_<xyz> - functions 2014-06-17 11:51:14 +02:00
Oliver Kowalke
f4defed2b5 workstealing example 2014-03-25 17:45:56 +01:00
Oliver Kowalke
b5b22ff606 workstealing example 2014-03-24 20:05:14 +01:00
Oliver Kowalke
e031ba4762 move asio-stuff to example section 2014-03-24 19:14:38 +01:00
Oliver Kowalke
ab91ab52b8 changes for boost.asio 2014-03-23 18:20:15 +01:00
Oliver Kowalke
9f7f74f662 use symmetric_coroutine<>::yield_type::operator()() 2014-03-15 19:16:13 +01:00
Oliver Kowalke
a1e3c1d081 merge from branch feature/tls 2014-03-08 10:16:22 +01:00
Oliver Kowalke
5b6d77b6b5 renaming of fiber classes 2014-03-05 17:30:11 +01:00
Oliver Kowalke
67111d3e58 workstealing round-robin scheduler moved to examples 2014-03-04 18:01:42 +01:00
Oliver Kowalke
2b37b33011 use asymmetric_coroutine<> from (coroutine branch develop) 2014-02-22 21:26:28 +01:00
olk
552c175be1 add some comments to publish-subscibe example 2014-01-07 08:46:26 +01:00
olk
a2611f032a change copy right in example/future_mt.cpp 2014-01-07 07:48:53 +01:00
Oliver Kowalke
8de7066392 fix library name in Jamfile 2013-12-30 15:33:13 +01:00
Oliver Kowalke
3cc7d06482 additional example for transfering future between threads 2013-12-29 22:21:44 +01:00
Mario Lang
d471d7133d Fix some typos. 2013-12-29 14:00:36 +01:00
Oliver Kowalke
7594f74568 add required compiler flags for segmentad-stacks 2013-12-08 15:02:49 +01:00
Oliver Kowalke
511b740ec2 default-scheduler allocated 2013-12-02 19:45:48 +01:00
Oliver Kowalke
64529df3b4 changed interface of (un)bounded_queue 2013-11-17 18:55:32 +01:00
Oliver Kowalke
393797a94e fix queues related to closed queue and poping values 2013-11-02 14:49:25 +01:00
Oliver Kowalke
bac5c197c0 remove queue::close() from ping_pong example 2013-11-02 14:21:32 +01:00
Oliver Kowalke
6bb976b4d3 fix queues 2013-11-02 14:15:05 +01:00
Oliver Kowalke
f04b484a21 fix test coein example simple.cpp 2013-10-28 13:38:22 +01:00
Oliver Kowalke
436883ca33 add workstealing round_robin 2013-10-25 18:01:56 +02:00
Oliver Kowalke
98f54ad0e4 rename fibers::asio::io_service -> fibers::asio::round_robin 2013-10-24 18:42:07 +02:00
Oliver Kowalke
ec8a11e60c atomic fiber::state_ 2013-10-17 19:21:26 +02:00
Oliver Kowalke
147d41833a remove exception example 2013-10-01 19:43:29 +02:00
Oliver Kowalke
500c1e605b example regarding to exceptions 2013-09-29 11:05:57 +02:00
Oliver Kowalke
4465d50c0c example interrupting fiber 2013-09-29 10:42:11 +02:00
Oliver Kowalke
2a6ea310a1 fix linkingissue 2013-09-28 16:53:04 +02:00
Oliver Kowalke
84d2a50491 fix Jamfiles and multithreading 2013-09-28 10:24:47 +02:00
Oliver Kowalke
32405f7a99 add asio example demonstaratiing sync. of fibers 2013-09-11 09:27:27 +02:00
Oliver Kowalke
e996d2e28f use coroutines inside fiber 2013-09-09 08:52:26 +02:00
Oliver Kowalke
00ec9d32a3 update 2013-08-28 21:57:14 +02:00
Oliver Kowalke
d91578120f fix libname 2013-08-18 22:14:10 +02:00
Oliver Kowalke
9d67164839 adapt io_service to wait-op requirements 2013-08-18 10:52:36 +02:00
Oliver Kowalke
3485f551aa add async() 2013-08-18 10:30:15 +02:00
Oliver Kowalke
94482d25b6 add time-point to schedulable fiber 2013-08-13 18:23:53 +02:00
Oliver Kowalke
f06b6cf0d4 fix auto-link in config.hpp 2013-08-13 10:27:02 +02:00
Oliver Kowalke
11eb0c6082 add boost.asio spawn() for fibers 2013-06-19 18:03:48 +02:00
Oliver Kowalke
9d58afd3ec add some examples using boost.asio async_result 2013-06-16 16:19:24 +02:00
Oliver Kowalke
de3bc64e4f boost.asio related stuff (fiber-aware io_servic etc.) 2013-06-14 20:37:47 +02:00
Oliver Kowalke
31c764b7bc some code clean-up 2013-06-14 16:53:46 +02:00
Oliver Kowalke
04ddde32f1 refactor of support of boost.asio async_result (use_future_t) 2013-06-13 17:39:03 +02:00
Oliver Kowalke
fc9938190e add example using boost.asio async_result feature 2013-06-12 16:58:45 +02:00
Oliver Kowalke
61c3fd4589 some fixes 2013-06-10 20:11:52 +02:00
Oliver Kowalke
9dfeb585d6 remove code for fiber migration 2013-03-19 17:44:43 +01:00
Oliver Kowalke
5ff11b0df4 example fiber-steeling updatedd 2013-03-16 19:57:15 +01:00
Oliver Kowalke
7ab57b66f7 examples updated 2013-03-16 19:54:59 +01:00
Oliver Kowalke
b752574dfa disable future tests and example 2013-02-27 20:16:03 +01:00
Oliver Kowalke
b4623a7e53 fix example join 2013-01-30 19:42:55 +01:00
Oliver Kowalke
9ad0ec1937 adapt examples 2013-01-30 19:16:19 +01:00
Oliver Kowalke
017039c3b5 addapt examples to new version 2013-01-12 21:16:46 +01:00
Oliver Kowalke
cfdcf1d16a interface algorithm, round_robin 2012-12-19 19:37:05 +01:00
Oliver Kowalke
1e248b0216 require to set scheduler for each os-thread 2012-12-17 19:54:34 +01:00
Oliver Kowalke
81e62e8962 changed directory structure as required by modularized-boost 2012-12-09 15:22:59 +01:00