aboutsummaryrefslogtreecommitdiffstats
path: root/common/intrusive_ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/intrusive_ptr.h')
-rw-r--r--common/intrusive_ptr.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h
index e1fc1f7b..31afa70f 100644
--- a/common/intrusive_ptr.h
+++ b/common/intrusive_ptr.h
@@ -1,6 +1,8 @@
#ifndef INTRUSIVE_PTR_H
#define INTRUSIVE_PTR_H
+#include <utility>
+
#include "atomic.h"
#include "opthelpers.h"
@@ -67,10 +69,13 @@ public:
}
intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept
{
- if(mPtr)
- mPtr->release();
- mPtr = rhs.mPtr;
- rhs.mPtr = nullptr;
+ if(likely(&rhs != this))
+ {
+ if(mPtr)
+ mPtr->release();
+ mPtr = rhs.mPtr;
+ rhs.mPtr = nullptr;
+ }
return *this;
}
@@ -87,12 +92,7 @@ public:
mPtr = ptr;
}
- T* release() noexcept
- {
- T *ret{mPtr};
- mPtr = nullptr;
- return ret;
- }
+ T* release() noexcept { return std::exchange(mPtr, nullptr); }
void swap(intrusive_ptr &rhs) noexcept { std::swap(mPtr, rhs.mPtr); }
void swap(intrusive_ptr&& rhs) noexcept { std::swap(mPtr, rhs.mPtr); }