diff options
author | Yuri Wiitala <miu@chromium.org> | 2019-06-05 17:13:15 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-06 00:20:37 +0000 |
commit | b929b830013ed73cf586c79ad8d61bac975d95e0 (patch) | |
tree | 67f317f80a7794953372ab5f6ffcc27921a34156 /DEPS | |
parent | c6f0d1aff30995a60225aa7cf622d52edf0ad358 (diff) | |
download | openscreen-b929b830013ed73cf586c79ad8d61bac975d95e0.tar.gz |
TaskRunner: Replace use of std::function with std::packaged_task.
The task runner is meant to run a "task" once. Thus, client code should
expect that it can std::bind() with movable types (e.g.,
std::unique_ptr<T>) as arguments. However, the TaskRunner uses
std::function, which only works when all std::bind() arguments are
copyable.
The solution is to replace std::function with std::packaged_task, the
latter of which is purposely designed to be a run-once variant of
std::function; and it also supports move-only types in the bind state.
This change also cleans-up a few other details around the switch:
1. std::packaged_task uses an explicit ctor, whereas std::function
provided an implicit one. Thus, TaskRunner::PostTask() has become a
templated member function, an inline wrapper around calling the
std::packaged_task ctor explicitly.
2. TaskRunnerImpl's use of std::priority_queue for delayed tasks was
replaced with std::multimap, because the API of the former did not
provide non-const access to its elements (which was required for move
operations).
3. Minor tweaks around comments and resource/allocation concerns in
touched code.
Change-Id: I5fe9a2e3a3c2d8d69b564575f81c4a7f4a80b265
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1646564
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Reviewed-by: Ryan Keane <rwkeane@google.com>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
Diffstat (limited to 'DEPS')
0 files changed, 0 insertions, 0 deletions