From: Luca Barbato <[email protected]>

Signed-off-by: Vittorio Giovara <[email protected]>
---
So, any objection to the proposed patch?
Although might not be immediately useful, there could be occurrences where it 
is.
Vittorio

 configure           |  2 ++
 libavutil/mem.c     | 26 ++++++++++++++++++++++----
 libavutil/version.h |  2 +-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index c1e516c..04089ef 100755
--- a/configure
+++ b/configure
@@ -1154,6 +1154,7 @@ EXTERNAL_LIBRARY_LIST="
     bzlib
     frei0r
     gnutls
+    jemalloc
     libbs2b
     libcdio
     libdc1394
@@ -4278,6 +4279,7 @@ enabled avisynth          && { check_lib2 
"avisynth/avisynth_c.h windows.h" Load
                                die "ERROR: LoadLibrary/dlopen not found, or 
avisynth header not found"; }
 enabled frei0r            && { check_header frei0r.h || die "ERROR: frei0r.h 
header not found"; }
 enabled gnutls            && require_pkg_config gnutls gnutls/gnutls.h 
gnutls_global_init
+enabled jemalloc          && require2 jemalloc "jemalloc/jemalloc.h" rallocm 
-ljemalloc
 enabled libbs2b           && require_pkg_config libbs2b bs2b.h bs2b_open
 enabled libdcadec         && require libdcadec libdcadec/dca_context.h 
dcadec_context_create -ldcadec
 enabled libfaac           && require2 libfaac "stdint.h faac.h" 
faacEncGetVersion -lfaac
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 15c2880..e540876 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -30,7 +30,9 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-#if HAVE_MALLOC_H
+#if CONFIG_JEMALLOC
+#include <jemalloc/jemalloc.h>
+#elif HAVE_MALLOC_H
 #include <malloc.h>
 #endif

@@ -70,7 +72,10 @@ void *av_malloc(size_t size)
     if (size > (INT_MAX - 32) || !size)
         return NULL;

-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+    if (allocm(&ptr, NULL, size, ALLOCM_ALIGN(32)))
+        ptr = NULL;
+#elif CONFIG_MEMALIGN_HACK
     ptr = malloc(size + 32);
     if (!ptr)
         return ptr;
@@ -124,7 +129,17 @@ void *av_realloc(void *ptr, size_t size)
     if (size > (INT_MAX - 16))
         return NULL;

-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+    if (!size) {
+        av_free(ptr);
+        return NULL;
+    }
+    if (!ptr)
+        return av_malloc(size);
+    if (rallocm(&ptr, NULL, size, 0, ALLOCM_ALIGN(32)))
+        return NULL;
+    return ptr;
+#elif CONFIG_MEMALIGN_HACK
     //FIXME this isn't aligned correctly, though it probably isn't needed
     if (!ptr)
         return av_malloc(size);
@@ -189,7 +204,10 @@ int av_reallocp_array(void *ptr, size_t nmemb, size_t size)

 void av_free(void *ptr)
 {
-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+    if (ptr)
+        dallocm(ptr, ALLOCM_ALIGN(32));
+#elif CONFIG_MEMALIGN_HACK
     if (ptr)
         free((char *)ptr - ((char *)ptr)[-1]);
 #elif HAVE_ALIGNED_MALLOC
diff --git a/libavutil/version.h b/libavutil/version.h
index c3342cd..5785bbd 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -55,7 +55,7 @@

 #define LIBAVUTIL_VERSION_MAJOR 54
 #define LIBAVUTIL_VERSION_MINOR 14
-#define LIBAVUTIL_VERSION_MICRO  0
+#define LIBAVUTIL_VERSION_MICRO  1

 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \
--
1.9.5 (Apple Git-50.3)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to