diff --git a/g2log/src/g2logworker.hpp b/g2log/src/g2logworker.hpp index bc4340f..e1d1f2c 100644 --- a/g2log/src/g2logworker.hpp +++ b/g2log/src/g2logworker.hpp @@ -65,8 +65,7 @@ public: std::unique_ptr> addSink(std::unique_ptr real_sink, DefaultLogCall call) { using namespace g2; using namespace g2::internal; - auto shared_sink = std::shared_ptr(real_sink.release()); - auto sink = std::make_shared < Sink < T >> (shared_sink, call); + auto sink = std::make_shared < Sink < T >> (std::move(real_sink), call); addWrappedSink(sink); return std2::make_unique < SinkHandle < T >> (sink); } diff --git a/g2log/src/g2sink.hpp b/g2log/src/g2sink.hpp index 1e86276..1f374f6 100644 --- a/g2log/src/g2sink.hpp +++ b/g2log/src/g2sink.hpp @@ -33,21 +33,21 @@ typedef std::function AsyncMessageCall; template struct Sink : public SinkWrapper { - std::shared_ptr _real_sink; + std::unique_ptr _real_sink; std::unique_ptr _bg; AsyncMessageCall _default_log_call; template - Sink(std::shared_ptr sink, DefaultLogCall call) + Sink(std::unique_ptr sink, DefaultLogCall call) : SinkWrapper (), - _real_sink{sink}, + _real_sink{std::move(sink)}, _bg(kjellkod::Active::createActive()), _default_log_call(std::bind(call, _real_sink.get(), std::placeholders::_1)) { } - Sink(std::shared_ptr sink, void(T::*Call)(std::string) ) + Sink(std::unique_ptr sink, void(T::*Call)(std::string) ) : SinkWrapper(), - _real_sink {sink}, + _real_sink {std::move(sink)}, _bg(kjellkod::Active::createActive()) { auto adapter = std::bind(Call, _real_sink.get(), std::placeholders::_1); _default_log_call = [ = ](LogMessageMover m){adapter(m.get().toString());}; diff --git a/g2log/test_unit/test_concept_sink.cpp b/g2log/test_unit/test_concept_sink.cpp index 66b9aaa..4cf2c9c 100644 --- a/g2log/test_unit/test_concept_sink.cpp +++ b/g2log/test_unit/test_concept_sink.cpp @@ -85,10 +85,8 @@ namespace g2 { template std::unique_ptr< SinkHandle > addSink(std::unique_ptr unique, DefaultLogCall call) { - auto shared = std::shared_ptr(unique.release()); - auto sink = std::make_shared < internal::Sink > (shared, call); + auto sink = std::make_shared < internal::Sink > (std::move(unique), call); auto add_sink_call = [this, sink] { _container.push_back(sink); }; - auto wait_result = g2::spawn_task(add_sink_call, _bg.get()); wait_result.wait(); @@ -101,6 +99,7 @@ namespace g2 { + using namespace g2; using namespace g2::internal;