dispenso
A library for task parallelism
Loading...
Searching...
No Matches
once_function.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) Meta Platforms, Inc. and affiliates.
3
*
4
* This source code is licensed under the MIT license found in the
5
* LICENSE file in the root directory of this source tree.
6
*/
7
14
#pragma once
15
16
#include <utility>
17
18
#include <dispenso/detail/once_callable_impl.h>
19
20
namespace
dispenso {
21
namespace
detail {
22
template
<
typename
Result>
23
class
FutureBase;
24
template
<
typename
Result>
25
class
FutureImplBase;
26
}
// namespace detail
27
37
class
OnceFunction
{
38
public
:
42
OnceFunction
()
43
#if defined DISPENSO_DEBUG
44
: onceCallable_(
nullptr
)
45
#endif
// DISPENSO_DEBUG
46
{
47
}
48
56
template
<
typename
F>
57
OnceFunction
(
F
&&
f
) : onceCallable_(detail::
createOnceCallable
(std::
forward
<
F
>(
f
))) {}
58
59
OnceFunction
(
const
OnceFunction
&
other
) =
delete
;
60
61
OnceFunction
(
OnceFunction
&&
other
) : onceCallable_(
other
.onceCallable_) {
62
#if defined DISPENSO_DEBUG
63
other
.onceCallable_ =
nullptr
;
64
#endif
// DISPENSO_DEBUG
65
}
66
67
OnceFunction
& operator=(
OnceFunction
&& other) {
68
onceCallable_ = other.onceCallable_;
69
#if defined DISPENSO_DEBUG
70
if
(&other !=
this
) {
71
other.onceCallable_ =
nullptr
;
72
}
73
#endif
// DISPENSO_DEBUG
74
return
*
this
;
75
}
76
81
void
operator()
()
const
{
82
#if defined DISPENSO_DEBUG
83
assert
(onceCallable_ !=
nullptr
&&
"Must not use OnceFunction more than once!"
);
84
#endif
// DISPENSO_DEBUG
85
86
onceCallable_->run();
87
88
#if defined DISPENSO_DEBUG
89
onceCallable_ =
nullptr
;
90
#endif
// DISPENSO_DEBUG
91
}
92
93
private
:
94
OnceFunction
(detail::OnceCallable*
func
,
bool
) : onceCallable_(
func
) {}
95
96
mutable
detail::OnceCallable* onceCallable_;
97
98
template
<
typename
Result>
99
friend
class
detail::FutureBase;
100
template
<
typename
Result>
101
friend
class
detail::FutureImplBase;
102
};
103
104
}
// namespace dispenso
dispenso::OnceFunction
Definition
once_function.h:37
dispenso::OnceFunction::OnceFunction
OnceFunction(F &&f)
Definition
once_function.h:57
dispenso::OnceFunction::operator()
void operator()() const
Definition
once_function.h:81
dispenso::OnceFunction::OnceFunction
OnceFunction()
Definition
once_function.h:42
dispenso::OpResult
detail::OpResult< T > OpResult
Definition
pipeline.h:29
dispenso
once_function.h
Generated by
1.9.8