aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-11-19 20:04:10 -0800
committerChris Robinson <[email protected]>2021-11-19 20:04:10 -0800
commit0c99a6b316b7e52c12a25d50550291562430834d (patch)
tree329d296c689215a6e9a712920189e9e5e853ca42 /alc
parent6e2c1b843132be98c016920d7e790aab69b64272 (diff)
Make the backend pointer part of ALCdevice instead of DeviceBase
Diffstat (limited to 'alc')
-rw-r--r--alc/alc.cpp6
-rw-r--r--alc/backends/base.h3
-rw-r--r--alc/device.cpp13
-rw-r--r--alc/device.h11
4 files changed, 16 insertions, 17 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 36f726fc..1b62e042 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -2817,7 +2817,7 @@ START_API_FUNC
values[i++] = ALC_OUTPUT_LIMITER_SOFT;
values[i++] = dev->Limiter ? ALC_TRUE : ALC_FALSE;
- ClockLatency clock{GetClockLatency(dev.get())};
+ ClockLatency clock{GetClockLatency(dev.get(), dev->Backend.get())};
values[i++] = ALC_DEVICE_CLOCK_SOFT;
values[i++] = clock.ClockTime.count();
@@ -2843,7 +2843,7 @@ START_API_FUNC
break;
case ALC_DEVICE_LATENCY_SOFT:
- *values = GetClockLatency(dev.get()).Latency.count();
+ *values = GetClockLatency(dev.get(), dev->Backend.get()).Latency.count();
break;
case ALC_DEVICE_CLOCK_LATENCY_SOFT:
@@ -2851,7 +2851,7 @@ START_API_FUNC
alcSetError(dev.get(), ALC_INVALID_VALUE);
else
{
- ClockLatency clock{GetClockLatency(dev.get())};
+ ClockLatency clock{GetClockLatency(dev.get(), dev->Backend.get())};
values[0] = clock.ClockTime.count();
values[1] = clock.Latency.count();
}
diff --git a/alc/backends/base.h b/alc/backends/base.h
index d661bc46..a3562f54 100644
--- a/alc/backends/base.h
+++ b/alc/backends/base.h
@@ -70,9 +70,8 @@ inline std::chrono::nanoseconds GetDeviceClockTime(DeviceBase *device)
/* Helper to get the device latency from the backend, including any fixed
* latency from post-processing.
*/
-inline ClockLatency GetClockLatency(DeviceBase *device)
+inline ClockLatency GetClockLatency(DeviceBase *device, BackendBase *backend)
{
- BackendBase *backend{device->Backend.get()};
ClockLatency ret{backend->getClockLatency()};
ret.Latency += device->FixedLatency;
return ret;
diff --git a/alc/device.cpp b/alc/device.cpp
index 41ef6d44..01153d51 100644
--- a/alc/device.cpp
+++ b/alc/device.cpp
@@ -25,17 +25,8 @@ using voidp = void*;
} // namespace
-/* This should be in core/device.cpp. */
-DeviceBase::DeviceBase(DeviceType type) : Type{type}, mContexts{&sEmptyContextArray}
-{
-}
-
-DeviceBase::~DeviceBase()
-{
- auto *oldarray = mContexts.exchange(nullptr, std::memory_order_relaxed);
- if(oldarray != &sEmptyContextArray) delete oldarray;
-}
-
+ALCdevice::ALCdevice(DeviceType type) : DeviceBase{type}
+{ }
ALCdevice::~ALCdevice()
{
diff --git a/alc/device.h b/alc/device.h
index 09d072a1..4798d422 100644
--- a/alc/device.h
+++ b/alc/device.h
@@ -2,6 +2,7 @@
#define ALC_DEVICE_H
#include <atomic>
+#include <memory>
#include <mutex>
#include <stdint.h>
#include <string>
@@ -20,6 +21,7 @@
struct ALbuffer;
struct ALeffect;
struct ALfilter;
+struct BackendBase;
using uint = unsigned int;
@@ -71,6 +73,13 @@ struct FilterSubList {
struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
+ /* This lock protects the device state (format, update size, etc) from
+ * being from being changed in multiple threads, or being accessed while
+ * being changed. It's also used to serialize calls to the backend.
+ */
+ std::mutex StateLock;
+ std::unique_ptr<BackendBase> Backend;
+
ALCuint NumMonoSources{};
ALCuint NumStereoSources{};
@@ -98,7 +107,7 @@ struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
al::vector<FilterSubList> FilterList;
- ALCdevice(DeviceType type) : DeviceBase{type} { }
+ ALCdevice(DeviceType type);
~ALCdevice();
void enumerateHrtfs();