[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
This commit is contained in:
Greg Zharun 2015-04-10 18:08:13 +03:00 committed by Paul Davis
parent 237f255fb5
commit 320da29922
2 changed files with 44 additions and 0 deletions

View file

@ -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
}

View file

@ -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__ */