Browse Source

Alternative approach to postponed rt events

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.1-rc2
falkTX 4 years ago
parent
commit
27548ae652
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 36 additions and 43 deletions
  1. +3
    -0
      source/backend/plugin/CarlaPlugin.cpp
  2. +2
    -4
      source/backend/plugin/CarlaPluginInternal.cpp
  3. +17
    -12
      source/backend/plugin/CarlaPluginInternal.hpp
  4. +10
    -5
      source/utils/LinkedList.hpp
  5. +4
    -22
      source/utils/RtLinkedList.hpp

+ 3
- 0
source/backend/plugin/CarlaPlugin.cpp View File

@@ -2061,6 +2061,9 @@ void CarlaPlugin::idle()

ProtectedData::PostRtEvents::Access rtEvents(pData->postRtEvents);

if (rtEvents.isEmpty())
return;

for (RtLinkedList<PluginPostRtEvent>::Itenerator it = rtEvents.getDataIterator(); it.valid(); it.next())
{
const PluginPostRtEvent& event(it.getValue(kPluginPostRtEventFallback));


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

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

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

@@ -602,7 +601,6 @@ CarlaPlugin::ProtectedData::PostRtEvents::~PostRtEvents() noexcept
void CarlaPlugin::ProtectedData::PostRtEvents::appendRT(const PluginPostRtEvent& e) noexcept
{
CARLA_SAFE_ASSERT_INT2_RETURN(dataPendingMutex.tryLock(), e.type, e.value1,);

dataPendingRT.append(e);
dataPendingMutex.unlock();
}
@@ -611,7 +609,7 @@ void CarlaPlugin::ProtectedData::PostRtEvents::trySplice() noexcept
{
const CarlaMutexTryLocker cmtl(dataPendingMutex);

if (cmtl.wasLocked() && dataPendingRT.count() > 0 && dataMutex.tryLock())
if (cmtl.wasLocked() && dataPendingRT.isNotEmpty() && dataMutex.tryLock())
{
dataPendingRT.moveTo(data, true);
dataMutex.unlock();


+ 17
- 12
source/backend/plugin/CarlaPluginInternal.hpp View File

@@ -310,32 +310,37 @@ struct CarlaPlugin::ProtectedData {

struct Access {
Access(PostRtEvents& e)
: cml(e.dataMutex),
data(e.data),
it(e.data.begin2()) {}
: data2(e.dataPool)
{
const CarlaMutexLocker cml(e.dataMutex);

if (e.data.isNotEmpty())
e.data.moveTo(data2, true);
}

~Access()
{
data.clear();
data2.clear();
}

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

inline std::size_t isEmpty() const noexcept
{
return data2.isEmpty();
}

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

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

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

CARLA_DECLARE_NON_COPY_CLASS(PostRtEvents)


+ 10
- 5
source/utils/LinkedList.hpp View File

@@ -1,6 +1,6 @@
/*
* High-level, templated, C++ doubly-linked list
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2013-2020 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -224,14 +224,19 @@ public:
_init();
}

std::size_t count() const noexcept
inline std::size_t count() const noexcept
{
return fCount;
}

bool isEmpty() const noexcept
inline bool isEmpty() const noexcept
{
return (fCount == 0);
return fCount == 0;
}

inline bool isNotEmpty() const noexcept
{
return fCount != 0;
}

bool append(const T& value) noexcept
@@ -352,7 +357,7 @@ public:
}

// move data to a new list, and clear ourselves
bool moveTo(AbstractLinkedList<T>& list, const bool inTail = true) noexcept
virtual bool moveTo(AbstractLinkedList<T>& list, const bool inTail = true) noexcept
{
CARLA_SAFE_ASSERT_RETURN(fCount > 0, false);



+ 4
- 22
source/utils/RtLinkedList.hpp View File

@@ -41,7 +41,8 @@ public:
: kDataSize(sizeof(typename AbstractLinkedList<T>::Data)),
fHandle(nullptr)
{
resize(minPreallocated, maxPreallocated);
rtsafe_memory_pool_create(&fHandle, nullptr, kDataSize, minPreallocated, maxPreallocated);
CARLA_SAFE_ASSERT(fHandle != nullptr);
}

~Pool() noexcept
@@ -70,18 +71,6 @@ public:
rtsafe_memory_pool_deallocate(fHandle, dataPtr);
}

void resize(const std::size_t minPreallocated, const std::size_t maxPreallocated) noexcept
{
if (fHandle != nullptr)
{
rtsafe_memory_pool_destroy(fHandle);
fHandle = nullptr;
}

rtsafe_memory_pool_create(&fHandle, nullptr, kDataSize, minPreallocated, maxPreallocated);
CARLA_SAFE_ASSERT(fHandle != nullptr);
}

bool operator==(const Pool& pool) const noexcept
{
return (fHandle == pool.fHandle && kDataSize == pool.kDataSize);
@@ -180,17 +169,10 @@ public:
return _add_sleepy(value, false);
}

void resize(const std::size_t minPreallocated, const std::size_t maxPreallocated) noexcept
bool moveTo(AbstractLinkedList<T>& list, const bool inTail) noexcept override
{
CARLA_SAFE_ASSERT(this->fCount == 0);
this->clear();

fMemPool.resize(minPreallocated, maxPreallocated);
}
CARLA_SAFE_ASSERT_RETURN(((RtLinkedList&)list).fMemPool == fMemPool, false);

bool moveTo(RtLinkedList<T>& list, const bool inTail) noexcept
{
// FIXME add some checks?
return AbstractLinkedList<T>::moveTo(list, inTail);
}



Loading…
Cancel
Save