From e8d46ae90851f2cf3abb79bb647c74a2dbe8317d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 7 Aug 2024 15:23:56 -0400 Subject: [PATCH] Remove retainer, add block allocation metadata. --- Makefile.am | 1 - .../libbitcoin-system.vcxproj | 1 - .../libbitcoin-system.vcxproj.filters | 3 - include/bitcoin/system.hpp | 1 - include/bitcoin/system/allocator.hpp | 2 +- include/bitcoin/system/chain/block.hpp | 8 +-- include/bitcoin/system/retainer.hpp | 63 ------------------- src/chain/block.cpp | 12 ++-- src/define.cpp | 3 +- 9 files changed, 10 insertions(+), 84 deletions(-) delete mode 100644 include/bitcoin/system/retainer.hpp diff --git a/Makefile.am b/Makefile.am index 8572feffa3..e9b27b0a52 100755 --- a/Makefile.am +++ b/Makefile.am @@ -434,7 +434,6 @@ include_bitcoin_system_HEADERS = \ include/bitcoin/system/have.hpp \ include/bitcoin/system/literals.hpp \ include/bitcoin/system/preprocessor.hpp \ - include/bitcoin/system/retainer.hpp \ include/bitcoin/system/settings.hpp \ include/bitcoin/system/typelets.hpp \ include/bitcoin/system/types.hpp \ diff --git a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj index a8ab04b118..f551aac1f4 100644 --- a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj @@ -404,7 +404,6 @@ - diff --git a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters index 43059903d0..d7c8ddd1a8 100644 --- a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.vcxproj.filters @@ -1091,9 +1091,6 @@ include\bitcoin\system\radix - - include\bitcoin\system - include\bitcoin\system\serial diff --git a/include/bitcoin/system.hpp b/include/bitcoin/system.hpp index 0b292d5e30..8eb1c1d6d9 100755 --- a/include/bitcoin/system.hpp +++ b/include/bitcoin/system.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/include/bitcoin/system/allocator.hpp b/include/bitcoin/system/allocator.hpp index a0e9257b40..6589387e7e 100644 --- a/include/bitcoin/system/allocator.hpp +++ b/include/bitcoin/system/allocator.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace libbitcoin { diff --git a/include/bitcoin/system/chain/block.hpp b/include/bitcoin/system/chain/block.hpp index abbc7efad0..83cf2a6345 100644 --- a/include/bitcoin/system/chain/block.hpp +++ b/include/bitcoin/system/chain/block.hpp @@ -112,9 +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/get memory retainer. - void set_retainer(retainer::ptr&& retainer) const NOEXCEPT; - const retainer::ptr& get_retainer() const NOEXCEPT; + /// Set/get memory allocation. + void set_allocation(size_t allocation) const NOEXCEPT; + const size_t get_allocation() const NOEXCEPT; /// Identity. /// ----------------------------------------------------------------------- @@ -220,7 +220,7 @@ class BC_API block // Cache. bool valid_; sizes size_; - mutable retainer::ptr retainer_{}; + mutable size_t allocation_{}; }; typedef std_vector blocks; diff --git a/include/bitcoin/system/retainer.hpp b/include/bitcoin/system/retainer.hpp deleted file mode 100644 index 2ef6566c59..0000000000 --- a/include/bitcoin/system/retainer.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2011-2024 libbitcoin developers (see AUTHORS) - * - * This file is part of libbitcoin. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -#ifndef LIBBITCOIN_SYSTEM_RETAINER_HPP -#define LIBBITCOIN_SYSTEM_RETAINER_HPP - -#include -#include -#include - -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 -{ -public: - using ptr = std::shared_ptr; - - DELETE_COPY_MOVE_DESTRUCT(retainer); - - inline retainer() NOEXCEPT - : allocation_{}, shared_lock_{} - { - } - - inline retainer(std::shared_mutex& mutex, size_t allocation=0) NOEXCEPT - : allocation_{ allocation }, shared_lock_{ mutex } - { - } - - inline size_t allocation() const NOEXCEPT - { - return allocation_; - } - -private: - // These are thread safe. - size_t allocation_; - std::shared_lock shared_lock_; -}; - -BC_POP_WARNING() - -} // namespace libbitcoin - -#endif diff --git a/src/chain/block.cpp b/src/chain/block.cpp index a7b69a9803..c2b95f9090 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -155,18 +155,14 @@ void block::assign_data(reader& source, bool witness) NOEXCEPT valid_ = source; } -// 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 +void block::set_allocation(size_t allocation) const NOEXCEPT { - retainer_ = std::move(retainer); + allocation_ = allocation; } -const retainer::ptr& block::get_retainer() const NOEXCEPT +const size_t block::get_allocation() const NOEXCEPT { - return retainer_; + return allocation_; } // Serialization. diff --git a/src/define.cpp b/src/define.cpp index d9d61408f9..6187290b5b 100644 --- a/src/define.cpp +++ b/src/define.cpp @@ -31,8 +31,7 @@ // boost : warnings // exceptions : boost // arena : exceptions -// retainer : arena -// allocator : retainer +// allocator : arena // types : allocator // constants : types // literals : constants