diff --git a/src/rt/CMakeLists.txt b/src/rt/CMakeLists.txt index a7845d25..d0933010 100644 --- a/src/rt/CMakeLists.txt +++ b/src/rt/CMakeLists.txt @@ -75,6 +75,6 @@ endif() target_compile_definitions(verona_rt INTERFACE -DSNMALLOC_CHEAP_CHECKS) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) warnings_high() diff --git a/src/rt/cpp/coro.h b/src/rt/cpp/coro.h new file mode 100644 index 00000000..e662a5e2 --- /dev/null +++ b/src/rt/cpp/coro.h @@ -0,0 +1,102 @@ +// Copyright Microsoft and Project Verona Contributors. +// SPDX-License-Identifier: MIT +#pragma once + +#include + +#ifdef COROUTINES +# ifdef EXPERIMENTAL_CORO +# include +# else +# include +# endif +#endif + +#include "../sched/behaviour.h" + +namespace verona::cpp +{ +#ifndef COROUTINES + struct coroutine + {}; +#else + +# ifdef EXPERIMENTAL_CORO + using namespace std::experimental; +# else + using namespace std; +# endif + + struct coroutine + { + struct promise_type; + using handle_type = coroutine_handle; + + struct promise_type + { + coroutine get_return_object() + { + return {handle_type::from_promise(*this)}; + } + suspend_always initial_suspend() noexcept + { + return {}; + } + suspend_always final_suspend() noexcept + { + return {}; + } + void unhandled_exception() {} + void return_void() {} + }; + + handle_type h_; + bool initialized = false; + + coroutine(handle_type h) : h_(h), initialized(true) {} + coroutine() : h_(nullptr), initialized(false) {} + + void resume() + { + h_.resume(); + } + + bool done() const + { + return h_.done(); + } + + void destroy() + { + h_.destroy(); + } + }; + + template + auto prepare_coro_lambda(F&& f) + { + coroutine coro_state; + + auto coro_f = [f = std::move(f), + coro_state = std::move(coro_state)](auto... args) mutable { + if (coro_state.initialized == false) + { + coro_state = std::move(f(args...)); + } + + coro_state.resume(); + + if (!(coro_state.done())) + { + verona::rt::Behaviour::behaviour_rerun() = true; + } + else + { + coro_state.destroy(); + } + }; + + return coro_f; + } +#endif +} // namespace verona::cpp diff --git a/src/rt/cpp/when.h b/src/rt/cpp/when.h index d6329c67..e385c8b7 100644 --- a/src/rt/cpp/when.h +++ b/src/rt/cpp/when.h @@ -3,6 +3,7 @@ #pragma once #include "../sched/behaviour.h" +#include "coro.h" #include "cown.h" #include "cown_array.h" @@ -30,6 +31,7 @@ namespace verona::cpp class Access { using Type = T; + ActualCown>* t; bool is_move; @@ -58,6 +60,7 @@ namespace verona::cpp class AccessBatch { using Type = T; + ActualCown>** act_array; acquired_cown* acq_array; size_t arr_len; @@ -385,16 +388,17 @@ namespace verona::cpp size_t count = array_assign(r); + /// Effectively converts ActualCown... to + /// acquired_cown... . + auto lift_f = [f = std::move(f)](Args... args) mutable { + std::move(f)(access_to_acquired(args)...); + }; + return std::make_tuple( count, r, - [f = std::move(f), cown_tuple = std::move(cown_tuple)]() mutable { - /// Effectively converts ActualCown... to - /// acquired_cown... . - auto lift_f = [f = std::move(f)](Args... args) mutable { - std::move(f)(access_to_acquired(args)...); - }; - + [lift_f = std::move(lift_f), + cown_tuple = std::move(cown_tuple)]() mutable { std::apply(std::move(lift_f), std::move(cown_tuple)); }); } @@ -466,22 +470,70 @@ namespace verona::cpp PreWhen(Args... args) : cown_tuple(std::move(args)...) {} + template + struct return_coroutine_t + : public return_coroutine_t + {}; + + template + struct return_coroutine_t + { + static constexpr bool value = true; + }; + + template + struct return_coroutine_t + { + static constexpr bool value = false; + }; + + template + struct return_coroutine_t + { + static constexpr bool value = true; + }; + + template + struct return_coroutine_t + { + static constexpr bool value = false; + }; + public: template auto operator<<(F&& f) { Scheduler::stats().behaviour(sizeof...(Args)); - if constexpr (sizeof...(Args) == 0) + if constexpr (return_coroutine_t::value) { - // Execute now atomic batch makes no sense. - verona::rt::schedule_lambda(std::forward(f)); - return Batch(std::make_tuple()); + auto coro_f = prepare_coro_lambda(f); + + if constexpr (sizeof...(Args) == 0) + { + // Execute now atomic batch makes no sense. + verona::rt::schedule_lambda(std::forward(coro_f)); + return Batch(std::make_tuple()); + } + else + { + return Batch(std::make_tuple(When( + std::forward(coro_f), std::move(cown_tuple)))); + } } else { - return Batch( - std::make_tuple(When(std::forward(f), std::move(cown_tuple)))); + if constexpr (sizeof...(Args) == 0) + { + // Execute now atomic batch makes no sense. + verona::rt::schedule_lambda(std::forward(f)); + return Batch(std::make_tuple()); + } + else + { + return Batch( + std::make_tuple(When(std::forward(f), std::move(cown_tuple)))); + } } } }; diff --git a/src/rt/sched/behaviour.h b/src/rt/sched/behaviour.h index d4e0ea8b..56e1ac15 100644 --- a/src/rt/sched/behaviour.h +++ b/src/rt/sched/behaviour.h @@ -24,6 +24,7 @@ namespace verona::rt { behaviour_rerun() = false; Scheduler::schedule(work); + Scheduler::local()->return_next_work(); return; } diff --git a/src/rt/sched/schedulerthread.h b/src/rt/sched/schedulerthread.h index 05f5d804..0b12f30b 100644 --- a/src/rt/sched/schedulerthread.h +++ b/src/rt/sched/schedulerthread.h @@ -54,6 +54,7 @@ namespace verona::rt friend class ThreadSync; LocalSync local_sync{}; #endif + friend class Behaviour; Alloc* alloc = nullptr; Core* victim = nullptr; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index aed74152..d3142896 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,6 +54,19 @@ foreach(TEST_MODE "sys" "con") target_compile_definitions(${TESTNAME} PRIVATE USE_FLIGHT_RECORDER) endif () endif () + if (${TEST} STREQUAL "coro") + target_compile_definitions(${TESTNAME} PRIVATE COROUTINES) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_definitions(${TESTNAME} PRIVATE EXPERIMENTAL_CORO) + target_compile_options(${TESTNAME} PRIVATE -stdlib=libc++ -fcoroutines-ts) + target_link_libraries(${TESTNAME} -lc++) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${TESTNAME} PRIVATE -fcoroutines) + elseif (MSVC) + target_compile_definitions(${TESTNAME} PRIVATE EXPERIMENTAL_CORO) + target_compile_options(${TESTNAME} PRIVATE /await) + endif() + endif () if (${TEST} STREQUAL "runtimepause") # This example uses external non-determinism. So add FLIGHT_RECORDER for CI crashes if (VERONA_CI_BUILD) diff --git a/test/func/atomic-sched/atomic-sched.cc b/test/func/atomic-sched/atomic-sched.cc index f462118f..834107dc 100644 --- a/test/func/atomic-sched/atomic-sched.cc +++ b/test/func/atomic-sched/atomic-sched.cc @@ -23,14 +23,14 @@ void test_body() auto log2 = make_cown(); (when(log) << - [=](auto b) { + [=](acquired_cown) { for (int i = 0; i < 10; i++) { Logging::cout() << "Behaviour 1\n"; // sleep(1); } }) + - (when(log2) << [=](auto) { + (when(log2) << [=](acquired_cown) { for (int i = 0; i < 10; i++) { Logging::cout() << "Behaviour 2\n"; @@ -46,13 +46,13 @@ void test_body_same() auto log = make_cown(); (when(log) << - [=](auto b) { + [=](acquired_cown b) { for (int i = 0; i < 10; i++) { Logging::cout() << "Behaviour 1" << Logging::endl; } }) + - (when(log) << [=](auto) { + (when(log) << [=](acquired_cown) { for (int i = 0; i < 10; i++) { Logging::cout() << "Behaviour 2" << Logging::endl; @@ -69,7 +69,7 @@ void test_body_smart() auto ptr = std::make_unique(42); (when(log) << - [=, ptr = std::move(ptr)](auto b) { + [=, ptr = std::move(ptr)](acquired_cown b) { std::cout << "ptr = " << *ptr << std::endl; for (int i = 0; i < 10; i++) { @@ -77,7 +77,7 @@ void test_body_smart() // sleep(1); } }) + - (when(log2) << [=](auto) { + (when(log2) << [=](acquired_cown) { for (int i = 0; i < 10; i++) { Logging::cout() << "Behaviour 2\n"; diff --git a/test/func/backpressure/deadlock.h b/test/func/backpressure/deadlock.h index 624ac402..591c393f 100644 --- a/test/func/backpressure/deadlock.h +++ b/test/func/backpressure/deadlock.h @@ -59,10 +59,14 @@ namespace backpressure_deadlock auto c3 = make_cown(); for (size_t i = 0; i < 100; i++) - when(c1) << [](auto) {}; + when(c1) << [](acquired_cown) {}; - when(c3) << [c1](auto) { when(c1) << [](auto) {}; }; - when(c2) << [c2, c3](auto) { when(c2, c3) << [](auto, auto) {}; }; - when(c1) << [c1, c2](auto) { when(c1, c2) << [](auto, auto) {}; }; + when(c3) << [c1](acquired_cown) { when(c1) << [](acquired_cown) {}; }; + when(c2) << [c2, c3](acquired_cown) { + when(c2, c3) << [](acquired_cown, acquired_cown) {}; + }; + when(c1) << [c1, c2](acquired_cown) { + when(c1, c2) << [](acquired_cown, acquired_cown) {}; + }; } } diff --git a/test/func/backpressure/unblock.h b/test/func/backpressure/unblock.h index 5da40896..2cefad04 100644 --- a/test/func/backpressure/unblock.h +++ b/test/func/backpressure/unblock.h @@ -53,7 +53,9 @@ namespace backpressure_unblock while (i > 0) { i--; - when(sender) << [receiver](auto) { when(receiver) << [](auto) {}; }; + when(sender) << [receiver](acquired_cown) { + when(receiver) << [](acquired_cown) {}; + }; } }; } @@ -67,6 +69,6 @@ namespace backpressure_unblock overload(sender1, receiver1); overload(sender2, receiver2); - when(sender1, receiver2) << [](auto, auto) {}; + when(sender1, receiver2) << [](acquired_cown, acquired_cown) {}; } } diff --git a/test/func/coro/coro.cc b/test/func/coro/coro.cc new file mode 100644 index 00000000..ea0fbc3b --- /dev/null +++ b/test/func/coro/coro.cc @@ -0,0 +1,55 @@ +// Copyright Microsoft and Project Verona Contributors. +// SPDX-License-Identifier: MIT +// Copyright Microsoft and Project Verona Contributors. +// SPDX-License-Identifier: MIT + +#include +#include +#include + +using namespace verona::cpp; + +class Body +{ +public: + int counter; + + ~Body() + { + Logging::cout() << "Body destroyed" << Logging::endl; + } +}; + +void test_body() +{ + Logging::cout() << "test_body()" << Logging::endl; + + auto log1 = make_cown(); + + when() << []() { std::cout << "in between\n"; }; + + when(log1) << [=](acquired_cown& acq) mutable -> coroutine { + std::cout << "counter = " << acq->counter << std::endl; + int local_counter = 0; + + acq->counter++; + local_counter++; + // Yield the execution + co_await suspend_always{}; + + std::cout << "counter = " << acq->counter << std::endl; + std::cout << "local counter = " << local_counter << std::endl; + std::cout << "end" << std::endl; + }; +} + +int main(int argc, char** argv) +{ + SystematicTestHarness harness(argc, argv); + + Logging::cout() << "Yield test" << Logging::endl; + + harness.run(test_body); + + return 0; +} diff --git a/test/func/dynamic-cownset/dynamic-cownset.cc b/test/func/dynamic-cownset/dynamic-cownset.cc index 1bcab55f..86917bc9 100644 --- a/test/func/dynamic-cownset/dynamic-cownset.cc +++ b/test/func/dynamic-cownset/dynamic-cownset.cc @@ -5,27 +5,15 @@ #include #include -class Body1 +class Body { public: int val; - Body1(int val_) : val(val_) {} + Body(int val_) : val(val_) {} - ~Body1() + ~Body() { - Logging::cout() << "Body1 destroyed" << Logging::endl; - } -}; - -class Body2 -{ -public: - int val; - Body2(int val_) : val(val_) {} - - ~Body2() - { - Logging::cout() << "Body2 destroyed" << Logging::endl; + Logging::cout() << "Body destroyed" << Logging::endl; } }; @@ -35,80 +23,87 @@ void test_span() { Logging::cout() << "test_span()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - when(t1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(t1) << [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } void test_span_empty() { Logging::cout() << "test_span_empty()" << Logging::endl; - cown_array t1{nullptr, 0}; + cown_array t1{nullptr, 0}; - when(t1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(t1) << [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } void test_span_single() { Logging::cout() << "test_span_single()" << Logging::endl; - auto log1 = make_cown(1); + auto log1 = make_cown(1); - cown_array t1{&log1, 1}; + cown_array t1{&log1, 1}; - when(t1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(t1) << [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } void test_multi_span() { Logging::cout() << "test_multi_span()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray1[2]; + cown_ptr carray1[2]; carray1[0] = log1; carray1[1] = log2; - cown_array t1{carray1, 2}; + cown_array t1{carray1, 2}; - auto log3 = make_cown(3); - auto log4 = make_cown(4); + auto log3 = make_cown(3); + auto log4 = make_cown(4); - cown_ptr carray2[2]; + cown_ptr carray2[2]; carray2[0] = log3; carray2[1] = log4; - cown_array t2{carray2, 2}; + cown_array t2{carray2, 2}; - when(t1, t2) << - [=](auto, auto) { Logging::cout() << "log" << Logging::endl; }; + when(t1, t2) << [=](acquired_cown_span, acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } void test_mixed1() { Logging::cout() << "test_mixed1()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - auto log3 = make_cown(1); + auto log3 = make_cown(1); - when(t1, log3) << [=](acquired_cown_span ca, acquired_cown a) { + when(t1, log3) << [=](acquired_cown_span ca, acquired_cown a) { Logging::cout() << "log" << Logging::endl; }; } @@ -117,18 +112,18 @@ void test_mixed2() { Logging::cout() << "test_mixed2()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - auto log3 = make_cown(1); + auto log3 = make_cown(1); - when(log3, t1) << [=](acquired_cown, acquired_cown_span ca) { + when(log3, t1) << [=](acquired_cown, acquired_cown_span ca) { Logging::cout() << "log" << Logging::endl; }; } @@ -137,82 +132,92 @@ void test_mixed3() { Logging::cout() << "test_mixed3()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray1[2]; + cown_ptr carray1[2]; carray1[0] = log1; carray1[1] = log2; - cown_array t1{carray1, 2}; + cown_array t1{carray1, 2}; - auto log3 = make_cown(3); - auto log4 = make_cown(4); + auto log3 = make_cown(3); + auto log4 = make_cown(4); - cown_ptr carray2[2]; + cown_ptr carray2[2]; carray2[0] = log3; carray2[1] = log4; - cown_array t2{carray2, 2}; + cown_array t2{carray2, 2}; - auto log5 = make_cown(4); + auto log5 = make_cown(4); when(t1, log5, t2) << - [=](auto, auto, auto) { Logging::cout() << "log" << Logging::endl; }; + [=]( + acquired_cown_span, acquired_cown, acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } void test_mixed4() { Logging::cout() << "test_mixed4()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray1[2]; + cown_ptr carray1[2]; carray1[0] = log1; carray1[1] = log2; - cown_array t1{carray1, 2}; + cown_array t1{carray1, 2}; - auto log3 = make_cown(3); - auto log4 = make_cown(4); + auto log3 = make_cown(3); + auto log4 = make_cown(4); when(log3, t1, log4) << - [=](auto, auto, auto) { Logging::cout() << "log" << Logging::endl; }; + [=](acquired_cown, acquired_cown_span, acquired_cown) { + Logging::cout() << "log" << Logging::endl; + }; } void test_multi() { Logging::cout() << "test_multi()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - (when(t1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) + - (when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }); + (when(t1) << + [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }) + + (when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_nest1() { Logging::cout() << "test_nest1()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - when(t1) << [=](auto) { - when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(t1) << [=](acquired_cown_span) { + when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; }; } @@ -220,17 +225,19 @@ void test_nest2() { Logging::cout() << "test_nest2()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1(carray, 2); + cown_array t1(carray, 2); - when(log1) << [=](auto) { - when(t1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(log1) << [=](acquired_cown) { + when(t1) << [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; }; } @@ -238,17 +245,18 @@ void test_move() { Logging::cout() << "test_span()" << Logging::endl; - auto log1 = make_cown(1); - auto log2 = make_cown(2); + auto log1 = make_cown(1); + auto log2 = make_cown(2); - cown_ptr carray[2]; + cown_ptr carray[2]; carray[0] = log1; carray[1] = log2; - cown_array t1{carray, 2}; + cown_array t1{carray, 2}; - when(std::move(t1)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(std::move(t1)) << [=](acquired_cown_span) { + Logging::cout() << "log" << Logging::endl; + }; } int main(int argc, char** argv) diff --git a/test/func/fair/fair.cc b/test/func/fair/fair.cc index d87395c2..6b51eb68 100644 --- a/test/func/fair/fair.cc +++ b/test/func/fair/fair.cc @@ -20,7 +20,7 @@ struct A void loop(cown_ptr c) { - when(c) << [c = std::move(c)](auto a) { + when(c) << [c = std::move(c)](acquired_cown a) { auto& count = a->count; if (count == 0) diff --git a/test/func/fair_variance/fair_variance.cc b/test/func/fair_variance/fair_variance.cc index 98bee4fe..3a31ec83 100644 --- a/test/func/fair_variance/fair_variance.cc +++ b/test/func/fair_variance/fair_variance.cc @@ -25,7 +25,7 @@ double elapsed_secs[n_cowns]; void loop(cown_ptr c) { - when(c) << [c = std::move(c)](auto a) { + when(c) << [c = std::move(c)](acquired_cown a) { auto& count = a->count; auto id = a->id; diff --git a/test/func/multimessage/multimessage.cc b/test/func/multimessage/multimessage.cc index 48bed47c..95abbcd4 100644 --- a/test/func/multimessage/multimessage.cc +++ b/test/func/multimessage/multimessage.cc @@ -30,14 +30,14 @@ void test_multimessage(size_t cores) { auto a1 = make_cown(3); - when(a1) << [](auto a) { + when(a1) << [](acquired_cown a) { Logging::cout() << "got message on " << a.cown() << Logging::endl; }; auto a2 = make_cown(5); // We are transfering our cown references to the message here. - when(a1, a2) << [](auto a, auto b) { + when(a1, a2) << [](acquired_cown a, acquired_cown b) { Logging::cout() << "result = " << (a->i + b->i) << Logging::endl; }; } diff --git a/test/func/simp1/simp1.cc b/test/func/simp1/simp1.cc index dae5a7b6..7e2b5b02 100644 --- a/test/func/simp1/simp1.cc +++ b/test/func/simp1/simp1.cc @@ -21,7 +21,8 @@ void test_body() auto log = make_cown(); - when(log) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(log) << + [=](acquired_cown a) { Logging::cout() << "log" << Logging::endl; }; } int main(int argc, char** argv) diff --git a/test/func/simp2/simp2.cc b/test/func/simp2/simp2.cc index e396a0b8..1d011829 100644 --- a/test/func/simp2/simp2.cc +++ b/test/func/simp2/simp2.cc @@ -22,8 +22,9 @@ void test_body() auto log1 = make_cown(); auto log2 = make_cown(); - when(log1, log2) << - [=](auto, auto) { Logging::cout() << "log" << Logging::endl; }; + when(log1, log2) << [=](acquired_cown b1, acquired_cown b2) { + Logging::cout() << "log" << Logging::endl; + }; } int main(int argc, char** argv) diff --git a/test/func/simp3/simp3.cc b/test/func/simp3/simp3.cc index 54602152..43ab6e61 100644 --- a/test/func/simp3/simp3.cc +++ b/test/func/simp3/simp3.cc @@ -21,8 +21,10 @@ void test_body() auto log1 = make_cown(); - when(log1) << [](auto) { Logging::cout() << "log" << Logging::endl; }; - when(log1) << [](auto) { Logging::cout() << "log" << Logging::endl; }; + when(log1) << + [](acquired_cown b) { Logging::cout() << "log" << Logging::endl; }; + when(log1) << + [](acquired_cown b) { Logging::cout() << "log" << Logging::endl; }; } int main(int argc, char** argv) diff --git a/test/func/simp4/simp4.cc b/test/func/simp4/simp4.cc index 3ca63905..511cb703 100644 --- a/test/func/simp4/simp4.cc +++ b/test/func/simp4/simp4.cc @@ -21,9 +21,10 @@ void test_body() auto log1 = make_cown(); - when(log1) << [](auto l) { + when(log1) << [](acquired_cown l) { Logging::cout() << "log" << Logging::endl; - when(l.cown()) << [](auto) { Logging::cout() << "log" << Logging::endl; }; + when(l.cown()) << + [](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; }; } diff --git a/test/func/simp5/simp5.cc b/test/func/simp5/simp5.cc index b6311a95..3be29413 100644 --- a/test/func/simp5/simp5.cc +++ b/test/func/simp5/simp5.cc @@ -23,12 +23,15 @@ void test_body() auto log2 = make_cown(); auto log3 = make_cown(); - when(log1, log2) << - [=](auto, auto) { Logging::cout() << "log1" << Logging::endl; }; - when(log2, log3) << - [=](auto, auto) { Logging::cout() << "log2" << Logging::endl; }; - when(log1, log3) << - [=](auto, auto) { Logging::cout() << "log3" << Logging::endl; }; + when(log1, log2) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log1" << Logging::endl; + }; + when(log2, log3) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log2" << Logging::endl; + }; + when(log1, log3) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log3" << Logging::endl; + }; } int main(int argc, char** argv) diff --git a/test/func/simp6/simp6.cc b/test/func/simp6/simp6.cc index a0bf6e97..3dfe7d01 100644 --- a/test/func/simp6/simp6.cc +++ b/test/func/simp6/simp6.cc @@ -24,14 +24,18 @@ void test_body() auto log3 = make_cown(); auto log4 = make_cown(); - when(log1, log2) << - [=](auto, auto) { Logging::cout() << "log1" << Logging::endl; }; - when(log3, log4) << - [=](auto, auto) { Logging::cout() << "log2" << Logging::endl; }; - when(log2, log3) << - [=](auto, auto) { Logging::cout() << "log3" << Logging::endl; }; - when(log4, log1) << - [=](auto, auto) { Logging::cout() << "log4" << Logging::endl; }; + when(log1, log2) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log1" << Logging::endl; + }; + when(log3, log4) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log2" << Logging::endl; + }; + when(log2, log3) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log3" << Logging::endl; + }; + when(log4, log1) << [=](acquired_cown, acquired_cown) { + Logging::cout() << "log4" << Logging::endl; + }; } int main(int argc, char** argv) diff --git a/test/func/simp_weak1/simp_weak1.cc b/test/func/simp_weak1/simp_weak1.cc index a2c311a2..b1f8ac0e 100644 --- a/test/func/simp_weak1/simp_weak1.cc +++ b/test/func/simp_weak1/simp_weak1.cc @@ -27,7 +27,7 @@ void test_body() auto log = make_cown(); - when(log) << [=](auto log) { + when(log) << [=](acquired_cown log) { // Create a self reference, this should not prevent the body from // being destroyed. log->self = log.cown(); diff --git a/test/func/steal/steal.cc b/test/func/steal/steal.cc index f8e7e6c5..f7c022ee 100644 --- a/test/func/steal/steal.cc +++ b/test/func/steal/steal.cc @@ -18,7 +18,7 @@ void schedule_run(size_t decay) auto& alloc = ThreadAlloc::get(); auto runner = make_cown(); - when(runner) << [decay](auto) { schedule_run(decay - 1); }; + when(runner) << [decay](acquired_cown) { schedule_run(decay - 1); }; } void basic_test(size_t cores) diff --git a/test/func/weak_leak_bug/weak_leak_bug.cc b/test/func/weak_leak_bug/weak_leak_bug.cc index bb5e9914..f1f535ff 100644 --- a/test/func/weak_leak_bug/weak_leak_bug.cc +++ b/test/func/weak_leak_bug/weak_leak_bug.cc @@ -31,8 +31,9 @@ void run_test() // HERE: the weak RC is never released. weak_leak = t.get_weak(); - when(t) << - [](auto t) { Logging::cout() << "Msg on " << t.cown() << std::endl; }; + when(t) << [](acquired_cown t) { + Logging::cout() << "Msg on " << t.cown() << std::endl; + }; } int main(int argc, char** argv) diff --git a/test/func/when-transfer/transfer.cc b/test/func/when-transfer/transfer.cc index 42749659..07daacda 100644 --- a/test/func/when-transfer/transfer.cc +++ b/test/func/when-transfer/transfer.cc @@ -22,7 +22,7 @@ void test_body_move() auto log = make_cown(); when(std::move(log)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }; + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; } void test_body_move_busy() @@ -31,9 +31,10 @@ void test_body_move_busy() auto log = make_cown(); - when(log) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(log) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; when(std::move(log)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }; + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; } void test_sched_many_no_move() @@ -43,8 +44,10 @@ void test_sched_many_no_move() auto log1 = make_cown(); auto log2 = cown_ptr(log1); - (when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) + - (when(log2) << [=](auto) { Logging::cout() << "log" << Logging::endl; }); + (when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + + (when(log2) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_sched_many_no_move_busy() @@ -54,9 +57,12 @@ void test_sched_many_no_move_busy() auto log1 = make_cown(); auto log2 = cown_ptr(log1); - when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; - (when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) + - (when(log2) << [=](auto) { Logging::cout() << "log" << Logging::endl; }); + when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; + (when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + + (when(log2) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_sched_many_move() @@ -67,9 +73,9 @@ void test_sched_many_move() auto log2 = cown_ptr(log1); (when(std::move(log1)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }) + + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + (when(std::move(log2)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }); + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_sched_many_move_busy() @@ -79,11 +85,12 @@ void test_sched_many_move_busy() auto log1 = make_cown(); auto log2 = cown_ptr(log1); - when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; + when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; (when(std::move(log1)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }) + + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + (when(std::move(log2)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }); + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_sched_many_mixed() @@ -93,9 +100,10 @@ void test_sched_many_mixed() auto log1 = make_cown(); auto log2 = cown_ptr(log1); - (when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) + + (when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + (when(std::move(log2)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }); + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } void test_sched_many_mixed_busy() @@ -105,10 +113,12 @@ void test_sched_many_mixed_busy() auto log1 = make_cown(); auto log2 = cown_ptr(log1); - when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }; - (when(log1) << [=](auto) { Logging::cout() << "log" << Logging::endl; }) + + when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }; + (when(log1) << + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }) + (when(std::move(log2)) << - [=](auto) { Logging::cout() << "log" << Logging::endl; }); + [=](acquired_cown) { Logging::cout() << "log" << Logging::endl; }); } int main(int argc, char** argv) diff --git a/test/func/yield/yield.cc b/test/func/yield/yield.cc index bfd64c98..55a19519 100644 --- a/test/func/yield/yield.cc +++ b/test/func/yield/yield.cc @@ -39,7 +39,7 @@ void test_state_machine() Logging::cout() << "Yield state machine test" << Logging::endl; auto state_cown = make_cown(); - when(state_cown) << [](auto state) { + when(state_cown) << [](acquired_cown state) { switch (state->s) { case ObjectWithState::StateA: @@ -65,7 +65,7 @@ void test_counter() auto counter_cown = make_cown(); - when(counter_cown) << [](auto counter) { + when(counter_cown) << [](acquired_cown counter) { // Ensure that the next behaviour does not run assert(counter->c % 2 == 0); while (counter->c < 10) @@ -77,7 +77,7 @@ void test_counter() } }; - when(counter_cown) << [](auto counter) { + when(counter_cown) << [](acquired_cown counter) { assert(counter->c == 10); Logging::cout() << "Incrementing counter by 1" << Logging::endl; counter->c++; diff --git a/test/perf/backpressure1/backpressure1.cc b/test/perf/backpressure1/backpressure1.cc index 05055552..3f4e5fec 100644 --- a/test/perf/backpressure1/backpressure1.cc +++ b/test/perf/backpressure1/backpressure1.cc @@ -167,7 +167,7 @@ int main(int argc, char** argv) proxy_chain.push_back(new (alloc) Proxy(p)); auto e = make_cown(); - when(e) << [](auto) { + when(e) << [](acquired_cown) { Logging::cout() << "Add external event source" << std::endl; Scheduler::add_external_event_source(); }; @@ -199,7 +199,7 @@ int main(int argc, char** argv) Cown::release(alloc, r); } - when(e) << [](auto) { + when(e) << [](acquired_cown) { Logging::cout() << "Remove external event source" << std::endl; Scheduler::remove_external_event_source(); }; diff --git a/test/perf/banking/verona_banks.cc b/test/perf/banking/verona_banks.cc index cea3df02..941e2615 100644 --- a/test/perf/banking/verona_banks.cc +++ b/test/perf/banking/verona_banks.cc @@ -57,7 +57,9 @@ struct Log void log(cown_ptr> log, std::string) { - when(log) << [=](auto) { /*std::cout << msg << std::endl;*/ }; + when(log) << + [=](acquired_cown< + std::unique_ptr>) { /*std::cout << msg << std::endl;*/ }; } void bank_job(