chore(fortuna): lock print_mtx in {} scopes
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
3db8100089
commit
4c77810535
61
fortuna.cpp
61
fortuna.cpp
|
@ -126,23 +126,21 @@ auto Fortuna::random_data(unsigned int n_bytes) -> void {
|
|||
|
||||
auto Fortuna::generator_service(
|
||||
std::shared_ptr<fortuna::generator::Generator> Gen) -> void {
|
||||
int i{0};
|
||||
static constexpr const std::chrono::milliseconds sleep_time{1000};
|
||||
|
||||
std::chrono::system_clock::time_point time_point;
|
||||
std::unique_lock<std::mutex> p_ul(print_mtx);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[i] fortuna: starting generator service\n");
|
||||
p_ul.unlock();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
p_ul.lock();
|
||||
fmt::print("[*] g: sleeping [{}]\n", i);
|
||||
p_ul.unlock();
|
||||
++i;
|
||||
time_point = fortuna::Util::current_time();
|
||||
p_ul.lock();
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] g: @{}\n", time_point);
|
||||
p_ul.unlock();
|
||||
}
|
||||
std::this_thread::sleep_until(time_point +
|
||||
std::chrono::milliseconds(sleep_time));
|
||||
}
|
||||
|
@ -152,15 +150,17 @@ auto Fortuna::accumulator_service() -> void {
|
|||
static constexpr const std::chrono::seconds sleep_time{10};
|
||||
|
||||
std::chrono::system_clock::time_point time_point;
|
||||
std::unique_lock<std::mutex> p_ul(print_mtx);
|
||||
{
|
||||
std::lock_guard<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();
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] accu: @{}\n", time_point);
|
||||
p_ul.unlock();
|
||||
}
|
||||
std::this_thread::sleep_until(time_point +
|
||||
std::chrono::seconds(sleep_time));
|
||||
}
|
||||
|
@ -169,10 +169,12 @@ auto Fortuna::accumulator_service() -> void {
|
|||
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);
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[i] fortuna: starting seed file manager service\n");
|
||||
fmt::print("[*] sfm: checkup interval {}\n", checkup_interval);
|
||||
p_ul.unlock();
|
||||
}
|
||||
|
||||
auto right_now{fortuna::Util::current_time()};
|
||||
std::unique_lock<std::mutex> mtx_l(mtx);
|
||||
std::unique_lock<std::mutex> a_ul(mtx_accu);
|
||||
|
@ -186,21 +188,30 @@ auto Fortuna::seed_file_manager_service() -> void {
|
|||
|
||||
while (true) {
|
||||
right_now = fortuna::Util::current_time();
|
||||
p_ul.lock();
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] sfm: checkup time @{}\n", right_now);
|
||||
}
|
||||
if (!sfm.is_job_running()) {
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] sfm: job not running, starting\n");
|
||||
}
|
||||
try {
|
||||
sfm.do_stuff();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
fmt::print(stderr, "[!] sfm: exception caught: {}\n", e.what());
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print(
|
||||
stderr, "[!] sfm: exception caught: {}\n", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] sfm: job running\n");
|
||||
}
|
||||
p_ul.unlock();
|
||||
std::this_thread::sleep_until(right_now +
|
||||
std::chrono::seconds(checkup_interval));
|
||||
}
|
||||
|
@ -208,11 +219,12 @@ auto Fortuna::seed_file_manager_service() -> void {
|
|||
|
||||
auto Fortuna::urandom_entropy_src_service() -> void {
|
||||
static constexpr const std::chrono::milliseconds wakeup_interval{50};
|
||||
std::unique_lock<std::mutex> p_ul(print_mtx);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[i] fortuna: starting urandom entropy src service\n");
|
||||
fmt::print("[*] ues: wakeup interval {}\n", wakeup_interval);
|
||||
p_ul.unlock();
|
||||
}
|
||||
|
||||
auto right_now{fortuna::Util::current_time()};
|
||||
|
||||
|
@ -225,7 +237,7 @@ auto Fortuna::urandom_entropy_src_service() -> void {
|
|||
|
||||
while (true) {
|
||||
try {
|
||||
p_ul.lock();
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[i] now: {}\n", fortuna::Util::current_time());
|
||||
|
||||
// check if ptr still valid
|
||||
|
@ -236,17 +248,22 @@ auto Fortuna::urandom_entropy_src_service() -> void {
|
|||
|
||||
ues.event(adder);
|
||||
}
|
||||
p_ul.unlock();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[!] ues exception: {}\n", e.what());
|
||||
}
|
||||
}
|
||||
right_now = fortuna::Util::current_time();
|
||||
std::this_thread::sleep_until(
|
||||
right_now + std::chrono::milliseconds(wakeup_interval));
|
||||
mtx_l.lock();
|
||||
{
|
||||
std::lock_guard<std::mutex> p_ul(print_mtx);
|
||||
fmt::print("[*] fortuna: current p0 length: {}\n\n",
|
||||
this->R._p_pools->at(0).get_s_byte_count());
|
||||
}
|
||||
mtx_l.unlock();
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue