diff --git a/fortuna.cpp b/fortuna.cpp index 8b27996..6f301a2 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace fortuna { static constexpr const unsigned int min_pool_size{64}; @@ -31,12 +32,20 @@ Fortuna::Fortuna() { fmt::print(stderr, "{}\n", e.what()); // perhaps die on error } + + + static constexpr const std::chrono::milliseconds duration{150}; + std::this_thread::sleep_for(duration); + + th_gen = std::thread(&Fortuna::generator_service, this, std::make_shared()); th_accu = std::thread(&Fortuna::accumulator_service, this); th_sfm = std::thread(&Fortuna::seed_file_manager_service, this); th_urandom = std::thread(&Fortuna::urandom_entropy_src_service, this); + + this->sync_point.count_down(); } Fortuna::~Fortuna() noexcept { if (th_gen.joinable()) { @@ -124,6 +133,10 @@ auto Fortuna::generator_service( std::shared_ptr Gen) -> void { int i{0}; static constexpr const std::chrono::milliseconds sleep_time{1000}; + + fmt::print("[i] gen: waiting on a latch\n"); + this->sync_point.count_down(); + std::chrono::system_clock::time_point time_point; std::unique_lock p_ul(print_mtx); fmt::print("[i] fortuna: starting generator service\n"); @@ -145,6 +158,10 @@ auto Fortuna::generator_service( auto Fortuna::accumulator_service() -> void { static constexpr const std::chrono::seconds sleep_time{10}; + + fmt::print("[i] accu: waiting on a latch\n"); + this->sync_point.count_down(); + std::chrono::system_clock::time_point time_point; std::unique_lock p_ul(print_mtx); fmt::print("[i] fortuna: starting accumulator service\n"); @@ -162,6 +179,10 @@ auto Fortuna::accumulator_service() -> void { auto Fortuna::seed_file_manager_service() -> void { static constexpr const std::chrono::seconds checkup_interval{10}; + + fmt::print("[i] sfm: waiting on a latch\n"); + this->sync_point.count_down(); + std::unique_lock p_ul(print_mtx); fmt::print("[i] fortuna: starting seed file manager service\n"); fmt::print("[*] sfm: checkup interval {}\n", checkup_interval); diff --git a/fortuna.h b/fortuna.h index 6a62dc3..78fea7b 100644 --- a/fortuna.h +++ b/fortuna.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ public: std::thread th_accu; std::thread th_sfm; std::thread th_urandom; + std::latch sync_point{5}; // 4 services + main thread Fortuna(); ~Fortuna() noexcept; @@ -79,6 +81,7 @@ public: e.what()); } p_ul.try_lock(); + this->sync_point.count_down(); fmt::print("[*] fortuna: PRNG initialized\n"); }