From d9b3c0eef2ba256b4e1e694c3828d1f4713ebf68 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 10 Sep 2007 11:35:30 +0000 Subject: posix_madvise and posix_fadvise aren't present on all systems. git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1783 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/core-util.c | 8 +++++--- src/pulsecore/sound-file-stream.c | 2 ++ src/pulsecore/sound-file.c | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 67d33e7c..13a7252c 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1262,11 +1262,13 @@ void *pa_will_need(const void *p, size_t l) { a = PA_PAGE_ALIGN_PTR(p); size = (const uint8_t*) p + l - (const uint8_t*) a; - + +#ifdef HAVE_POSIX_MADVISE if ((r = posix_madvise((void*) a, size, POSIX_MADV_WILLNEED)) == 0) { pa_log_debug("posix_madvise() worked fine!"); return (void*) p; } +#endif /* Most likely the memory was not mmap()ed from a file and thus * madvise() didn't work, so let's misuse mlock() do page this @@ -1279,7 +1281,7 @@ void *pa_will_need(const void *p, size_t l) { pa_assert_se(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0); if (rlim.rlim_cur < PA_PAGE_SIZE) { - pa_log_debug("posix_madvise() failed, resource limits don't allow mlock(), can't page in data: %s", pa_cstrerror(r)); + pa_log_debug("posix_madvise() failed (or doesn't exist), resource limits don't allow mlock(), can't page in data: %s", pa_cstrerror(r)); return (void*) p; } @@ -1288,7 +1290,7 @@ void *pa_will_need(const void *p, size_t l) { bs = PA_PAGE_SIZE*4; #endif - pa_log_debug("posix_madvise() failed, trying mlock(): %s", pa_cstrerror(r)); + pa_log_debug("posix_madvise() failed (or doesn't exist), trying mlock(): %s", pa_cstrerror(r)); while (size > 0 && bs > 0) { diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c index 36c7f03c..d5523a64 100644 --- a/src/pulsecore/sound-file-stream.c +++ b/src/pulsecore/sound-file-stream.c @@ -255,6 +255,7 @@ int pa_play_file( * file reader into the main event loop and pass the data over the * asyncmsgq. */ +#ifdef HAVE_POSIX_FADVISE if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL) < 0) { pa_log_warn("POSIX_FADV_SEQUENTIAL failed: %s", pa_cstrerror(errno)); goto fail; @@ -266,6 +267,7 @@ int pa_play_file( goto fail; } else pa_log_debug("POSIX_FADV_WILLNEED succeeded."); +#endif if (!(u->sndfile = sf_open_fd(fd, SFM_READ, &sfinfo, 1))) { pa_log("Failed to open file %s", fname); diff --git a/src/pulsecore/sound-file.c b/src/pulsecore/sound-file.c index ef43eef0..8727ba15 100644 --- a/src/pulsecore/sound-file.c +++ b/src/pulsecore/sound-file.c @@ -67,11 +67,13 @@ int pa_sound_file_load( goto finish; } +#ifdef HAVE_POSIX_FADVISE if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL) < 0) { pa_log_warn("POSIX_FADV_SEQUENTIAL failed: %s", pa_cstrerror(errno)); goto finish; } else pa_log_debug("POSIX_FADV_SEQUENTIAL succeeded."); +#endif if (!(sf = sf_open_fd(fd, SFM_READ, &sfinfo, 1))) { pa_log("Failed to open file %s", fname); -- cgit