Skip to content

Commit 47ccacc

Browse files
committed
temp
1 parent 13367e4 commit 47ccacc

File tree

7 files changed

+51
-31
lines changed

7 files changed

+51
-31
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (BENCH_SOURCE_DIR STREQUAL BENCH_BINARY_DIR)
1111
endif ()
1212

1313
# Set variables
14-
set(CMAKE_CXX_STANDARD 17)
14+
set(CMAKE_CXX_STANDARD 20)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1616
set(CMAKE_CXX_EXTENSIONS OFF)
1717
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

future/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ if (YACLIB)
3737
GIT_REPOSITORY https://github.com/YACLib/YACLib.git
3838
GIT_TAG "${YACLIB}"
3939
)
40-
set(YACLIB_CXX_STANDARD 20)
4140
list(APPEND YACLIB_FLAGS "ATOMIC_EVENT")
4241
FetchContent_MakeAvailable(yaclib)
4342
link_libraries(yaclib)

future/bench/thens.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ template <typename Library>
88
void Then(benchmark::State& state) {
99
auto const count = state.range(0);
1010
auto const type = state.range(1);
11-
std::unique_ptr<typename Library::Executor> executor;
12-
if (type != 0) {
13-
executor = std::make_unique<typename Library::Executor>(1);
14-
}
11+
auto* executor = Library::AcquireExecutor(/*threads*/ static_cast<size_t>(type != 0));
1512
for (auto _ : state) {
16-
if (type == 0) {
17-
Library::SomeThens(nullptr, count, false);
18-
} else {
19-
Library::SomeThens(executor.get(), count, type == 2);
13+
Library::SomeThens(executor, count, type == 2);
14+
if (executor != nullptr) {
2015
executor->Restart();
2116
}
2217
}
18+
Library::ReleaseExecutor(/*threads*/ static_cast<size_t>(type != 0), executor);
2319
}
2420

2521
} // namespace bench

future/bind/folly/future.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,20 @@ void Folly::PromiseAndFuture() {
9797
std::ignore = std::move(f).get();
9898
}
9999

100-
void Folly::SomeThens(Executor* executor, size_t n, bool no_inline) {
100+
detail::fy::TestExecutor* Folly::AcquireExecutor(std::size_t threads) {
101+
if (threads != 0) {
102+
return new detail::fy::TestExecutor{threads};
103+
}
104+
return nullptr;
105+
}
106+
107+
void Folly::ReleaseExecutor(std::size_t threads, detail::fy::TestExecutor* e) {
108+
if (threads != 0) {
109+
delete e;
110+
}
111+
}
112+
113+
void Folly::SomeThens(detail::fy::TestExecutor* executor, size_t n, bool no_inline) {
101114
const bool is_executor = executor != nullptr;
102115
auto f = folly::makeFuture(42).via(executor);
103116
f = Thens(std::move(f), n, is_executor && no_inline);

future/bind/folly/future.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ struct Folly {
6565
static void CreateFuture();
6666
static void PromiseAndFuture();
6767

68-
using Executor = detail::fy::TestExecutor;
69-
static void SomeThens(Executor* executor, size_t n, bool no_inline);
68+
static detail::fy::TestExecutor* AcquireExecutor(std::size_t threads);
69+
static void SomeThens(detail::fy::TestExecutor* executor, size_t n, bool no_inline);
70+
static void ReleaseExecutor(std::size_t threads, detail::fy::TestExecutor* e);
7071

7172
template <typename T = folly::Unit>
7273
static void ComplexBenchmark();

future/bind/yaclib/future.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <bind/yaclib/intrusive_list.hpp>
33
#include <semaphore.hpp>
44
#include <yaclib/async/future.hpp>
5-
#include <yaclib/executor/inline.hpp>
5+
#include <yaclib/exe/inline.hpp>
66

77
#include <future>
88
#include <thread>
@@ -17,7 +17,7 @@ T Incr(yaclib::Result<T>&& r) {
1717
return std::move(r).Ok() + 1;
1818
}
1919

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) {
2121
for (std::size_t i = 0; i != n; ++i) {
2222
if (is_executor) {
2323
f = std::move(f).Then(Incr<int>);
@@ -38,11 +38,10 @@ TestExecutor::TestExecutor(std::size_t num_threads) {
3838
_workers.emplace_back([this] {
3939
std::unique_lock lock{_m};
4040
while (true) {
41-
while (!_tasks.Empty()) {
42-
auto& task = _tasks.PopFront();
41+
while (!_jobs.Empty()) {
42+
auto& job = _jobs.PopFront();
4343
lock.unlock();
44-
task.Call();
45-
task.DecRef();
44+
static_cast<yaclib::Job&>(job).Call();
4645
lock.lock();
4746
}
4847
if (_stop) {
@@ -79,14 +78,12 @@ yaclib::IExecutor::Type TestExecutor::Tag() const {
7978
return Type::Custom;
8079
}
8180

82-
bool TestExecutor::Submit(yaclib::ITask& task) noexcept {
83-
task.IncRef();
81+
void TestExecutor::Submit(yaclib::Job& job) noexcept {
8482
{
8583
std::lock_guard guard{_m};
86-
_tasks.PushBack(task);
84+
_jobs.PushBack(job);
8785
}
8886
_cv.notify_one();
89-
return true;
9087
}
9188

9289
} // namespace detail::yb
@@ -101,15 +98,28 @@ void YACLib::PromiseAndFuture() {
10198
std::ignore = std::move(f).Get().Ok();
10299
}
103100

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());
107111
f = Thens(std::move(f), n, is_executor && no_inline);
108112
f = Thens(std::move(f), 1, is_executor);
109113
f = Thens(std::move(f), n, is_executor && no_inline);
110114
Wait(f);
111115
}
112116

117+
void YACLib::ReleaseExecutor(std::size_t threads, detail::yb::TestExecutor* e) {
118+
if (threads != 0) {
119+
delete e;
120+
}
121+
}
122+
113123
void YACLib::NoContention(benchmark::State& state) {
114124
state.PauseTiming();
115125

future/bind/yaclib/future.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <yaclib/algo/when_any.hpp>
66
#include <yaclib/async/contract.hpp>
77
#include <yaclib/async/future.hpp>
8-
#include <yaclib/executor/inline.hpp>
8+
#include <yaclib/exe/inline.hpp>
99

1010
#include <condition_variable>
1111
#include <memory>
@@ -34,11 +34,11 @@ class TestExecutor final : public yaclib::IExecutor {
3434

3535
[[nodiscard]] Type Tag() const final;
3636

37-
bool Submit(yaclib::ITask& task) noexcept final;
37+
void Submit(yaclib::Job& job) noexcept final;
3838

3939
std::mutex _m;
4040
std::condition_variable _cv;
41-
List<yaclib::ITask> _tasks;
41+
List<yaclib::Job> _jobs;
4242
std::vector<std::thread> _workers;
4343
bool _stop = false;
4444
};
@@ -94,8 +94,9 @@ struct YACLib {
9494
static void CreateFuture();
9595
static void PromiseAndFuture();
9696

97-
using Executor = detail::yb::TestExecutor;
98-
static void SomeThens(Executor* executor, size_t n, bool no_inline);
97+
static detail::yb::TestExecutor* AcquireExecutor(std::size_t threads);
98+
static void SomeThens(detail::yb::TestExecutor* executor, size_t n, bool no_inline);
99+
static void ReleaseExecutor(std::size_t threads, detail::yb::TestExecutor* e);
99100

100101
template <typename T = void>
101102
static void ComplexBenchmark();

0 commit comments

Comments
 (0)