fortuna: add accumulator service,thread
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1817b4a82e
commit
3553968d52
19
fortuna.cpp
19
fortuna.cpp
|
@ -25,10 +25,12 @@ Fortuna::Fortuna() {
|
|||
fmt::print(stderr, "{}\n", e.what());
|
||||
}
|
||||
th_gen = std::thread(&Fortuna::generator_service, this, &R.Gen);
|
||||
th_accu = std::thread(&Fortuna::accumulator_service, this);
|
||||
th_sfm = std::thread(&Fortuna::seed_file_manager_service, this);
|
||||
}
|
||||
Fortuna::~Fortuna() noexcept {
|
||||
th_gen.join();
|
||||
th_accu.join();
|
||||
th_sfm.join();
|
||||
}
|
||||
|
||||
|
@ -104,6 +106,23 @@ auto Fortuna::generator_service(fortuna::generator::Generator* Gen) -> void {
|
|||
}
|
||||
}
|
||||
|
||||
auto Fortuna::accumulator_service() -> void {
|
||||
std::chrono::seconds sleep_time{10};
|
||||
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");
|
||||
p_ul.unlock();
|
||||
|
||||
while (true) {
|
||||
time_point = fortuna::Util::current_time();
|
||||
p_ul.lock();
|
||||
fmt::print("[*] accu: @{}\n", time_point);
|
||||
p_ul.unlock();
|
||||
std::this_thread::sleep_until(time_point +
|
||||
std::chrono::seconds(sleep_time));
|
||||
}
|
||||
}
|
||||
|
||||
auto Fortuna::seed_file_manager_service() -> void {
|
||||
static constexpr const std::chrono::seconds checkup_interval{10};
|
||||
std::unique_lock<std::mutex> p_ul(print_mtx);
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
std::mutex mtx;
|
||||
std::mutex print_mtx;
|
||||
std::thread th_gen;
|
||||
std::thread th_accu;
|
||||
std::thread th_sfm;
|
||||
|
||||
Fortuna();
|
||||
|
@ -62,6 +63,8 @@ public:
|
|||
|
||||
auto generator_service(fortuna::generator::Generator*) -> void;
|
||||
|
||||
auto accumulator_service() -> void;
|
||||
|
||||
auto seed_file_manager_service() -> void;
|
||||
|
||||
// PRNG state
|
||||
|
|
Reference in New Issue