proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
AddTasks.h
Go to the documentation of this file.
1
/*
2
* Copyright 2014-present Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
#pragma once
17
18
#include <functional>
19
#include <vector>
20
21
#include <
folly/Optional.h
>
22
#include <
folly/Try.h
>
23
#include <
folly/fibers/FiberManagerInternal.h
>
24
#include <
folly/fibers/Promise.h
>
25
26
namespace
folly
{
27
namespace
fibers {
28
29
template
<
typename
T>
30
class
TaskIterator
;
31
43
template
<
class
InputIterator>
44
TaskIterator
<
invoke_result_t
<
45
typename
std::iterator_traits<InputIterator>
::
46
value_type
>>
inline
addTasks
(InputIterator
first
, InputIterator last);
47
48
template
<
typename
T>
49
class
TaskIterator
{
50
public
:
51
typedef
T
value_type
;
52
53
TaskIterator
() :
fm_
(
FiberManager
::
getFiberManager
()) {}
54
55
// not copyable
56
TaskIterator
(
const
TaskIterator
& other) =
delete
;
57
TaskIterator
&
operator=
(
const
TaskIterator
& other) =
delete
;
58
59
// movable
60
TaskIterator
(
TaskIterator
&& other)
noexcept
;
61
TaskIterator
&
operator=
(
TaskIterator
&& other) =
delete
;
62
68
template
<
typename
F>
69
void
addTask
(F&& func);
70
75
bool
hasCompleted
()
const
;
76
80
bool
hasPending
()
const
;
81
85
bool
hasNext
()
const
;
86
94
T
awaitNext
();
95
104
void
reserve
(
size_t
n);
105
109
size_t
getTaskID
()
const
;
110
111
private
:
112
template
<
class
InputIterator>
113
friend
TaskIterator
<
114
invoke_result_t<typename std::iterator_traits<InputIterator>::value_type
>>
115
addTasks
(InputIterator
first
, InputIterator last);
116
117
struct
Context
{
118
std::vector<std::pair<size_t, folly::Try<T>>>
results
;
119
folly::Optional<Promise<void>
>
promise
;
120
size_t
totalTasks
{0};
121
size_t
tasksConsumed
{0};
122
size_t
tasksToFulfillPromise
{0};
123
};
124
125
std::shared_ptr<Context>
context_
{std::make_shared<Context>()};
126
size_t
id_
{
std::numeric_limits<size_t>::max
()};
127
FiberManager
&
fm_
;
128
129
folly::Try<T>
awaitNextResult
();
130
};
131
}
// namespace fibers
132
}
// namespace folly
133
134
#include <
folly/fibers/AddTasks-inl.h
>
Try.h
folly::fibers::TaskIterator::value_type
T value_type
Definition:
AddTasks.h:51
folly::fibers::TaskIterator::addTasks
friend TaskIterator< invoke_result_t< typename std::iterator_traits< InputIterator >::value_type > > addTasks(InputIterator first, InputIterator last)
Definition:
AddTasks-inl.h:114
folly::fibers::TaskIterator::awaitNextResult
folly::Try< T > awaitNextResult()
Definition:
AddTasks-inl.h:42
folly::fibers::TaskIterator::hasCompleted
bool hasCompleted() const
Definition:
AddTasks-inl.h:27
folly::fibers::TaskIterator::Context
Definition:
AddTasks.h:117
folly::invoke_result_t
typename invoke_result< F, Args... >::type invoke_result_t
Definition:
Invoke.h:142
max
LogLevel max
Definition:
LogLevel.cpp:31
folly::fibers::TaskIterator::addTask
void addTask(F &&func)
Definition:
AddTasks-inl.h:89
folly::fibers::TaskIterator::fm_
FiberManager & fm_
Definition:
AddTasks.h:127
folly::fibers::TaskIterator::Context::promise
folly::Optional< Promise< void > > promise
Definition:
AddTasks.h:119
folly::fibers::TaskIterator::reserve
void reserve(size_t n)
Definition:
AddTasks-inl.h:62
folly::fibers::TaskIterator::id_
size_t id_
Definition:
AddTasks.h:126
folly::T
folly::std T
AddTasks-inl.h
folly::fibers::TaskIterator::Context::tasksToFulfillPromise
size_t tasksToFulfillPromise
Definition:
AddTasks.h:122
folly
—— Concurrent Priority Queue Implementation ——
Definition:
AtomicBitSet.h:29
folly::pushmi::__adl::noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
Definition:
extension_points.h:40
folly::fibers::TaskIterator::Context::tasksConsumed
size_t tasksConsumed
Definition:
AddTasks.h:121
folly::fibers::TaskIterator::Context::results
std::vector< std::pair< size_t, folly::Try< T > > > results
Definition:
AddTasks.h:118
folly::fibers::TaskIterator::Context::totalTasks
size_t totalTasks
Definition:
AddTasks.h:120
folly::fibers::FiberManager
Single-threaded task execution engine.
Definition:
FiberManagerInternal.h:77
folly::fibers::TaskIterator::operator=
TaskIterator & operator=(const TaskIterator &other)=delete
folly::Optional
Definition:
Optional.h:71
Promise.h
folly::fibers::TaskIterator::getTaskID
size_t getTaskID() const
Definition:
AddTasks-inl.h:82
folly::fibers::addTasks
TaskIterator< invoke_result_t< typename std::iterator_traits< InputIterator >::value_type > > addTasks(InputIterator first, InputIterator last)
Definition:
AddTasks-inl.h:114
folly::fibers::TaskIterator::hasNext
bool hasNext() const
Definition:
AddTasks-inl.h:37
folly::fibers::TaskIterator::TaskIterator
TaskIterator()
Definition:
AddTasks.h:53
folly::Try
Definition:
Try.h:51
folly::fibers::TaskIterator::context_
std::shared_ptr< Context > context_
Definition:
AddTasks.h:125
folly::fibers::TaskIterator::hasPending
bool hasPending() const
Definition:
AddTasks-inl.h:32
folly::fibers::TaskIterator
Definition:
AddTasks.h:30
FiberManagerInternal.h
folly::fibers::TaskIterator::awaitNext
T awaitNext()
Definition:
AddTasks-inl.h:52
Optional.h
folly::gen::first
constexpr detail::First first
Definition:
Base-inl.h:2553
folly::fibers::getFiberManager
FiberManager & getFiberManager(EventBase &evb, const FiberManager::Options &opts)
Definition:
FiberManagerMap.cpp:183
proxygen
folly
folly
fibers
AddTasks.h
Generated by
1.8.11