diff options
author | Greg Zharun <grygoriiz@wavesglobal.com> | 2015-04-10 18:08:13 +0300 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2015-06-29 14:18:14 -0400 |
commit | 320da29922f8a9aa2df0a9454818ddf03bc0124f (patch) | |
tree | e564a4aa4305fc01202c09e386ad1a01328f5af8 /libs/pbd | |
parent | 237f255fb51d02bf312c04900ecd9a37579ff9f8 (diff) |
[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
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/malign.cc | 41 | ||||
-rw-r--r-- | libs/pbd/pbd/malign.h | 3 |
2 files changed, 44 insertions, 0 deletions
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__ */ |