mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
memory: respect configured alignment
Move the alignment from GstBuffer to GstMemory. make sure memory is at least aligned to the configured values.
This commit is contained in:
parent
b27ee30a35
commit
17ff81fc7d
3 changed files with 32 additions and 33 deletions
18
configure.ac
18
configure.ac
|
@ -556,22 +556,22 @@ dnl bit of a misnomer, but keep the conditional named like this so we don't
|
|||
dnl have to change too much elsewhere
|
||||
AM_CONDITIONAL(HAVE_CHECK, test "x$BUILD_CHECK" = "xyes")
|
||||
|
||||
dnl configure the desired buffer alignment
|
||||
AC_ARG_WITH([buffer-alignment],
|
||||
AS_HELP_STRING([--with-buffer-alignment],[8,N,malloc,pagesize (default is 32)]),
|
||||
dnl configure the desired memory alignment
|
||||
AC_ARG_WITH([memory-alignment],
|
||||
AS_HELP_STRING([--with-memory-alignment],[8,N,malloc,pagesize (default is 32)]),
|
||||
[
|
||||
if test "x$withval" = "xyes"
|
||||
then
|
||||
AC_DEFINE(BUFFER_ALIGNMENT, 32, [Buffer alignment to use])
|
||||
AC_DEFINE(MEMORY_ALIGNMENT, 32, [Memory alignment to use])
|
||||
else
|
||||
case "${withval}" in
|
||||
malloc) AC_DEFINE(BUFFER_ALIGNMENT_MALLOC, 1, [Buffer alignment by malloc default]) ;;
|
||||
pagesize) AC_DEFINE(BUFFER_ALIGNMENT_PAGESIZE, 1, [Buffer alignment by pagesize]) ;;
|
||||
*) AC_DEFINE_UNQUOTED(BUFFER_ALIGNMENT, ${withval}, [Buffer alignment to use]) ;;
|
||||
malloc) AC_DEFINE(MEMORY_ALIGNMENT_MALLOC, 1, [Memory alignment by malloc default]) ;;
|
||||
pagesize) AC_DEFINE(MEMORY_ALIGNMENT_PAGESIZE, 1, [Memory alignment by pagesize]) ;;
|
||||
*) AC_DEFINE_UNQUOTED(MEMORY_ALIGNMENT, ${withval}, [Memory alignment to use]) ;;
|
||||
esac
|
||||
fi
|
||||
], [
|
||||
AC_DEFINE(BUFFER_ALIGNMENT_MALLOC, 1, [Buffer alignment by malloc default])
|
||||
AC_DEFINE(MEMORY_ALIGNMENT_MALLOC, 1, [Memory alignment by malloc default])
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -798,7 +798,7 @@ sed \
|
|||
-e 's/.* HAVE_WIN32$/#define HAVE_WIN32 1/' \
|
||||
-e 's/.* HAVE_WINSOCK2_H$/#define HAVE_WINSOCK2_H 1/' \
|
||||
-e 's/.* HOST_CPU$/#define HOST_CPU "i686"/' \
|
||||
-e 's/.* BUFFER_ALIGNMENT_MALLOC/#define BUFFER_ALIGNMENT_MALLOC 1/' \
|
||||
-e 's/.* MEMORY_ALIGNMENT_MALLOC/#define MEMORY_ALIGNMENT_MALLOC 1/' \
|
||||
-e 's/.* LIBDIR$/#ifdef _DEBUG\n# define LIBDIR PREFIX "\\\\debug\\\\lib"\n#else\n# define LIBDIR PREFIX "\\\\lib"\n#endif/' \
|
||||
-e 's/.* LOCALEDIR$/#define LOCALEDIR PREFIX "\\\\share\\\\locale"/' \
|
||||
-e 's/.* PACKAGE$/#define PACKAGE "gstreamer"/' \
|
||||
|
|
|
@ -211,35 +211,11 @@ _memory_add (GstBuffer * buffer, GstMemory * mem)
|
|||
GST_BUFFER_MEM_LEN (buffer) = len + 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* buffer alignment in bytes - 1
|
||||
* an alignment of 7 would be the same as malloc() guarantees
|
||||
*/
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
#if defined(BUFFER_ALIGNMENT_MALLOC)
|
||||
static size_t _gst_buffer_data_alignment = 7;
|
||||
#elif defined(BUFFER_ALIGNMENT_PAGESIZE)
|
||||
static size_t _gst_buffer_data_alignment = 0;
|
||||
#elif defined(BUFFER_ALIGNMENT)
|
||||
static size_t _gst_buffer_data_alignment = BUFFER_ALIGNMENT - 1;
|
||||
#else
|
||||
#error "No buffer alignment configured"
|
||||
#endif
|
||||
#endif /* HAVE_POSIX_MEMALIGN */
|
||||
#endif
|
||||
|
||||
void
|
||||
_gst_buffer_initialize (void)
|
||||
{
|
||||
if (G_LIKELY (_gst_buffer_type == 0)) {
|
||||
_gst_buffer_type = gst_mini_object_register ("GstBuffer");
|
||||
#if 0
|
||||
#ifdef HAVE_GETPAGESIZE
|
||||
#ifdef BUFFER_ALIGNMENT_PAGESIZE
|
||||
_gst_buffer_data_alignment = getpagesize () - 1;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,21 @@
|
|||
#include "gstmemory.h"
|
||||
|
||||
|
||||
/* buffer alignment in bytes - 1
|
||||
* an alignment of 7 would be the same as malloc() guarantees
|
||||
*/
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
#if defined(MEMORY_ALIGNMENT_MALLOC)
|
||||
static size_t _gst_memory_alignment = 7;
|
||||
#elif defined(MEMORY_ALIGNMENT_PAGESIZE)
|
||||
static size_t _gst_memory_alignment = 0;
|
||||
#elif defined(MEMORY_ALIGNMENT)
|
||||
static size_t _gst_memory_alignment = MEMORY_ALIGNMENT - 1;
|
||||
#else
|
||||
#error "No memory alignment configured"
|
||||
#endif
|
||||
#endif /* HAVE_POSIX_MEMALIGN */
|
||||
|
||||
struct _GstMemoryAllocator
|
||||
{
|
||||
GQuark name;
|
||||
|
@ -131,6 +146,8 @@ _default_mem_new_block (gsize maxsize, gsize align, gsize offset, gsize size)
|
|||
gsize aoffset, slice_size;
|
||||
guint8 *data;
|
||||
|
||||
/* ensure configured alignment */
|
||||
align |= _gst_memory_alignment;
|
||||
/* allocate more to compensate for alignment */
|
||||
maxsize += align;
|
||||
/* alloc header and data in one block */
|
||||
|
@ -300,6 +317,12 @@ _gst_memory_init (void)
|
|||
|
||||
allocators = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
#ifdef HAVE_GETPAGESIZE
|
||||
#ifdef MEMORY_ALIGNMENT_PAGESIZE
|
||||
_gst_memory_alignment = getpagesize () - 1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_default_mem_impl =
|
||||
gst_memory_allocator_register ("GstMemoryDefault", &_mem_info);
|
||||
|
||||
|
|
Loading…
Reference in a new issue