From f658a850c47ada526cf7216ba2a131dfb61ac598 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 4 Jul 2016 14:17:33 +0200 Subject: [PATCH] clean up --- src/uvw.hpp | 1 - src/uvw/handle.hpp | 12 +++++++----- src/uvw/self.hpp | 25 ------------------------- 3 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 src/uvw/self.hpp diff --git a/src/uvw.hpp b/src/uvw.hpp index 6743a01e..8458c501 100644 --- a/src/uvw.hpp +++ b/src/uvw.hpp @@ -6,7 +6,6 @@ #include "uvw/loop.hpp" #include "uvw/prepare.hpp" #include "uvw/request.hpp" -#include "uvw/self.hpp" #include "uvw/stream.hpp" #include "uvw/tcp.hpp" #include "uvw/timer.hpp" diff --git a/src/uvw/handle.hpp b/src/uvw/handle.hpp index 74e2c85b..1c2a06bd 100644 --- a/src/uvw/handle.hpp +++ b/src/uvw/handle.hpp @@ -5,7 +5,6 @@ #include #include #include "emitter.hpp" -#include "self.hpp" #include "loop.hpp" @@ -23,7 +22,7 @@ template<> struct HandleType { }; template -class Handle: public Emitter, public Self { +class Handle: public Emitter, public std::enable_shared_from_this { struct BaseWrapper { virtual ~BaseWrapper() = default; virtual void * get() const noexcept = 0; @@ -41,15 +40,17 @@ class Handle: public Emitter, public Self { Handle &ref = *(static_cast(handle->data)); ref.initialized = false; ref.publish(CloseEvent{}); - ref.reset(); + ref.leak.reset(); } protected: template explicit Handle(HandleType, std::shared_ptr ref) - : Emitter{}, Self{}, + : Emitter{}, + std::enable_shared_from_this{}, wrapper{std::make_unique>()}, pLoop{std::move(ref)}, + leak{nullptr}, initialized{false} { this->template get()->data = static_cast(this); @@ -71,8 +72,8 @@ protected: this->publish(ErrorEvent{err}); ret = false; } else { + leak = this->shared_from_this(); initialized = true; - this->leak(); } } @@ -108,6 +109,7 @@ public: private: std::unique_ptr wrapper; std::shared_ptr pLoop; + std::shared_ptr leak; bool initialized; }; diff --git a/src/uvw/self.hpp b/src/uvw/self.hpp deleted file mode 100644 index 28bf58da..00000000 --- a/src/uvw/self.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - - -#include - - -namespace uvw { - - -template -struct Self: public std::enable_shared_from_this { - virtual ~Self() { - static_assert(std::is_base_of, T>::value, "!"); - } - -protected: - void leak() noexcept { self = this->shared_from_this(); } - void reset() noexcept { self.reset(); } - -private: - std::shared_ptr self; -}; - - -}