Commit Graph

35 Commits

Author SHA1 Message Date
Tomasz Grabiec
e5e7348f76 core: Reimplement keep_doing() using repeat() 2015-06-22 09:08:38 +02:00
Tomasz Grabiec
61992f84c5 core: Introduce repeat()
It's like do_until(), but the stop condition is calculated by the
callback instead of being supplied separately.
2015-06-22 09:08:38 +02:00
Avi Kivity
a99956db8e future-util: implement range-based map_reduce() variant 2015-06-21 20:21:24 +03:00
Avi Kivity
3fe6bb505e future: document traitless map_reduce() 2015-06-02 22:20:13 +03:00
Avi Kivity
b0abe9230b doc: fix typo in do_until() 2015-06-01 11:37:42 +03:00
Avi Kivity
3a63706f97 future: document more future-util functions 2015-05-31 19:00:40 +03:00
Avi Kivity
2877364947 future: separate task class into its own header
tasks are a lower-level concept than future/promise, so move them to their
own header.
2015-05-31 15:49:05 +03:00
Avi Kivity
bdfe41820a future-util.hh: add missing include 2015-05-26 16:42:15 +03:00
Vlad Zolotarov
796c203d68 core: remove #include "reactor.hh" from future-util.hh
When future-util.hh is included in files included in reactor.hh (e.g. file.hh).

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-26 15:15:28 +03:00
Avi Kivity
bf527c2842 future: add range-based parallel_for_each variant 2015-05-13 10:53:13 +03:00
Avi Kivity
b35ea31cc9 futures: fix map_reduce() future chaining
map_reduce() did not properly chain futures, so the result was bogus.
2015-04-14 15:13:15 +03:00
Avi Kivity
6f5dc8c15e future: fix map_reduce() return type
Needs to return a future.
2015-04-14 14:55:36 +03:00
Avi Kivity
e03a23b53a future: add std::accumulate-style map_reduce variant 2015-04-13 17:11:44 +03:00
Avi Kivity
6e185d21f0 future: remove bogus when_all() forward declaration
Doesn't match the definition, and is unneeded anyway.
2015-04-13 16:23:33 +03:00
Raphael S. Carvalho
3c908f1ed0 core: Add do_for_each variant
This variant is intended to simplify do_for_each idiom where the
iterators begin() and end() will be implicit.

Allowing the user to do something as follow:
	return do_for_each(map, [] { ... });

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-04-07 23:10:34 +03:00
Gleb Natapov
0838a0ce2f core: drop future<> casting to rvalue before call to then_wrapped()
No longer required.
2015-03-11 17:19:23 +02:00
Avi Kivity
239475e10b future: add runtime-sized variant of when_all()
Add a when_all() variant that waits for a runtime variable number of
futures, all of the same type.  The function returns a future containing
a vector of all input futures, each in ready state, containing either
a result or an exception.
2015-03-10 22:00:02 +02:00
Avi Kivity
baf62adbab future: make when_all(Future... future) mode selective
Currently we have one version of when_all(), that accepts a compile
type variable number of independently typed futures.  We wish to add more
overloads, but for that, we must ensure that this variant doesn't match them.

Accomplish this by requiring that the first argument be a future, and don't
accept any other type.
2015-03-10 21:55:54 +02:00
Tomasz Grabiec
f5485c667d core: Move futurize<> to future.hh 2015-03-06 11:35:56 +01:00
Gleb Natapov
5d1b10d97a core: properly propogate exception in do_until()
[avi: use std::move(f).then_wrapped() until patch removing rvalue
      qualification from then_wrapped() lands]
2015-03-06 12:12:19 +02:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Avi Kivity
17914a80cd future: add a utility to promote a type to a its own future
Some of the core functions accept functions returning either an immediate
type, or a future, and return a future in either case (e.g. smp::submit_to()).

To make it easier to metaprogram with these functions, provide a utility
that computes the return type, futurize<T>:

   futurize_t<bar>          => future<bar>

   futurize_t<void>         => future<>

   futurize_t<future<bar>>  =>  future<bar>
2015-02-18 16:52:56 +02:00
Tomasz Grabiec
331d5e1569 core: Fail do_until() future when the callback throws
Otherwise we will aband the result promise, which results in abort.
2015-02-10 14:47:42 +02:00
Gleb Natapov
3f483b22bc future: add missing std::forward() in do_until_continued() 2015-01-06 14:43:34 +02:00
Avi Kivity
f2e25b8442 Merge branch 'shared_ptr'
Split shared_ptr into a traditional polymorphic shared_ptr implementation,
and a lighter-weight, non polymorphic lw_shared_ptr.
2015-01-05 11:29:35 +02:00
Avi Kivity
87f63f7b90 shared_ptr: rename to lw_shared_ptr (for light-weight)
The current shared_ptr implementation is efficient, but does not support
polymorphic types.

Rename it in order to make room for a polymorphic shared_ptr.
2015-01-04 22:38:49 +02:00
Tomasz Grabiec
584139decd future-util: make do_for_each() propagate failure 2014-12-03 20:02:21 +01:00
Tomasz Grabiec
8d48c91a35 future-util: introduce now()
This function belongs to a group of functions for associating futures
with time points. Currently there's only now(), which servers as a shorthand
for make_ready_future<>().
2014-12-03 19:57:43 +01:00
Avi Kivity
e1397038d4 future-util.hh: add missing include
'task_quota' needs reactor.hh
2014-12-01 17:47:28 +02:00
Tomasz Grabiec
f458117b83 core: avoid recursion in keep_doing()
Recursion takes up space on stack which takes up space in caches which
means less room for useful data.

In addition to that, a limit on iteration count can be larger than the
limit on recursion, because we're not limited by stack size here.

Also, recursion makes flame-graphs really hard to analyze because
keep_doing() frames appear at different levels of nesting in the
profile leading to many short "towers" instead of one big tower.

This change reuses the same counter for limiting iterations as is used
to limit the number of tasks executed by the reactor before polling.

There was a run-time parameter added for controlling task quota.
2014-11-20 11:16:09 +02:00
Tomasz Grabiec
7e25d70392 core: introduce map_reduce() utility
It spawns async mapping action in parallel and reduces the results as
they come.
2014-11-11 13:52:23 +02:00
Gleb Natapov
f0416f44b1 keep_doing: remove infinite loop
Prevent keep_doing() from monopolizing the cpu.
2014-11-04 15:19:01 +02:00
Avi Kivity
7f91f1b937 future: add when_all(future...)
when_all(f1, f2) returns a future that becomes ready when all input futures
are ready.  The return value is a tuple with all input futures, so the values
and exceptions can be accessed.
2014-10-30 13:59:17 +02:00
Avi Kivity
6dcf24f98d Move contents of async-action.hh into future-util.hh 2014-10-27 19:28:10 +02:00
Avi Kivity
82321d435f future: add parallel_for_each() helper
Runs functions in paralllel, and returns a future<> that becomes ready
when all are complete.
2014-10-26 13:34:31 +02:00