Browse Source

Protect Post-RT events with RAII, use separate pool for pending data

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.1-rc2
falkTX 4 years ago
parent
commit
6b2f607169
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 28 additions and 30 deletions
  1. +2
    -4
      source/backend/plugin/CarlaPlugin.cpp
  2. +2
    -11
      source/backend/plugin/CarlaPluginInternal.cpp
  3. +23
    -13
      source/backend/plugin/CarlaPluginInternal.hpp
  4. +1
    -2
      source/utils/RtLinkedList.hpp

+ 2
- 4
source/backend/plugin/CarlaPlugin.cpp View File

@@ -2059,9 +2059,9 @@ void CarlaPlugin::idle()
#endif
}

const CarlaMutexLocker sl(pData->postRtEvents.getDataMutex());
ProtectedData::PostRtEvents::Access rtEvents(pData->postRtEvents);

for (RtLinkedList<PluginPostRtEvent>::Itenerator it = pData->postRtEvents.getDataIterator(); it.valid(); it.next())
for (RtLinkedList<PluginPostRtEvent>::Itenerator it = rtEvents.getDataIterator(); it.valid(); it.next())
{
const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));
CARLA_SAFE_ASSERT_CONTINUE(event.type != kPluginPostRtEventNull);
@@ -2246,8 +2246,6 @@ void CarlaPlugin::idle()
} break;
}
}

pData->postRtEvents.clearData();
}

bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept


+ 2
- 11
source/backend/plugin/CarlaPluginInternal.cpp View File

@@ -581,8 +581,9 @@ void CarlaPlugin::ProtectedData::Latency::recreateBuffers(const uint32_t newChan

CarlaPlugin::ProtectedData::PostRtEvents::PostRtEvents() noexcept
: dataPool(128, 128),
dataPendingRT(dataPool),
dataPoolRT(256, 256),
data(dataPool),
dataPendingRT(dataPoolRT),
dataMutex(),
dataPendingMutex() {}

@@ -617,16 +618,6 @@ void CarlaPlugin::ProtectedData::PostRtEvents::trySplice() noexcept
}
}

void CarlaPlugin::ProtectedData::PostRtEvents::clearData() noexcept
{
const bool tryLockOk(dataMutex.tryLock());
CARLA_SAFE_ASSERT(! tryLockOk);
data.clear();

if (tryLockOk)
dataMutex.unlock();
}

// -----------------------------------------------------------------------
// ProtectedData::PostUiEvents



+ 23
- 13
source/backend/plugin/CarlaPluginInternal.hpp View File

@@ -307,25 +307,35 @@ struct CarlaPlugin::ProtectedData {
~PostRtEvents() noexcept;
void appendRT(const PluginPostRtEvent& event) noexcept;
void trySplice() noexcept;
void clearData() noexcept;

inline CarlaMutex& getDataMutex() noexcept
{
return dataMutex;
}
struct Access {
Access(PostRtEvents& e)
: cml(e.dataMutex),
data(e.data),
it(e.data.begin2()) {}

inline RtLinkedList<PluginPostRtEvent>::Itenerator getDataIterator() const noexcept
{
return data.begin2();
}
~Access()
{
data.clear();
}

inline RtLinkedList<PluginPostRtEvent>::Itenerator& getDataIterator() noexcept
{
return it;
}

private:
const CarlaMutexLocker cml;
RtLinkedList<PluginPostRtEvent>& data;
RtLinkedList<PluginPostRtEvent>::Itenerator it;
};

private:
RtLinkedList<PluginPostRtEvent>::Pool dataPool;
RtLinkedList<PluginPostRtEvent> dataPendingRT;
RtLinkedList<PluginPostRtEvent> data;
RtLinkedList<PluginPostRtEvent>::Pool dataPool, dataPoolRT;
RtLinkedList<PluginPostRtEvent> data, dataPendingRT;
CarlaMutex dataMutex;

// TESTING for thread-safety, remove later
// TESTING for thread-safety, remove later?
CarlaMutex dataPendingMutex;

CARLA_DECLARE_NON_COPY_CLASS(PostRtEvents)


+ 1
- 2
source/utils/RtLinkedList.hpp View File

@@ -190,8 +190,7 @@ public:

bool moveTo(RtLinkedList<T>& list, const bool inTail) noexcept
{
CARLA_SAFE_ASSERT_RETURN(fMemPool == list.fMemPool, false);

// FIXME add some checks?
return AbstractLinkedList<T>::moveTo(list, inTail);
}



Loading…
Cancel
Save