aboutsummaryrefslogtreecommitdiffstats
path: root/alc/alc.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-08-01 15:19:37 -0700
committerChris Robinson <[email protected]>2019-08-01 15:19:37 -0700
commit0be823320d651130e79fbba33eff81676d59b09c (patch)
treec9c3f111530680363be4c8fb04e20b24ca12679d /alc/alc.cpp
parent57e7fff6f67f302d0202b2229a960c02c3cb3c5d (diff)
Add and use an intrusive_ptr type
Diffstat (limited to 'alc/alc.cpp')
-rw-r--r--alc/alc.cpp63
1 files changed, 5 insertions, 58 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 462d4bd0..6837d107 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -906,53 +906,7 @@ constexpr ALCint alcEFXMinorVersion = 0;
al::FlexArray<ALCcontext*> EmptyContextArray{0u};
-/* Simple RAII device reference. Takes the reference of the provided ALCdevice,
- * and decrements it when leaving scope. Movable (transfer reference) but not
- * copyable (no new references).
- */
-class DeviceRef {
- ALCdevice *mDev{nullptr};
-
- void reset() noexcept
- {
- if(mDev)
- mDev->release();
- mDev = nullptr;
- }
-
-public:
- DeviceRef() noexcept = default;
- DeviceRef(DeviceRef&& rhs) noexcept : mDev{rhs.mDev}
- { rhs.mDev = nullptr; }
- explicit DeviceRef(ALCdevice *dev) noexcept : mDev(dev) { }
- ~DeviceRef() { reset(); }
-
- DeviceRef& operator=(const DeviceRef&) = delete;
- DeviceRef& operator=(DeviceRef&& rhs) noexcept
- {
- std::swap(mDev, rhs.mDev);
- return *this;
- }
-
- operator bool() const noexcept { return mDev != nullptr; }
-
- ALCdevice* operator->() const noexcept { return mDev; }
- ALCdevice* get() const noexcept { return mDev; }
-
- ALCdevice* release() noexcept
- {
- ALCdevice *ret{mDev};
- mDev = nullptr;
- return ret;
- }
-};
-
-inline bool operator==(const DeviceRef &lhs, const ALCdevice *rhs) noexcept
-{ return lhs.get() == rhs; }
-inline bool operator!=(const DeviceRef &lhs, const ALCdevice *rhs) noexcept
-{ return !(lhs == rhs); }
-inline bool operator<(const DeviceRef &lhs, const ALCdevice *rhs) noexcept
-{ return lhs.get() < rhs; }
+using DeviceRef = al::intrusive_ptr<ALCdevice>;
/************************************************
@@ -2345,11 +2299,8 @@ static DeviceRef VerifyDevice(ALCdevice *device)
std::lock_guard<std::recursive_mutex> _{ListLock};
auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device);
if(iter != DeviceList.cend() && *iter == device)
- {
- (*iter)->add_ref();
- return DeviceRef{iter->get()};
- }
- return DeviceRef{};
+ return *iter;
+ return nullptr;
}
@@ -2590,14 +2541,10 @@ static ContextRef VerifyContext(ALCcontext *context)
std::lock_guard<std::recursive_mutex> _{ListLock};
auto iter = std::lower_bound(ContextList.cbegin(), ContextList.cend(), context);
if(iter != ContextList.cend() && *iter == context)
- {
- (*iter)->add_ref();
- return ContextRef{iter->get()};
- }
- return ContextRef{};
+ return *iter;
+ return nullptr;
}
-
/* GetContextRef
*
* Returns a new reference to the currently active context for this thread.