From 320da29922f8a9aa2df0a9454818ddf03bc0124f Mon Sep 17 00:00:00 2001 From: Greg Zharun Date: Fri, 10 Apr 2015 18:08:13 +0300 Subject: [Summary] AudioPort buffer does not need 64 byte alignment which cache_aligned_malloc provides. Added new function which accepts argument to specify required alignment. AudioPort buffer requires 32 byte alignment [Review Required] YPosdnyakov --- libs/pbd/malign.cc | 41 +++++++++++++++++++++++++++++++++++++++++ libs/pbd/pbd/malign.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/libs/pbd/malign.cc b/libs/pbd/malign.cc index a5f966c0c5..e9695cd91c 100644 --- a/libs/pbd/malign.cc +++ b/libs/pbd/malign.cc @@ -47,6 +47,8 @@ int cache_aligned_malloc (void** memptr, size_t size) return 0; } #else + std::string << string_compose (_("Memory allocation error: malloc (%1 * %2)"), + CPU_CACHE_ALIGN, size) << endmsg; if (((*memptr) = malloc (size)) == 0) { fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"), CPU_CACHE_ALIGN, size, strerror (errno)) << endmsg; @@ -72,4 +74,43 @@ void cache_aligned_free (void* memptr) #else free (memptr); #endif +} + +int aligned_malloc (void** memptr, size_t size, size_t alignment) +{ +#ifndef HAVE_POSIX_MEMALIGN +#ifdef PLATFORM_WINDOWS + if (((*memptr) = _aligned_malloc (size, alignment)) == 0) { + fatal << string_compose (_("Memory allocation error: malloc (%1 * %2) failed (%3)"), + alignment, 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)"), + alignment, size, strerror (errno)) << endmsg; + return errno; + } else { + return 0; + } +#endif +#else + if (posix_memalign (memptr, alignment, size)) { + fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"), + alignment, size, strerror (errno)) << endmsg; + } + + return 0; +#endif +} + +void 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 ecee47c4e6..09d182fa40 100644 --- a/libs/pbd/pbd/malign.h +++ b/libs/pbd/pbd/malign.h @@ -27,4 +27,7 @@ LIBPBD_API int cache_aligned_malloc (void** memptr, size_t size); LIBPBD_API void cache_aligned_free (void* memptr); +LIBPBD_API int aligned_malloc (void** memptr, size_t size, size_t alignment); +LIBPBD_API void aligned_free (void* memptr); + #endif /* __pbd_malign_h__ */ -- cgit v1.2.3