@@ -63,16 +63,16 @@ struct ProxyClient<Thread> : public ProxyClientBase<Thread, ::capnp::Void>
63
63
ProxyClient (const ProxyClient&) = delete ;
64
64
~ProxyClient ();
65
65
66
- void setCleanup (std::function<void ()> cleanup );
66
+ void setCleanup (std::function<void ()> fn );
67
67
68
68
// ! Cleanup function to run when the connection is closed. If the Connection
69
69
// ! gets destroyed before this ProxyClient<Thread> object, this cleanup
70
70
// ! callback lets it destroy this object and remove its entry in the
71
71
// ! thread's request_threads or callback_threads map (after resetting
72
- // ! m_cleanup so the destructor does not try to access it). But if this
72
+ // ! m_cleanup_it so the destructor does not try to access it). But if this
73
73
// ! object gets destroyed before the Connection, there's no need to run the
74
74
// ! cleanup function and the destructor will unregister it.
75
- std::optional<CleanupIt> m_cleanup ;
75
+ std::optional<CleanupIt> m_cleanup_it ;
76
76
};
77
77
78
78
template <>
@@ -379,7 +379,7 @@ ProxyClientBase<Interface, Impl>::ProxyClientBase(typename Interface::Client cli
379
379
}
380
380
381
381
// Handler for the connection getting destroyed before this client object.
382
- auto cleanup = m_context.connection ->addSyncCleanup ([this ]() {
382
+ auto cleanup_it = m_context.connection ->addSyncCleanup ([this ]() {
383
383
// Release client capability by move-assigning to temporary.
384
384
{
385
385
typename Interface::Client (std::move (self ().m_client ));
@@ -402,11 +402,11 @@ ProxyClientBase<Interface, Impl>::ProxyClientBase(typename Interface::Client cli
402
402
// The first case is handled here when m_context.connection is not null. The
403
403
// second case is handled by the cleanup function, which sets m_context.connection to
404
404
// null so nothing happens here.
405
- m_context.cleanup .emplace_front ([this , destroy_connection, cleanup ]{
405
+ m_context.cleanup_fns .emplace_front ([this , destroy_connection, cleanup_it ]{
406
406
if (m_context.connection ) {
407
407
// Remove cleanup callback so it doesn't run and try to access
408
408
// this object after it's already destroyed.
409
- m_context.connection ->removeSyncCleanup (cleanup );
409
+ m_context.connection ->removeSyncCleanup (cleanup_it );
410
410
411
411
// If the capnp interface defines a destroy method, call it to destroy
412
412
// the remote object, waiting for it to be deleted server side. If the
@@ -437,9 +437,7 @@ ProxyClientBase<Interface, Impl>::ProxyClientBase(typename Interface::Client cli
437
437
template <typename Interface, typename Impl>
438
438
ProxyClientBase<Interface, Impl>::~ProxyClientBase () noexcept
439
439
{
440
- for (auto & cleanup : m_context.cleanup ) {
441
- cleanup ();
442
- }
440
+ CleanupRun (m_context.cleanup_fns );
443
441
}
444
442
445
443
template <typename Interface, typename Impl>
@@ -476,14 +474,12 @@ ProxyServerBase<Interface, Impl>::~ProxyServerBase()
476
474
// connection is broken). Probably some refactoring of the destructor
477
475
// and invokeDestroy function is possible to make this cleaner and more
478
476
// consistent.
479
- m_context.connection ->addAsyncCleanup ([impl=std::move (m_impl), c =std::move (m_context.cleanup )]() mutable {
477
+ m_context.connection ->addAsyncCleanup ([impl=std::move (m_impl), fns =std::move (m_context.cleanup_fns )]() mutable {
480
478
impl.reset ();
481
- for (auto & cleanup : c) {
482
- cleanup ();
483
- }
479
+ CleanupRun (fns);
484
480
});
485
481
}
486
- assert (m_context.cleanup .size () == 0 );
482
+ assert (m_context.cleanup_fns .size () == 0 );
487
483
std::unique_lock<std::mutex> lock (m_context.connection ->m_loop .m_mutex );
488
484
m_context.connection ->m_loop .removeClient (lock);
489
485
}
@@ -509,10 +505,7 @@ template <typename Interface, typename Impl>
509
505
void ProxyServerBase<Interface, Impl>::invokeDestroy()
510
506
{
511
507
m_impl.reset ();
512
- for (auto & cleanup : m_context.cleanup ) {
513
- cleanup ();
514
- }
515
- m_context.cleanup .clear ();
508
+ CleanupRun (m_context.cleanup_fns );
516
509
}
517
510
518
511
using ConnThreads = std::map<Connection*, ProxyClient<Thread>>;
0 commit comments