mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-14 20:40:03 +02:00
Move memory mapping setup to a function
So we don't need to repeat this twice.
This commit is contained in:
+23
-24
@@ -21,14 +21,7 @@ AudioShmBuffer::AudioShmBuffer(const Config& config)
|
||||
shm(boost::interprocess::open_or_create,
|
||||
config.name.c_str(),
|
||||
boost::interprocess::read_write) {
|
||||
// Apparently you get a `Resource temporarily unavailable` when calling
|
||||
// `ftruncate()` with a size of 0 on shared memory
|
||||
if (config.size > 0) {
|
||||
shm.truncate(config.size);
|
||||
buffer = boost::interprocess::mapped_region(
|
||||
shm, boost::interprocess::read_write, 0, config.size, nullptr,
|
||||
MAP_LOCKED);
|
||||
}
|
||||
setup_mapping();
|
||||
}
|
||||
|
||||
AudioShmBuffer::~AudioShmBuffer() noexcept {
|
||||
@@ -40,22 +33,6 @@ AudioShmBuffer::~AudioShmBuffer() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void AudioShmBuffer::resize(const Config& new_config) {
|
||||
if (new_config.name != config.name) {
|
||||
throw std::invalid_argument("Expected buffer configuration for \"" +
|
||||
config.name + "\", got \"" +
|
||||
new_config.name + "\"");
|
||||
}
|
||||
|
||||
config = new_config;
|
||||
if (config.size > 0) {
|
||||
shm.truncate(config.size);
|
||||
buffer = boost::interprocess::mapped_region(
|
||||
shm, boost::interprocess::read_write, 0, config.size, nullptr,
|
||||
MAP_LOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
AudioShmBuffer::AudioShmBuffer(AudioShmBuffer&& o) noexcept
|
||||
: config(std::move(o.config)),
|
||||
shm(std::move(o.shm)),
|
||||
@@ -71,3 +48,25 @@ AudioShmBuffer& AudioShmBuffer::operator=(AudioShmBuffer&& o) noexcept {
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void AudioShmBuffer::resize(const Config& new_config) {
|
||||
if (new_config.name != config.name) {
|
||||
throw std::invalid_argument("Expected buffer configuration for \"" +
|
||||
config.name + "\", got \"" +
|
||||
new_config.name + "\"");
|
||||
}
|
||||
|
||||
config = new_config;
|
||||
setup_mapping();
|
||||
}
|
||||
|
||||
void AudioShmBuffer::setup_mapping() {
|
||||
// Apparently you get a `Resource temporarily unavailable` when calling
|
||||
// `ftruncate()` with a size of 0 on shared memory
|
||||
if (config.size > 0) {
|
||||
shm.truncate(config.size);
|
||||
buffer = boost::interprocess::mapped_region(
|
||||
shm, boost::interprocess::read_write, 0, config.size, nullptr,
|
||||
MAP_LOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user