diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index dd599cf8..04cb9750 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -627,6 +627,18 @@ namespace misc_utils }; + // helper class mainly intended for using with std::atomic to repair copy-construction in classes where std::atomic is aggregated + template + struct void_copy : public parent_t + { + void_copy() = default; + void_copy(void_copy&&) noexcept = default; + void_copy& operator=(void_copy&&) noexcept = default; + + void_copy(const void_copy&) : parent_t{} {} + void_copy& operator=(const void_copy&) { return *this; } + }; + } // namespace misc_utils } // namespace epee diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index 891c314d..9593a2d5 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -77,28 +77,7 @@ namespace currency // This is an optional data fields, It is not included in serialization and therefore is never stored in the database. // It might be calculated "on the fly" to speed up access operations. mutable std::shared_ptr m_cache_coinbase_id; - mutable std::atomic m_cache_coinbase_state{0}; - - block_extended_info& operator=(const block_extended_info& rhs) - { - this->bl = rhs.bl; - this->height = rhs.height; - this->block_cumulative_size = rhs.block_cumulative_size; - this->cumulative_diff_adjusted = rhs.cumulative_diff_adjusted; - this->cumulative_diff_precise = rhs.cumulative_diff_precise; - this->cumulative_diff_precise_adjusted = rhs.cumulative_diff_precise_adjusted; - this->difficulty = rhs.difficulty; - this->already_generated_coins = rhs.already_generated_coins; - this->stake_hash = rhs.stake_hash; - this->version = rhs.version; - this->this_block_tx_fee_median = rhs.this_block_tx_fee_median; - this->effective_tx_fee_median = rhs.effective_tx_fee_median; - this->m_cache_coinbase_id.reset(); - this->m_cache_coinbase_state = 0; - return *this; - } - block_extended_info(const block_extended_info& rhs) { *this = rhs; } - block_extended_info() = default; + mutable epee::misc_utils::void_copy> m_cache_coinbase_state; }; struct gindex_increment @@ -235,7 +214,7 @@ namespace currency // state has just been 0, now 1, we're calculating std::shared_ptr ptr_h = std::make_shared(get_transaction_hash(bei.bl.miner_tx)); bei.m_cache_coinbase_id = ptr_h; - bei.m_cache_coinbase_state = 2; + bei.m_cache_coinbase_state.store(2); return *ptr_h; }