2
2
#include < bind/yaclib/intrusive_list.hpp>
3
3
#include < semaphore.hpp>
4
4
#include < yaclib/async/future.hpp>
5
- #include < yaclib/executor /inline.hpp>
5
+ #include < yaclib/exe /inline.hpp>
6
6
7
7
#include < future>
8
8
#include < thread>
@@ -17,7 +17,7 @@ T Incr(yaclib::Result<T>&& r) {
17
17
return std::move (r).Ok () + 1 ;
18
18
}
19
19
20
- yaclib::Future <int > Thens (yaclib::Future <int > f, std::size_t n, bool is_executor) {
20
+ yaclib::FutureOn <int > Thens (yaclib::FutureOn <int > f, std::size_t n, bool is_executor) {
21
21
for (std::size_t i = 0 ; i != n; ++i) {
22
22
if (is_executor) {
23
23
f = std::move (f).Then (Incr<int >);
@@ -38,11 +38,10 @@ TestExecutor::TestExecutor(std::size_t num_threads) {
38
38
_workers.emplace_back ([this ] {
39
39
std::unique_lock lock{_m};
40
40
while (true ) {
41
- while (!_tasks .Empty ()) {
42
- auto & task = _tasks .PopFront ();
41
+ while (!_jobs .Empty ()) {
42
+ auto & job = _jobs .PopFront ();
43
43
lock.unlock ();
44
- task.Call ();
45
- task.DecRef ();
44
+ static_cast <yaclib::Job&>(job).Call ();
46
45
lock.lock ();
47
46
}
48
47
if (_stop) {
@@ -79,14 +78,12 @@ yaclib::IExecutor::Type TestExecutor::Tag() const {
79
78
return Type::Custom;
80
79
}
81
80
82
- bool TestExecutor::Submit (yaclib::ITask& task) noexcept {
83
- task.IncRef ();
81
+ void TestExecutor::Submit (yaclib::Job& job) noexcept {
84
82
{
85
83
std::lock_guard guard{_m};
86
- _tasks .PushBack (task );
84
+ _jobs .PushBack (job );
87
85
}
88
86
_cv.notify_one ();
89
- return true ;
90
87
}
91
88
92
89
} // namespace detail::yb
@@ -101,15 +98,28 @@ void YACLib::PromiseAndFuture() {
101
98
std::ignore = std::move (f).Get ().Ok ();
102
99
}
103
100
104
- void YACLib::SomeThens (YACLib::Executor* executor, size_t n, bool no_inline) {
105
- const bool is_executor = executor != nullptr ;
106
- auto f = yaclib::MakeFuture (42 ).Via (executor);
101
+ detail::yb::TestExecutor* YACLib::AcquireExecutor (std::size_t threads) {
102
+ if (threads != 0 ) {
103
+ return new detail::yb::TestExecutor{threads};
104
+ }
105
+ return nullptr ;
106
+ }
107
+
108
+ void YACLib::SomeThens (detail::yb::TestExecutor* executor, size_t n, bool no_inline) {
109
+ bool is_executor = executor != nullptr ;
110
+ auto f = yaclib::MakeFuture (42 ).On (executor != nullptr ? *executor : yaclib::MakeInline ());
107
111
f = Thens (std::move (f), n, is_executor && no_inline);
108
112
f = Thens (std::move (f), 1 , is_executor);
109
113
f = Thens (std::move (f), n, is_executor && no_inline);
110
114
Wait (f);
111
115
}
112
116
117
+ void YACLib::ReleaseExecutor (std::size_t threads, detail::yb::TestExecutor* e) {
118
+ if (threads != 0 ) {
119
+ delete e;
120
+ }
121
+ }
122
+
113
123
void YACLib::NoContention (benchmark::State& state) {
114
124
state.PauseTiming ();
115
125
0 commit comments