fortuna: update the init-latch logic

This commit is contained in:
surtur 2022-01-21 06:27:06 +01:00
parent 6c68efc6ee
commit c852c723fd
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 2 additions and 17 deletions

View File

@ -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<fortuna::generator::Generator>());
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<std::mutex> 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<std::mutex> 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<std::mutex> p_ul(print_mtx);
fmt::print("[i] fortuna: starting seed file manager service\n");
fmt::print("[*] sfm: checkup interval {}\n", checkup_interval);

View File

@ -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;