-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scheduler and timer should be separated (#124)
- Loading branch information
1 parent
a4d058c
commit 9597d6c
Showing
15 changed files
with
105 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#pragma once | ||
|
||
#include <type_traits> | ||
#include <cstddef> | ||
|
||
#include "forwards.hpp" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
|
||
#include <chrono> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include <actor-zeta.hpp> | ||
#include <actor-zeta/detail/memory_resource.hpp> | ||
#include "tooltestsuites/scheduler_test.hpp" | ||
#include "tooltestsuites/clock_test.hpp" | ||
|
||
static std::atomic<uint64_t> alarm_counter{0}; | ||
|
||
using actor_zeta::detail::pmr::memory_resource; | ||
/// non thread safe | ||
constexpr static auto alarm_id = actor_zeta::make_message_id(0); | ||
class supervisor_lite final : public actor_zeta::cooperative_supervisor<supervisor_lite> { | ||
public: | ||
explicit supervisor_lite(memory_resource* ptr) | ||
: cooperative_supervisor(ptr, "network") | ||
, executor_(new actor_zeta::test::scheduler_test_t(1, 1)) { | ||
add_handler(alarm_id, &supervisor_lite::alarm); | ||
scheduler()->start(); | ||
} | ||
|
||
auto clock() noexcept -> actor_zeta::test::clock_test& { | ||
return executor_->clock(); | ||
} | ||
|
||
~supervisor_lite() override = default; | ||
|
||
void alarm() { | ||
alarm_counter += 1; | ||
} | ||
|
||
protected: | ||
auto scheduler_impl() noexcept -> actor_zeta::scheduler_abstract_t* final { return executor_.get(); } | ||
auto enqueue_impl(actor_zeta::message_ptr msg, actor_zeta::execution_unit*) -> void final { | ||
{ | ||
set_current_message(std::move(msg)); | ||
execute(this, current_message()); | ||
} | ||
} | ||
|
||
private: | ||
std::unique_ptr<actor_zeta::test::scheduler_test_t> executor_; | ||
std::vector<actor_zeta::actor> actors_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,16 @@ | ||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file | ||
#include <catch2/catch.hpp> | ||
|
||
#include <cassert> | ||
|
||
#include <chrono> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include <actor-zeta.hpp> | ||
#include <actor-zeta/detail/memory_resource.hpp> | ||
|
||
#include "classes.hpp" | ||
#include "tooltestsuites/scheduler_test.hpp" | ||
|
||
static std::atomic<uint64_t> alarm_counter{0}; | ||
|
||
using actor_zeta::detail::pmr::memory_resource; | ||
/// non thread safe | ||
constexpr static auto alarm_id = actor_zeta::make_message_id(0); | ||
class supervisor_lite final : public actor_zeta::cooperative_supervisor<supervisor_lite> { | ||
public: | ||
explicit supervisor_lite(memory_resource* ptr) | ||
: cooperative_supervisor(ptr, "network") | ||
, executor_(new actor_zeta::test::scheduler_test_t(1, 1)) { | ||
add_handler(alarm_id, &supervisor_lite::alarm); | ||
scheduler()->start(); | ||
} | ||
|
||
auto scheduler_test() noexcept -> actor_zeta::test::scheduler_test_t* { | ||
return executor_.get(); | ||
} | ||
|
||
~supervisor_lite() override = default; | ||
|
||
void alarm() { | ||
alarm_counter += 1; | ||
} | ||
|
||
protected: | ||
auto scheduler_impl() noexcept -> actor_zeta::scheduler_abstract_t* final { return executor_.get(); } | ||
auto enqueue_impl(actor_zeta::message_ptr msg, actor_zeta::execution_unit*) -> void final { | ||
{ | ||
set_current_message(std::move(msg)); | ||
execute(this,current_message()); | ||
} | ||
} | ||
|
||
private: | ||
std::unique_ptr<actor_zeta::test::scheduler_test_t> executor_; | ||
std::vector<actor_zeta::actor> actors_; | ||
}; | ||
|
||
TEST_CASE("timer") { | ||
auto* mr_ptr = actor_zeta::detail::pmr::get_default_resource(); | ||
auto supervisor = actor_zeta::spawn_supervisor<supervisor_lite>(mr_ptr); | ||
|
||
auto time = supervisor->clock().now() + std::chrono::seconds(10); | ||
supervisor->clock().schedule_message(time, supervisor->address(), actor_zeta::make_message(actor_zeta::address_t::empty_address(), alarm_id)); | ||
supervisor->scheduler_test()->advance_time(std::chrono::seconds(10)); | ||
auto& clock = supervisor->clock(); | ||
auto time = clock.now() + std::chrono::seconds(10); | ||
clock.schedule_message(time, supervisor->address(), actor_zeta::make_message(actor_zeta::address_t::empty_address(), alarm_id)); | ||
supervisor->clock().advance_time(std::chrono::seconds(10)); | ||
|
||
REQUIRE(alarm_counter.load() == 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters