From 4c626a8654186cc166c9aa83de3adc965f7f3533 Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Mon, 30 Mar 2020 12:15:13 +0200 Subject: [PATCH] Add high level bindings for spawn/sync. --- lib/pls/include/pls/pls.h | 4 ++-- test/patterns_test.cpp | 23 +++++++++++++++++++++++ test/scheduling_tests.cpp | 4 +--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/pls/include/pls/pls.h b/lib/pls/include/pls/pls.h index b766dfe..c38f5d6 100644 --- a/lib/pls/include/pls/pls.h +++ b/lib/pls/include/pls/pls.h @@ -13,10 +13,10 @@ namespace pls { // 'basic' for-join APIs using internal::scheduling::scheduler; template -void spawn(Function &&function) { +static void spawn(Function &&function) { scheduler::spawn(std::forward(function)); } -void sync() { +static void sync() { scheduler::sync(); } diff --git a/test/patterns_test.cpp b/test/patterns_test.cpp index 3726626..0fddc82 100644 --- a/test/patterns_test.cpp +++ b/test/patterns_test.cpp @@ -7,6 +7,29 @@ constexpr int MAX_NUM_TASKS = 32; constexpr int MAX_STACK_SIZE = 1024 * 8; +TEST_CASE("spawn/sync invoke calls correctly", "[algorithms/invoke.h]") { + pls::scheduler scheduler{3, MAX_NUM_TASKS, MAX_STACK_SIZE}; + + std::atomic num_run{0}; + scheduler.perform_work([&] { + pls::spawn([&] { + num_run++; + while (num_run < 3); + }); + pls::spawn([&] { + while (num_run < 1); + num_run++; + while (num_run < 3); + }); + pls::spawn([&] { + while (num_run < 2); + num_run++; + }); + pls::sync(); + REQUIRE(num_run == 3); + }); +} + TEST_CASE("parallel invoke calls correctly", "[algorithms/invoke.h]") { pls::scheduler scheduler{3, MAX_NUM_TASKS, MAX_STACK_SIZE}; diff --git a/test/scheduling_tests.cpp b/test/scheduling_tests.cpp index 442fa17..826bdf5 100644 --- a/test/scheduling_tests.cpp +++ b/test/scheduling_tests.cpp @@ -1,12 +1,10 @@ #include -#include #include #include "pls/internal/scheduling/traded_cas_field.h" -#include "pls/internal/scheduling/task.h" #include "pls/internal/scheduling/external_trading_deque.h" -#include "pls/internal/scheduling/scheduler.h" +#include "pls/pls.h" using namespace pls::internal::scheduling; -- libgit2 0.26.0