mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-06 21:57:54 +02:00
Merge bitcoin/bitcoin#34471: refactor: Use aliasing shared_ptr in Sock::Wait
faa016af54refactor: Use aliasing shared_ptr in Sock::Wait (MarcoFalke) Pull request description: Currently, a no-op lambda is used as the deleter for the temporary shared pointer helper in `Sock::Wait`. This is perfectly fine, but has a few style issues: * The lambda needs to be allocated on the heap * It triggers a false-positive upstream GCC-16-trunk bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123912 Fix all issues by just using an aliasing shared pointer, which points to `this`, but is otherwise empty (sits on the stack without any heap allocations). ACKs for top commit: hodlinator: ACKfaa016af54sedited: ACKfaa016af54vasild: ACKfaa016af54Tree-SHA512: b7330862204e79fb61f30694accb16f9a24e5722bd0ceb098ca27c877cff921afa00c0cfd953d4cbb355e6433706961a25b628efefdbe0b48bdec2941eaaee7a
This commit is contained in:
@@ -140,10 +140,12 @@ bool Sock::IsSelectable() const
|
||||
|
||||
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
|
||||
{
|
||||
// We need a `shared_ptr` owning `this` for `WaitMany()`, but don't want
|
||||
// We need a `shared_ptr` holding `this` for `WaitMany()`, but don't want
|
||||
// `this` to be destroyed when the `shared_ptr` goes out of scope at the
|
||||
// end of this function. Create it with a custom noop deleter.
|
||||
std::shared_ptr<const Sock> shared{this, [](const Sock*) {}};
|
||||
// end of this function.
|
||||
// Create it with an aliasing shared_ptr that points to `this` without
|
||||
// owning it.
|
||||
std::shared_ptr<const Sock> shared{std::shared_ptr<const Sock>{}, this};
|
||||
|
||||
EventsPerSock events_per_sock{std::make_pair(shared, Events{requested})};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user