Browse Source

Continue cleanup; RtList C++ class objects support

tags/1.9.4
falkTX 12 years ago
parent
commit
741c649d40
12 changed files with 118 additions and 123 deletions
  1. +11
    -10
      source/backend/CarlaBackend.hpp
  2. +13
    -0
      source/includes/CarlaDefines.hpp
  3. +13
    -7
      source/includes/lv2_rdf.hpp
  4. +3
    -3
      source/modules/rtmempool/list.h
  5. +2
    -1
      source/modules/utils/CarlaBridgeUtils.hpp
  6. +2
    -0
      source/modules/utils/CarlaMutex.hpp
  7. +8
    -2
      source/modules/utils/CarlaRingBuffer.hpp
  8. +3
    -1
      source/modules/utils/CarlaString.hpp
  9. +38
    -72
      source/modules/utils/RtList.hpp
  10. +18
    -9
      source/tests/ANSI.cpp
  11. +3
    -3
      source/tests/Makefile
  12. +4
    -15
      source/tests/RtList.cpp

+ 11
- 10
source/backend/CarlaBackend.hpp View File

@@ -144,16 +144,17 @@ enum BinaryType {
* Some plugin classes might provide more than 1 plugin type.
*/
enum PluginType {
PLUGIN_NONE = 0, //!< Null plugin type.
PLUGIN_INTERNAL = 1, //!< Internal plugin.
PLUGIN_LADSPA = 2, //!< LADSPA plugin.
PLUGIN_DSSI = 3, //!< DSSI plugin.
PLUGIN_LV2 = 4, //!< LV2 plugin.
PLUGIN_VST = 5, //!< VST1/2 plugin.
PLUGIN_VST3 = 6, //!< VST3 plugin.
PLUGIN_GIG = 7, //!< GIG sound kit.
PLUGIN_SF2 = 8, //!< SF2 sound kit (aka SoundFont).
PLUGIN_SFZ = 9 //!< SFZ sound kit.
PLUGIN_NONE = 0, //!< Null plugin type.
PLUGIN_INTERNAL = 1, //!< Internal plugin.
PLUGIN_LADSPA = 2, //!< LADSPA plugin.
PLUGIN_DSSI = 3, //!< DSSI plugin.
PLUGIN_LV2 = 4, //!< LV2 plugin.
PLUGIN_VST = 5, //!< VST1/2 plugin.
PLUGIN_VST3 = 6, //!< VST3 plugin.
PLUGIN_AU = 7, //!< AU plugin.
PLUGIN_GIG = 8, //!< GIG sound kit.
PLUGIN_SF2 = 9, //!< SF2 sound kit (aka SoundFont).
PLUGIN_SFZ = 10 //!< SFZ sound kit.
};

/*!


+ 13
- 0
source/includes/CarlaDefines.hpp View File

@@ -160,4 +160,17 @@
# define OS_SEP '/'
#endif

// Define PRE/POST_PACKED_STRUCTURE
#if defined(__GNUC__)
# define PRE_PACKED_STRUCTURE
# define POST_PACKED_STRUCTURE __attribute__((__packed__))
#elif defined(_MSC_VER)
# define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
# define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
# define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
#else
# define PRE_PACKED_STRUCTURE
# define POST_PACKED_STRUCTURE
#endif

#endif // CARLA_DEFINES_HPP_INCLUDED

+ 13
- 7
source/includes/lv2_rdf.hpp View File

@@ -118,11 +118,13 @@ typedef uint32_t LV2_Property;
#define LV2_PORT_ATOM_SEQUENCE (0x040 | LV2_PORT_ATOM)
#define LV2_PORT_EVENT 0x080
#define LV2_PORT_MIDI_LL 0x100
#define LV2_PORT_OSC 0x200

// Port Data Types
#define LV2_PORT_DATA_MIDI_EVENT 0x1000
#define LV2_PORT_DATA_PATCH_MESSAGE 0x2000
#define LV2_PORT_DATA_TIME_POSITION 0x4000
#define LV2_PORT_DATA_OSC 0x2000
#define LV2_PORT_DATA_PATCH_MESSAGE 0x4000
#define LV2_PORT_DATA_TIME_POSITION 0x8000

#define LV2_IS_PORT_INPUT(x) ((x) & LV2_PORT_INPUT)
#define LV2_IS_PORT_OUTPUT(x) ((x) & LV2_PORT_OUTPUT)
@@ -132,8 +134,10 @@ typedef uint32_t LV2_Property;
#define LV2_IS_PORT_ATOM_SEQUENCE(x) ((x) & LV2_PORT_ATOM_SEQUENCE)
#define LV2_IS_PORT_EVENT(x) ((x) & LV2_PORT_EVENT)
#define LV2_IS_PORT_MIDI_LL(x) ((x) & LV2_PORT_MIDI_LL)
#define LV2_IS_PORT_OSC(x) ((x) & LV2_PORT_OSC)

#define LV2_PORT_SUPPORTS_MIDI_EVENT(x) ((x) & LV2_PORT_DATA_MIDI_EVENT)
#define LV2_PORT_SUPPORTS_OSC(x) ((x) & LV2_PORT_DATA_OSC)
#define LV2_PORT_SUPPORTS_PATCH_MESSAGE(x) ((x) & LV2_PORT_DATA_PATCH_MESSAGE)
#define LV2_PORT_SUPPORTS_TIME_POSITION(x) ((x) & LV2_PORT_DATA_TIME_POSITION)

@@ -210,16 +214,18 @@ typedef uint32_t LV2_Property;
#define LV2_UI_GTK3 2
#define LV2_UI_QT4 3
#define LV2_UI_QT5 4
#define LV2_UI_COCOA 5
#define LV2_UI_WINDOWS 6
#define LV2_UI_X11 7
#define LV2_UI_EXTERNAL 8
#define LV2_UI_OLD_EXTERNAL 9
#define LV2_UI_NTK 5
#define LV2_UI_COCOA 6
#define LV2_UI_WINDOWS 7
#define LV2_UI_X11 8
#define LV2_UI_EXTERNAL 9
#define LV2_UI_OLD_EXTERNAL 10

#define LV2_IS_UI_GTK2(x) ((x) == LV2_UI_GTK2)
#define LV2_IS_UI_GTK3(x) ((x) == LV2_UI_GTK3)
#define LV2_IS_UI_QT4(x) ((x) == LV2_UI_QT4)
#define LV2_IS_UI_QT5(x) ((x) == LV2_UI_QT5)
#define LV2_IS_UI_NTK(x) ((x) == LV2_UI_NTK)
#define LV2_IS_UI_COCOA(x) ((x) == LV2_UI_COCOA)
#define LV2_IS_UI_WINDOWS(x) ((x) == LV2_UI_WINDOWS)
#define LV2_IS_UI_X11(x) ((x) == LV2_UI_X11)


+ 3
- 3
source/modules/rtmempool/list.h View File

@@ -38,7 +38,7 @@
# include <stddef.h>
#endif

#if !defined(offsetof)
#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

@@ -51,7 +51,7 @@
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
(type *)( (char *)__mptr - offsetof(type, member) );})

#define prefetch(x) (x = x)

@@ -305,7 +305,7 @@ static inline void list_splice_tail_init(struct list_head *list, struct list_hea
container_of(ptr, type, member)
#else
# define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
((type *)((char *)(ptr)-offsetof(type, member)))
#endif

/**


+ 2
- 1
source/modules/utils/CarlaBridgeUtils.hpp View File

@@ -67,6 +67,7 @@ const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Hos

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

PRE_PACKED_STRUCTURE
struct BridgeShmControl {
union {
void* runServer;
@@ -77,7 +78,7 @@ struct BridgeShmControl {
char _padClient[32];
};
RingBuffer ringBuffer;
} __attribute__((__packed__));
} POST_PACKED_STRUCTURE;

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



+ 2
- 0
source/modules/utils/CarlaMutex.hpp View File

@@ -95,4 +95,6 @@ private:
CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaMutex)
};

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

#endif // CARLA_MUTEX_HPP_INCLUDED

+ 8
- 2
source/modules/utils/CarlaRingBuffer.hpp View File

@@ -19,7 +19,7 @@
#ifndef CARLA_RING_BUFFER_HPP_INCLUDED
#define CARLA_RING_BUFFER_HPP_INCLUDED

#include "CarlaUtils.hpp"
#include "CarlaJuceUtils.hpp"

#ifndef RING_BUFFER_SIZE
# define RING_BUFFER_SIZE 2048
@@ -28,11 +28,12 @@
// -----------------------------------------------------------------------
// RingBuffer struct

PRE_PACKED_STRUCTURE
struct RingBuffer {
int32_t head, tail, written;
bool invalidateCommit;
char buf[RING_BUFFER_SIZE];
} __attribute__((__packed__));
} POST_PACKED_STRUCTURE;

// -----------------------------------------------------------------------
// RingBufferControl class
@@ -229,6 +230,11 @@ private:

fRingBuf->written = static_cast<int32_t>(writeto);
}

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(RingBufferControl)
};

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

#endif // CARLA_RING_BUFFER_HPP_INCLUDED

+ 3
- 1
source/modules/utils/CarlaString.hpp View File

@@ -467,8 +467,8 @@ private:
}
}

CARLA_LEAK_DETECTOR(CarlaString)
CARLA_PREVENT_HEAP_ALLOCATION
CARLA_LEAK_DETECTOR(CarlaString)
};

// -----------------------------------------------------------------------
@@ -499,4 +499,6 @@ CarlaString operator+(const char* const strBufBefore, const CarlaString& strAfte
return CarlaString(newBuf);
}

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

#endif // CARLA_STRING_HPP_INCLUDED

+ 38
- 72
source/modules/utils/RtList.hpp View File

@@ -88,7 +88,7 @@ public:
T& operator*()
{
fData = list_entry(fEntry, Data, siblings);
CARLA_SAFE_ASSERT_RETURN(fData != nullptr, nullptr);
CARLA_ASSERT(fData != nullptr);
return fData->value;
}

@@ -116,7 +116,10 @@ public:
list_for_each_safe(entry, entry2, &fQueue)
{
if (Data* data = list_entry(entry, Data, siblings))
{
data->~Data();
_deallocate(data);
}
}
}

@@ -137,6 +140,7 @@ public:
{
if (Data* const data = _allocate())
{
new(data)Data();
data->value = value;
list_add_tail(&data->siblings, &fQueue);
++fCount;
@@ -150,6 +154,7 @@ public:
{
if (Data* const data = _allocate())
{
new(data)Data();
data->value = value;
list_add_tail(&data->siblings, it.fEntry->next);
++fCount;
@@ -163,6 +168,7 @@ public:
{
if (Data* const data = _allocate())
{
new(data)Data();
data->value = value;
list_add(&data->siblings, &fQueue);
++fCount;
@@ -176,6 +182,7 @@ public:
{
if (Data* const data = _allocate())
{
new(data)Data();
data->value = value;
list_add(&data->siblings, it.fEntry->prev);
++fCount;
@@ -188,7 +195,7 @@ public:
T& getAt(const size_t index, const bool remove = false)
{
if (fCount == 0 || index >= fCount)
return _getEmpty();
return fFallbackValue;

size_t i = 0;
Data* data = nullptr;
@@ -202,21 +209,25 @@ public:

data = list_entry(entry, Data, siblings);

if (data != nullptr)
fRetValue = data->value;

if (remove)
{
--fCount;
list_del(entry);

if (data != nullptr)
{
data->~Data();
_deallocate(data);
}
}

break;
}

CARLA_ASSERT(data != nullptr);

return (data != nullptr) ? data->value : _getEmpty();
return (data != nullptr) ? fRetValue : fFallbackValue;
}

T& getFirst(const bool remove = false)
@@ -238,6 +249,8 @@ public:
{
--fCount;
list_del(it.fEntry);

it.fData->~Data();
_deallocate(it.fData);
}
}
@@ -258,6 +271,8 @@ public:
{
--fCount;
list_del(entry);

data->~Data();
_deallocate(data);
break;
}
@@ -266,27 +281,6 @@ public:
return (data != nullptr);
}

void removeAll(const T& value)
{
Data* data;
k_list_head* entry;
k_list_head* entry2;

list_for_each_safe(entry, entry2, &fQueue)
{
data = list_entry(entry, Data, siblings);

CARLA_ASSERT(data != nullptr);

if (data != nullptr && data->value == value)
{
--fCount;
list_del(entry);
_deallocate(data);
}
}
}

void spliceAppend(List& list, const bool init = true)
{
if (init)
@@ -323,9 +317,12 @@ protected:
k_list_head fQueue;

virtual Data* _allocate() = 0;
virtual void _deallocate(Data* const dataPtr) = 0;
virtual void _deallocate(Data*& dataPtr) = 0;

private:
T fFallbackValue;
T fRetValue;

void _init() noexcept
{
fCount = 0;
@@ -335,33 +332,29 @@ private:
T& _getFirstOrLast(const bool first, const bool remove)
{
if (fCount == 0)
return _getEmpty();
return fFallbackValue;

k_list_head* const entry = first ? fQueue.next : fQueue.prev;
Data* const data = list_entry(entry, Data, siblings);

CARLA_SAFE_ASSERT_RETURN(data != nullptr, _getEmpty());
Data* data = list_entry(entry, Data, siblings);

T& ret = data->value;
if (data != nullptr)
fRetValue = data->value;

if (remove)
{
--fCount;
list_del(entry);
_deallocate(data);
}

return ret;
}
if (data != nullptr)
{
data->~Data();
_deallocate(data);
}
}

T& _getEmpty()
{
carla_zeroStruct<T>(fFallbackValue);
return fFallbackValue;
return (data != nullptr) ? fRetValue : fFallbackValue;
}

T fFallbackValue;

LIST_DECLARATIONS(List)
};

@@ -452,6 +445,7 @@ public:
{
if (typename List<T>::Data* const data = _allocate_sleepy())
{
new(data)typename List<T>::Data();
data->value = value;
list_add_tail(&data->siblings, &this->fQueue);
++this->fCount;
@@ -462,6 +456,7 @@ public:
{
if (typename List<T>::Data* const data = _allocate_sleepy())
{
new(data)typename List<T>::Data();
data->value = value;
list_add(&data->siblings, &this->fQueue);
++this->fCount;
@@ -518,7 +513,7 @@ private:
};

// -----------------------------------------------------------------------
// Non-Realtime list, using malloc/free methods
// Non-Realtime list

template<typename T>
class NonRtList : public List<T>
@@ -549,34 +544,5 @@ private:
};

// -----------------------------------------------------------------------
// Non-Realtime list, using new/delete methods

template<typename T>
class NonRtListNew : public List<T>
{
public:
NonRtListNew()
{
}

~NonRtListNew() override
{
}

private:
typename List<T>::Data* _allocate() override
{
return new typename List<T>::Data;
}

void _deallocate(typename List<T>::Data*& dataPtr) override
{
CARLA_ASSERT(dataPtr != nullptr);
delete dataPtr;
dataPtr = nullptr;
}

LIST_DECLARATIONS(NonRtListNew)
};

#endif // RT_LIST_HPP_INCLUDED

+ 18
- 9
source/tests/ANSI.cpp View File

@@ -40,8 +40,8 @@
#include "RtList.hpp"

// Carla utils (part 3/4)
#include "CarlaBackendUtils.hpp"
#include "CarlaBridgeUtils.hpp"
// #include "CarlaBackendUtils.hpp"
// #include "CarlaBridgeUtils.hpp"
// #include "CarlaLadspaUtils.hpp"
// #include "CarlaLibUtils.hpp"
// #include "CarlaLv2Utils.hpp"
@@ -54,19 +54,19 @@
// #include "Lv2AtomQueue.hpp"

// Carla Native Plugin API
#include "CarlaNative.h"
// #include "CarlaNative.h"

// Carla Native Plugin API (C++)
#include "CarlaNative.hpp"
// #include "CarlaNative.hpp"

// Carla Plugin API
#include "CarlaPlugin.hpp"
// #include "CarlaPlugin.hpp"

// Carla Engine API
#include "CarlaEngine.hpp"
// #include "CarlaEngine.hpp"

// Carla Standalone API
#include "CarlaStandalone.hpp"
// #include "CarlaStandalone.hpp"

// // Carla Plugin
// #include "plugin/CarlaPluginThread.hpp"
@@ -84,7 +84,6 @@ int safe_assert_return_test(bool test)

int main()
{
#if 0
// ladspa rdf
{
LADSPA_RDF_ScalePoint a;
@@ -125,6 +124,7 @@ int main()
a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;
}

#if 0
// Carla Native Plugin API
{
HostHandle a = nullptr;
@@ -158,6 +158,7 @@ int main()
a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;p=p;
(void)q;
}
#endif

// Carla common utils
{
@@ -400,6 +401,7 @@ int main()
ScopedPointer<Test> f(nullptr);
}

#if 0
// Carla Native Plugin API (C++)
{
class PluginDescriptorClassTest : public PluginDescriptorClass
@@ -456,6 +458,7 @@ int main()
assert(b.i == 5);
assert(c.i == 6);
}
#endif

// Carla Mutex
{
@@ -464,7 +467,6 @@ int main()
m.unlock();
const CarlaMutex::ScopedLocker sl(m);
}
#endif

// RingBuffer
{
@@ -526,5 +528,12 @@ int main()
printf("\nDUMP FINISHED");
}

// RtList
{
NonRtList<int> list;
list.append(6);
list.clear();
}

return 0;
}

+ 3
- 3
source/tests/Makefile View File

@@ -42,7 +42,7 @@ all: $(TARGETS) RUN
ANSI: ANSI.cpp
$(CXX) $^ $(BUILD_CXX_FLAGS) $(ANSI_CXX_FLAGS) $(LINK_FLAGS) -lpthread -o $@

CarlaString: CarlaString.cpp
CarlaString: CarlaString.cpp ../modules/utils/CarlaString.hpp
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@

DGL1: DGL1.cpp DGL1_Artwork.cpp ../libs/dgl.a
@@ -54,8 +54,8 @@ DGL2: DGL2.cpp NekoArtwork.cpp ../libs/dgl.a
MacTest: MacTest.cpp
$(CXX) MacTest.cpp -o $@

RtList: RtList.cpp ../utils/RtList.hpp ../libs/rtmempool.a
$(CXX) RtList.cpp ../libs/rtmempool.a $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -pthread -lpthread -o $@
RtList: RtList.cpp ../modules/utils/RtList.hpp ../modules/rtmempool.a
$(CXX) RtList.cpp ../modules/rtmempool.a $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -pthread -lpthread -o $@

Print: Print.cpp
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@


+ 4
- 15
source/tests/RtList.cpp View File

@@ -20,8 +20,8 @@
#include "CarlaString.hpp"
#include "CarlaMutex.hpp"

const unsigned short MIN_RT_EVENTS = 152;
const unsigned short MAX_RT_EVENTS = 512;
const unsigned short MIN_RT_EVENTS = 5;
const unsigned short MAX_RT_EVENTS = 10;

struct MyData {
CarlaString str;
@@ -33,11 +33,6 @@ struct MyData {
MyData(int id)
: str(id),
idStr(id) {}

#ifdef PROPER_CPP11_SUPPORT
MyData(MyData&) = delete;
MyData(const MyData&) = delete;
#endif
};

struct PostRtEvents {
@@ -78,11 +73,6 @@ struct PostRtEvents {
}
}

//void appendNonRT(const PluginPostRtEvent& event)
//{
// data.append_sleepy(event);
//}

} postRtEvents;

void run5Tests()
@@ -95,9 +85,8 @@ void run5Tests()

while (! postRtEvents.data.isEmpty())
{
MyData& my = postRtEvents.data.getFirst(true);
const MyData& my(postRtEvents.data.getFirst(true));
allMyData[k++] = my;
//std::memcpy(&allMyData[i++], &my, sizeof(MyData));
}

postRtEvents.mutex.unlock();
@@ -114,7 +103,7 @@ void run5Tests()
// Handle events now
for (unsigned short i=0; i < k; ++i)
{
const MyData& my = allMyData[i];
const MyData& my(allMyData[i]);

printf("Got data: %i %s\n", my.idStr, (const char*)my.str);
}


Loading…
Cancel
Save