summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Zharun <grygoriiz@wavesglobal.com>2015-04-09 13:27:57 +0300
committerPaul Davis <paul@linuxaudiosystems.com>2015-06-29 14:16:43 -0400
commit92e4f227deb5a340dad0c4dbbec5ad52d44fa391 (patch)
tree1736736c1f1667b20dcb784a1711c9eaa7bac7db
parent24c531a9a64199645783605a1e0b322b6bba095a (diff)
[Summary] Added correct memory alignment for Windows in ../pbd/malign.h
[Reviewed by] YPozdnyakov
-rw-r--r--libs/ardour/audio_buffer.cc4
-rw-r--r--libs/ardour/midi_buffer.cc4
-rw-r--r--libs/pbd/malign.cc19
-rw-r--r--libs/pbd/pbd/malign.h3
4 files changed, 25 insertions, 5 deletions
diff --git a/libs/ardour/audio_buffer.cc b/libs/ardour/audio_buffer.cc
index de2c1ddf00..6d8b2aa55f 100644
--- a/libs/ardour/audio_buffer.cc
+++ b/libs/ardour/audio_buffer.cc
@@ -43,7 +43,7 @@ AudioBuffer::AudioBuffer(size_t capacity)
AudioBuffer::~AudioBuffer()
{
if (_owns_data)
- free(_data);
+ cache_aligned_free(_data);
}
void
@@ -60,7 +60,7 @@ AudioBuffer::resize (size_t size)
return;
}
- free (_data);
+ cache_aligned_free (_data);
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index b1b09e4c98..50ff7b728f 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -44,7 +44,7 @@ MidiBuffer::MidiBuffer(size_t capacity)
MidiBuffer::~MidiBuffer()
{
- free(_data);
+ cache_aligned_free(_data);
}
void
@@ -60,7 +60,7 @@ MidiBuffer::resize(size_t size)
return;
}
- free (_data);
+ cache_aligned_free (_data);
cache_aligned_malloc ((void**) &_data, size);
diff --git a/libs/pbd/malign.cc b/libs/pbd/malign.cc
index a11a23f35f..a5f966c0c5 100644
--- a/libs/pbd/malign.cc
+++ b/libs/pbd/malign.cc
@@ -38,6 +38,15 @@ static const int CPU_CACHE_ALIGN = 16; /* arguably 32 on most arches, but it mat
int cache_aligned_malloc (void** memptr, size_t size)
{
#ifndef HAVE_POSIX_MEMALIGN
+#ifdef PLATFORM_WINDOWS
+ if (((*memptr) = _aligned_malloc (size, CPU_CACHE_ALIGN)) == 0) {
+ fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"),
+ CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg;
+ return errno;
+ } else {
+ return 0;
+ }
+#else
if (((*memptr) = malloc (size)) == 0) {
fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"),
CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg;
@@ -45,6 +54,7 @@ int cache_aligned_malloc (void** memptr, size_t size)
} else {
return 0;
}
+#endif
#else
if (posix_memalign (memptr, CPU_CACHE_ALIGN, size)) {
fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"),
@@ -54,3 +64,12 @@ int cache_aligned_malloc (void** memptr, size_t size)
return 0;
#endif
}
+
+void cache_aligned_free (void* memptr)
+{
+#ifdef PLATFORM_WINDOWS
+ _aligned_free (memptr);
+#else
+ free (memptr);
+#endif
+} \ No newline at end of file
diff --git a/libs/pbd/pbd/malign.h b/libs/pbd/pbd/malign.h
index 07f42f586f..ecee47c4e6 100644
--- a/libs/pbd/pbd/malign.h
+++ b/libs/pbd/pbd/malign.h
@@ -24,6 +24,7 @@
#include "pbd/libpbd_visibility.h"
-LIBPBD_API int cache_aligned_malloc (void** memptr, size_t size);
+LIBPBD_API int cache_aligned_malloc (void** memptr, size_t size);
+LIBPBD_API void cache_aligned_free (void* memptr);
#endif /* __pbd_malign_h__ */