fortuna: use a proper shared_ptr to Generator

This commit is contained in:
surtur 2022-01-13 03:02:31 +01:00
parent 226a5c2c6c
commit 8c3aee1b07
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 8 additions and 3 deletions

View File

@ -10,6 +10,7 @@
#include <chrono> #include <chrono>
#include <exception> #include <exception>
#include <memory>
#include <mutex> #include <mutex>
namespace fortuna { namespace fortuna {
@ -24,7 +25,8 @@ Fortuna::Fortuna() {
catch (CryptoPP::Exception& e) { catch (CryptoPP::Exception& e) {
fmt::print(stderr, "{}\n", e.what()); fmt::print(stderr, "{}\n", e.what());
} }
th_gen = std::thread(&Fortuna::generator_service, this, &R.Gen); th_gen = std::thread(&Fortuna::generator_service, this,
std::make_shared<fortuna::generator::Generator>());
th_accu = std::thread(&Fortuna::accumulator_service, this); th_accu = std::thread(&Fortuna::accumulator_service, this);
th_sfm = std::thread(&Fortuna::seed_file_manager_service, this); th_sfm = std::thread(&Fortuna::seed_file_manager_service, this);
} }
@ -90,7 +92,8 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12); fmt::print("getting random data took {:.{}f}s\n", diff.count(), 12);
} // random_data } // random_data
auto Fortuna::generator_service(fortuna::generator::Generator* Gen) -> void { auto Fortuna::generator_service(
std::shared_ptr<fortuna::generator::Generator> Gen) -> void {
int i{0}; int i{0};
std::chrono::milliseconds sleep_time{1000}; std::chrono::milliseconds sleep_time{1000};
std::chrono::system_clock::time_point time_point; std::chrono::system_clock::time_point time_point;

View File

@ -7,6 +7,7 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <chrono> #include <chrono>
#include <memory>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -61,7 +62,8 @@ public:
fmt::print("PRNG initialized\n"); fmt::print("PRNG initialized\n");
} }
auto generator_service(fortuna::generator::Generator*) -> void; auto generator_service(std::shared_ptr<fortuna::generator::Generator> Gen)
-> void;
auto accumulator_service() -> void; auto accumulator_service() -> void;