1
0
Fork 0
forked from lthn/blockchain

epee::misc_utils::void_copy introduced

This commit is contained in:
sowle 2025-05-21 04:32:16 +03:00
parent d9c7a2ac08
commit 4be5761a90
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
2 changed files with 14 additions and 23 deletions

View file

@ -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<typename parent_t>
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

View file

@ -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<crypto::hash> m_cache_coinbase_id;
mutable std::atomic<uint8_t> 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<std::atomic<uint8_t>> 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<crypto::hash> ptr_h = std::make_shared<crypto::hash>(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;
}