pool: add call_once to initialize_pool() mem. fun
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
* also protect set_id() member function with a std::lock_guard, which holds mtx for the time of initialization
This commit is contained in:
parent
14462e6b16
commit
e452a63b4a
4
pool.cpp
4
pool.cpp
|
@ -15,6 +15,7 @@ namespace fortuna {
|
|||
namespace accumulator {
|
||||
|
||||
auto Pool::set_id(const unsigned int& id) noexcept -> void {
|
||||
std::lock_guard<std::mutex> lg(mtx);
|
||||
this->pool_id = id;
|
||||
}
|
||||
|
||||
|
@ -23,7 +24,8 @@ auto Pool::get_id() const noexcept -> unsigned int {
|
|||
}
|
||||
|
||||
auto Pool::initialize_pool(const unsigned int& id) -> void {
|
||||
set_id(id);
|
||||
// ref: https://stackoverflow.com/a/23204682
|
||||
std::call_once(init, [this, id]{ this->set_id(id); } );
|
||||
}
|
||||
|
||||
auto Pool::add_entropy(const unsigned int& source,
|
||||
|
|
Reference in New Issue