Browse Source

Add CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION; Fix RingBuffer for effc++

tags/1.9.4
falkTX 10 years ago
parent
commit
d5f8f0c5ba
2 changed files with 26 additions and 15 deletions
  1. +11
    -0
      source/includes/CarlaDefines.h
  2. +15
    -15
      source/utils/CarlaRingBuffer.hpp

+ 11
- 0
source/includes/CarlaDefines.h View File

@@ -209,6 +209,17 @@ private: \
static void operator delete(void*);
#endif

/* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
#ifdef CARLA_PROPER_CPP11_SUPPORT
# define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
private: \
static void* operator new(size_t) = delete;
#else
# define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
private: \
static void* operator new(size_t);
#endif

/* Define EXTERN_C */
#ifdef __cplusplus
# define EXTERN_C extern "C"


+ 15
- 15
source/utils/CarlaRingBuffer.hpp View File

@@ -75,6 +75,9 @@ struct BigStackBuffer {
uint8_t buf[size];
};

#define HeapBuffer_INIT {0, 0, 0, 0, false, nullptr}
#define StackBuffer_INIT {0, 0, 0, false, {0}}

// -----------------------------------------------------------------------
// CarlaRingBuffer templated class

@@ -85,12 +88,9 @@ public:
CarlaRingBuffer() noexcept
: fBuffer(nullptr) {}

CarlaRingBuffer(BufferStruct* const ringBuf) noexcept
: fBuffer(ringBuf)
{
if (ringBuf != nullptr)
clear();
}
virtual ~CarlaRingBuffer() noexcept {}

// -------------------------------------------------------------------

void clear() noexcept
{
@@ -376,7 +376,7 @@ protected:
private:
BufferStruct* fBuffer;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(CarlaRingBuffer)
};

@@ -387,12 +387,9 @@ class CarlaHeapRingBuffer : public CarlaRingBuffer<HeapBuffer>
{
public:
CarlaHeapRingBuffer() noexcept
: CarlaRingBuffer<HeapBuffer>()
{
carla_zeroStruct(fHeapBuffer);
}
: fHeapBuffer(HeapBuffer_INIT) {}

~CarlaHeapRingBuffer() noexcept
~CarlaHeapRingBuffer() noexcept override
{
if (fHeapBuffer.buf == nullptr)
return;
@@ -430,7 +427,7 @@ public:
private:
HeapBuffer fHeapBuffer;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(CarlaHeapRingBuffer)
};

@@ -441,12 +438,15 @@ class CarlaStackRingBuffer : public CarlaRingBuffer<StackBuffer>
{
public:
CarlaStackRingBuffer() noexcept
: CarlaRingBuffer<StackBuffer>(&fStackBuffer) {}
: fStackBuffer(StackBuffer_INIT)
{
setRingBuffer(&fStackBuffer, true); // FIXME
}

private:
StackBuffer fStackBuffer;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(CarlaStackRingBuffer)
};



Loading…
Cancel
Save