Skip to content

Commit

Permalink
Merge pull request #1510 from evoskuil/master
Browse files Browse the repository at this point in the history
Move retainer to own file.
  • Loading branch information
evoskuil authored Jul 31, 2024
2 parents 7288c70 + 5f3551b commit d9e6319
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ 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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\radix\base_64.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\radix\base_85.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\radix\radix.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\retainer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\serial\deserialize.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\serial\props.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\system\serial\serial.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\system\radix\radix.hpp">
<Filter>include\bitcoin\system\radix</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\retainer.hpp">
<Filter>include\bitcoin\system</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\system\serial\deserialize.hpp">
<Filter>include\bitcoin\system\serial</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#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>
Expand Down
28 changes: 1 addition & 27 deletions include/bitcoin/system/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,14 @@

#include <iterator>
#include <limits>
#include <memory>
#include <new>
#include <shared_mutex>
#include <type_traits>
#include <utility>
#include <vector>
#include <bitcoin/system/arena.hpp>
#include <bitcoin/system/retainer.hpp>

namespace libbitcoin {

/// Shared lock object to inform allocator that memory may be freed.
class retainer
{
public:
using ptr = std::shared_ptr<retainer>;

DELETE_COPY_MOVE_DESTRUCT(retainer);

retainer() NOEXCEPT
: shared_lock_{}
{
}

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
retainer(std::shared_mutex& mutex) NOEXCEPT
: shared_lock_(mutex)
{
}
BC_POP_WARNING()

private:
std::shared_lock<std::shared_mutex> shared_lock_;
};

/// Default-filling polymorphic allocator.
/// Strictly conforms to std::pmr::polymorphic_allocator.
/// Does not default to std::pmr::get_default_resource() but
Expand Down
54 changes: 54 additions & 0 deletions include/bitcoin/system/retainer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_SYSTEM_RETAINER_HPP
#define LIBBITCOIN_SYSTEM_RETAINER_HPP

#include <memory>
#include <shared_mutex>
#include <bitcoin/system/arena.hpp>

namespace libbitcoin {

/// Shared lock object to inform allocator that memory may be freed.
class retainer
{
public:
using ptr = std::shared_ptr<retainer>;

DELETE_COPY_MOVE_DESTRUCT(retainer);

retainer() NOEXCEPT
: shared_lock_{}
{
}

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
retainer(std::shared_mutex& mutex) NOEXCEPT
: shared_lock_(mutex)
{
}
BC_POP_WARNING()

private:
std::shared_lock<std::shared_mutex> shared_lock_;
};

} // namespace libbitcoin

#endif
3 changes: 2 additions & 1 deletion src/define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
// boost : warnings
// exceptions : boost
// arena : exceptions
// allocator : arena
// retainer : arena
// allocator : retainer
// types : allocator
// constants : types
// literals : constants
Expand Down

0 comments on commit d9e6319

Please sign in to comment.