diff --git a/fortuna.cpp b/fortuna.cpp index a1d53a4..94e0dbd 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -27,25 +27,19 @@ auto now{std::chrono::steady_clock::now()}; Fortuna::Fortuna() { try { initialize_prng(); + this->sync_point.wait(); // wait for init } catch (CryptoPP::Exception& e) { 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()) { @@ -134,9 +128,6 @@ auto Fortuna::generator_service( 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"); @@ -159,9 +150,6 @@ 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"); @@ -180,9 +168,6 @@ 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 1a50764..f73eb41 100644 --- a/fortuna.h +++ b/fortuna.h @@ -28,7 +28,7 @@ public: std::thread th_accu; std::thread th_sfm; std::thread th_urandom; - std::latch sync_point{5}; // 4 services + main thread + std::latch sync_point{1}; // wait for init before spawning the threads Fortuna(); ~Fortuna() noexcept;