Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduler of tests #5

Merged
merged 3 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/beman/lazy/detail/scheduler_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
#ifndef INCLUDED_INCLUDE_BEMAN_LAZY_DETAIL_SCHEDULER_OF
#define INCLUDED_INCLUDE_BEMAN_LAZY_DETAIL_SCHEDULER_OF

#include <beman/lazy/detail/any_scheduler.hpp>
#include <beman/execution26/execution.hpp>

// ----------------------------------------------------------------------------

namespace beman::lazy::detail {
/*!
* \brief Utility to get a scheduler type from a context
* \headerfile beman/lazy/lazy.hpp <beman/lazy/lazy.hpp>
* \internal
*/
template <typename>
struct scheduler_of {
using type = ::beman::lazy::detail::any_scheduler;
Expand All @@ -15,6 +23,8 @@ template <typename Context>
requires requires { typename Context::scheduler_type; }
struct scheduler_of<Context> {
using type = typename Context::scheduler_type;
static_assert(::beman::execution26::scheduler<type>,
"The type alias scheduler_type needs to refer to a scheduler");
};
template <typename Context>
using scheduler_of_t = typename scheduler_of<Context>::type;
Expand Down
10 changes: 9 additions & 1 deletion tests/beman/lazy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

list(APPEND lazy_tests any_scheduler inline_scheduler lazy poly)
list(
APPEND
lazy_tests
any_scheduler
inline_scheduler
lazy
poly
scheduler_of
)

foreach(test ${lazy_tests})
add_executable(beman.lazy.tests.${test})
Expand Down
3 changes: 0 additions & 3 deletions tests/beman/lazy/any_scheduler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct thread_context {
virtual void complete() = 0;
};

std::latch stop_done{1u};
std::mutex mutex;
std::condition_variable condition;
bool done{false};
Expand Down Expand Up @@ -60,7 +59,6 @@ struct thread_context {
while (auto w{this->get_work()}) {
w->complete();
}
this->stop_done.count_down();
}) {}
~thread_context() {
this->stop();
Expand Down Expand Up @@ -145,7 +143,6 @@ struct thread_context {
this->done = true;
}
this->condition.notify_one();
this->stop_done.wait();
}
};

Expand Down
33 changes: 33 additions & 0 deletions tests/beman/lazy/scheduler_of.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// tests/beman/lazy/scheduler_of.test.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/lazy/detail/scheduler_of.hpp>
#include <beman/lazy/detail/any_scheduler.hpp>
#include <beman/lazy/detail/inline_scheduler.hpp>
#include <concepts>
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <cassert>

// ----------------------------------------------------------------------------

namespace {
struct no_scheduler {};

struct defines_scheduler {
using scheduler_type = beman::lazy::detail::inline_scheduler;
};

struct non_scheduler {};
struct defines_non_scheduler {
using scheduler_type = non_scheduler;
};
} // namespace

int main() {
static_assert(std::same_as<beman::lazy::detail::any_scheduler, beman::lazy::detail::scheduler_of_t<no_scheduler>>);
static_assert(
std::same_as<beman::lazy::detail::inline_scheduler, beman::lazy::detail::scheduler_of_t<defines_scheduler>>);
// using type = beman::lazy::detail::scheduler_of_t<defines_non_scheduler>;
}
Loading