Skip to content

Commit

Permalink
Add disabled retainer allocated parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Aug 4, 2024
1 parent 95e7e3a commit cde27c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ class BC_API block
/// Reference used to avoid copy, sets cache if not set (not thread safe).
const hash_digest& get_hash() const NOEXCEPT;

/// Set memory retention mutex.
/// Set/get memory retainer.
void set_retainer(retainer::ptr&& retainer) const NOEXCEPT;
const retainer::ptr& get_retainer() const NOEXCEPT;

/// Identity.
/// -----------------------------------------------------------------------
Expand Down
22 changes: 15 additions & 7 deletions include/bitcoin/system/retainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace libbitcoin {

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

/// Shared lock object to inform allocator that memory may be freed.
class BC_API retainer final
{
Expand All @@ -33,23 +35,29 @@ class BC_API retainer final

DELETE_COPY_MOVE_DESTRUCT(retainer);

retainer() NOEXCEPT
: shared_lock_{}
inline retainer() NOEXCEPT
: /*allocation_{},*/ shared_lock_{}
{
}

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
retainer(std::shared_mutex& mutex) NOEXCEPT
: shared_lock_(mutex)
inline retainer(std::shared_mutex& mutex, size_t=0) NOEXCEPT
: /*allocation_{ allocation },*/ shared_lock_{ mutex }
{
}
BC_POP_WARNING()

inline size_t allocation() const NOEXCEPT
{
return {};//// allocation_;
}

private:
// This is thread safe.
// These are thread safe.
////size_t allocation_;
std::shared_lock<std::shared_mutex> shared_lock_;
};

BC_POP_WARNING()

} // namespace libbitcoin

#endif
5 changes: 5 additions & 0 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ void block::set_retainer(retainer::ptr&& retainer) const NOEXCEPT
retainer_ = std::move(retainer);
}

const retainer::ptr& block::get_retainer() const NOEXCEPT
{
return retainer_;
}

// Serialization.
// ----------------------------------------------------------------------------

Expand Down

0 comments on commit cde27c7

Please sign in to comment.