Commit f793d7ed authored by Dominik Charousset's avatar Dominik Charousset

Enable intrusive_ptr<const T>

parent eb1cc7b1
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
/// reference of this object before calling this member /// reference of this object before calling this member
/// function. This information is important when /// function. This information is important when
/// implementing a type with support for weak pointers. /// implementing a type with support for weak pointers.
virtual void request_deletion(bool decremented_rc) noexcept; virtual void request_deletion(bool decremented_rc) const noexcept;
protected: protected:
virtual ~memory_managed(); virtual ~memory_managed();
......
...@@ -38,13 +38,13 @@ public: ...@@ -38,13 +38,13 @@ public:
ref_counted& operator=(const ref_counted&); ref_counted& operator=(const ref_counted&);
/// Increases reference count by one. /// Increases reference count by one.
inline void ref() noexcept { inline void ref() const noexcept {
rc_.fetch_add(1, std::memory_order_relaxed); rc_.fetch_add(1, std::memory_order_relaxed);
} }
/// Decreases reference count by one and calls `request_deletion` /// Decreases reference count by one and calls `request_deletion`
/// when it drops to zero. /// when it drops to zero.
void deref() noexcept; void deref() const noexcept;
/// Queries whether there is exactly one reference. /// Queries whether there is exactly one reference.
inline bool unique() const noexcept { inline bool unique() const noexcept {
...@@ -56,16 +56,16 @@ public: ...@@ -56,16 +56,16 @@ public:
} }
protected: protected:
std::atomic<size_t> rc_; mutable std::atomic<size_t> rc_;
}; };
/// @relates ref_counted /// @relates ref_counted
inline void intrusive_ptr_add_ref(ref_counted* p) { inline void intrusive_ptr_add_ref(const ref_counted* p) {
p->ref(); p->ref();
} }
/// @relates ref_counted /// @relates ref_counted
inline void intrusive_ptr_release(ref_counted* p) { inline void intrusive_ptr_release(const ref_counted* p) {
p->deref(); p->deref();
} }
......
...@@ -24,7 +24,7 @@ memory_managed::~memory_managed() { ...@@ -24,7 +24,7 @@ memory_managed::~memory_managed() {
// nop // nop
} }
void memory_managed::request_deletion(bool) noexcept { void memory_managed::request_deletion(bool) const noexcept {
delete this; delete this;
} }
......
...@@ -37,7 +37,7 @@ ref_counted& ref_counted::operator=(const ref_counted&) { ...@@ -37,7 +37,7 @@ ref_counted& ref_counted::operator=(const ref_counted&) {
return *this; return *this;
} }
void ref_counted::deref() noexcept { void ref_counted::deref() const noexcept {
if (unique()) { if (unique()) {
request_deletion(false); request_deletion(false);
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment