]> git.sesse.net Git - casparcg/blobdiff - common/memory/safe_ptr.h
2.0.0.2: image: Started working on image_scroll_producer.
[casparcg] / common / memory / safe_ptr.h
index fb8cfeb5c6d052f51a957f308385a9820179f105..5b371808c22ace5fc4a0b23b747b94ddf8798c40 100644 (file)
@@ -23,7 +23,7 @@
 #include <type_traits>\r
 #include <exception>\r
 \r
-#include <tbb/spin_mutex.h>\r
+#include "../utility/assert.h"\r
 \r
 namespace caspar {\r
        \r
@@ -31,7 +31,6 @@ template<typename T>
 class safe_ptr\r
 {      \r
        std::shared_ptr<T> impl_;\r
-       tbb::spin_mutex mutex_;\r
        template <typename> friend class safe_ptr;\r
 public:\r
        typedef T element_type;\r
@@ -106,11 +105,23 @@ public:
                return *this;\r
        }\r
 \r
-       T& operator*() const { return *impl_.get();}  // noexcept\r
+       T& operator*() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return *impl_.get();\r
+       } \r
 \r
-       T* operator->() const { return impl_.get();}  // noexcept\r
+       T* operator->() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return impl_.get();\r
+       } \r
 \r
-       T* get() const { return impl_.get();}  // noexcept\r
+       T* get() const // noexcept\r
+       {\r
+               CASPAR_ASSERT(impl_);\r
+               return impl_.get();\r
+       }  \r
 \r
        bool unique() const { return impl_.unique();}  // noexcept\r
 \r
@@ -130,6 +141,18 @@ public:
        D* get_deleter(safe_ptr<U> const& ptr) { return impl_.get_deleter(); }  // noexcept\r
 };\r
 \r
+template<class T, class U>\r
+bool operator==(const std::shared_ptr<T>& a, const safe_ptr<U>& b)  // noexcept\r
+{\r
+       return a.get() == b.get();\r
+}\r
+\r
+template<class T, class U>\r
+bool operator==(const safe_ptr<T>& a, const std::shared_ptr<U>& b)  // noexcept\r
+{\r
+       return a.get() == b.get();\r
+}\r
+\r
 template<class T, class U>\r
 bool operator==(const safe_ptr<T>& a, const safe_ptr<U>& b)  // noexcept\r
 {\r
@@ -253,4 +276,10 @@ safe_ptr<T> make_safe(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4)
        return safe_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4)));\r
 }\r
 \r
+template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>\r
+safe_ptr<T> make_safe(P0&& p0, P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5)\r
+{\r
+       return safe_ptr<T>(std::make_shared<T>(std::forward<P0>(p0), std::forward<P1>(p1), std::forward<P2>(p2), std::forward<P3>(p3), std::forward<P4>(p4), std::forward<P5>(p5)));\r
+}\r
+\r
 }
\ No newline at end of file