libluna/SharedPtr: Count references with separately created objects properly
This commit is contained in:
parent
5aa042a5f2
commit
d41fb85466
@ -23,7 +23,7 @@ struct Shareable
|
||||
return m_ref_count == 0;
|
||||
}
|
||||
|
||||
Atomic<int> m_ref_count { 1 };
|
||||
Atomic<int> m_ref_count { 0 };
|
||||
};
|
||||
|
||||
template <typename T> class SharedPtr
|
||||
@ -36,6 +36,7 @@ template <typename T> class SharedPtr
|
||||
|
||||
SharedPtr(T* ptr) : m_ptr(ptr)
|
||||
{
|
||||
if (m_ptr) shareable()->ref();
|
||||
}
|
||||
|
||||
SharedPtr(const SharedPtr<T>& other) : m_ptr(other.m_ptr)
|
||||
@ -50,7 +51,6 @@ template <typename T> class SharedPtr
|
||||
|
||||
template <typename Tp> operator SharedPtr<Tp>()
|
||||
{
|
||||
if (m_ptr) shareable()->ref();
|
||||
return { (Tp*)m_ptr };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user