Skip to content

Commit

Permalink
Merge pull request #1509 from evoskuil/master
Browse files Browse the repository at this point in the history
Change block's memory retainer cache to shared_ptr.
  • Loading branch information
evoskuil authored Jul 30, 2024
2 parents 41dff01 + 3773f22 commit 7288c70
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 41 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/system/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace libbitcoin {
class retainer
{
public:
using ptr = std::unique_ptr<retainer>;
using ptr = std::shared_ptr<retainer>;

DELETE_COPY_MOVE_DESTRUCT(retainer);

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/arena.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

namespace libbitcoin {

/// Memory resource interface, for use with our (polymorphic) allocator.
/// Strictly conforms to std::pmr::memory_resource.
/// Thread safe resource interface, for use with our (polymorphic) allocator.
class arena
{
public:
Expand Down
12 changes: 2 additions & 10 deletions include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace chain {
class BC_API block
{
public:
DEFAULT_COPY_MOVE_DESTRUCT(block);

typedef std::shared_ptr<const block> cptr;

static bool is_malleable64(const transaction_cptrs& txs) NOEXCEPT;
Expand All @@ -49,12 +51,6 @@ class BC_API block

/// Default block is an invalid object.
block() NOEXCEPT;
virtual ~block() NOEXCEPT;

/// Cache is defaulted on copy/assign.
block(block&& other) NOEXCEPT;
block(const block& other) NOEXCEPT;

block(chain::header&& header, transactions&& txs) NOEXCEPT;
block(const chain::header& header, const transactions& txs) NOEXCEPT;
block(const chain::header::cptr& header,
Expand All @@ -71,10 +67,6 @@ class BC_API block
/// Operators.
/// -----------------------------------------------------------------------

/// Cache is defaulted on copy/assign.
block& operator=(block&& other) NOEXCEPT;
block& operator=(const block& other) NOEXCEPT;

bool operator==(const block& other) const NOEXCEPT;
bool operator!=(const block& other) const NOEXCEPT;

Expand Down
31 changes: 2 additions & 29 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ block::block() NOEXCEPT
{
}

block::~block() NOEXCEPT
{
}

block::block(block&& other) NOEXCEPT
: block(other)
{
}

block::block(const block& other) NOEXCEPT
: block(other.header_, other.txs_, other.valid_)
{
}

block::block(chain::header&& header, chain::transactions&& txs) NOEXCEPT
: block(to_shared(std::move(header)), to_shareds(std::move(txs)), true)
{
Expand Down Expand Up @@ -141,21 +127,6 @@ block::block(const chain::header::cptr& header,
// Operators.
// ----------------------------------------------------------------------------

block& block::operator=(block&& other) NOEXCEPT
{
*this = other;
return *this;
}

block& block::operator=(const block& other) NOEXCEPT
{
header_ = other.header_;
txs_ = other.txs_;
valid_ = other.valid_;
size_ = other.size_;
return *this;
}

bool block::operator==(const block& other) const NOEXCEPT
{
return (header_ == other.header_ || *header_ == *other.header_)
Expand Down Expand Up @@ -189,6 +160,8 @@ void block::assign_data(reader& source, bool witness) NOEXCEPT

// Retainer will be an empty pointer when default allocator is used.
// Retainer release informs allocator that associated memory may be freed.
// Retainer is copied on block copy/assign, since allocations are thus shared.
// WARNING: retainer does not track objects shared from the block (e.g. tx).
void block::set_retainer(retainer::ptr&& retainer) const NOEXCEPT
{
retainer_ = std::move(retainer);
Expand Down

0 comments on commit 7288c70

Please sign in to comment.