[x264-devel] [PATCH] Check whether posix_madvise exists.

Xiaolei Yu dreifachstein at gmail.com
Thu Nov 12 09:30:35 CET 2015


Android supports mmap but does not expose posix_madvise.
---
 configure     | 3 ++-
 input/input.c | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 4cb5da1..24de369 100755
--- a/configure
+++ b/configure
@@ -374,7 +374,7 @@ NL="
 # list of all preprocessor HAVE values we can define
 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
              LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
-             MSA MMAP"
+             MSA MMAP POSIX_MADVISE"
 
 # parse options
 
@@ -973,6 +973,7 @@ fi
 
 if [ "$SYS" != "WINDOWS" ] && [ "$SYS" != "CYGWIN" ] && cc_check "sys/mman.h unistd.h" ; then
     define HAVE_MMAP
+    cc_check 'sys/mman.h' '' 'posix_madvise(0, 0, 0);' && define HAVE_POSIX_MADVISE
 fi
 
 if [ "$SYS" = "LINUX" -a \( "$ARCH" = "X86" -o "$ARCH" = "X86_64" \) ] && cc_check "sys/mman.h" "" "MADV_HUGEPAGE;" ; then
diff --git a/input/input.c b/input/input.c
index 27e4043..03be61d 100644
--- a/input/input.c
+++ b/input/input.c
@@ -180,9 +180,11 @@ void *x264_cli_mmap( cli_mmap_t *h, int64_t offset, size_t size )
     uint8_t *base = mmap( NULL, size, PROT_READ, MAP_PRIVATE, h->fd, offset );
     if( base != MAP_FAILED )
     {
+#if HAVE_POSIX_MADVISE
         /* Ask the OS to readahead pages. This improves performance whereas
          * forcing page faults by manually accessing every page does not. */
         posix_madvise( base, size, POSIX_MADV_WILLNEED );
+#endif
         return base + align;
     }
 #endif
-- 
2.6.2




More information about the x264-devel mailing list