mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
if MAP_ANONYMOUS is not supported use posix_memalign if possible to allocate the memory pool
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1296 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
d50c56a8f3
commit
3e0f00f93d
1 changed files with 19 additions and 2 deletions
|
|
@ -19,6 +19,10 @@
|
||||||
USA.
|
USA.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -32,6 +36,7 @@
|
||||||
#include <pulsecore/core-error.h>
|
#include <pulsecore/core-error.h>
|
||||||
#include <pulsecore/log.h>
|
#include <pulsecore/log.h>
|
||||||
#include <pulsecore/random.h>
|
#include <pulsecore/random.h>
|
||||||
|
#include <pulse/xmalloc.h>
|
||||||
|
|
||||||
#include "shm.h"
|
#include "shm.h"
|
||||||
|
|
||||||
|
|
@ -64,6 +69,15 @@ int pa_shm_create_rw(pa_shm *m, size_t size, int shared, mode_t mode) {
|
||||||
pa_log("mmap() failed: %s", pa_cstrerror(errno));
|
pa_log("mmap() failed: %s", pa_cstrerror(errno));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
#elif defined(HAVE_POSIX_MEMALIGN)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if ((r = posix_memalign(&m->ptr, sysconf(_SC_PAGESIZE), size)) < 0) {
|
||||||
|
pa_log("posix_memalign() failed: %s", pa_cstrerror(r));
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
m->ptr = pa_xmalloc(m->size);
|
m->ptr = pa_xmalloc(m->size);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -114,7 +128,11 @@ void pa_shm_free(pa_shm *m) {
|
||||||
assert(m->ptr && m->ptr != MAP_FAILED);
|
assert(m->ptr && m->ptr != MAP_FAILED);
|
||||||
assert(m->size > 0);
|
assert(m->size > 0);
|
||||||
|
|
||||||
#ifndef MAP_ANONYMOUS
|
#if !defined(MAP_ANONYMOUS) && defined(HAVE_POSIX_MEMALIGN)
|
||||||
|
if (!m->shared)
|
||||||
|
free(m->ptr);
|
||||||
|
else
|
||||||
|
#elif !defined(MAP_ANONYMOUS)
|
||||||
if (!m->shared)
|
if (!m->shared)
|
||||||
pa_xfree(m->ptr);
|
pa_xfree(m->ptr);
|
||||||
else
|
else
|
||||||
|
|
@ -139,7 +157,6 @@ void pa_shm_punch(pa_shm *m, size_t offset, size_t size) {
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(m->ptr && m->ptr != MAP_FAILED);
|
assert(m->ptr && m->ptr != MAP_FAILED);
|
||||||
assert(m->size > 0);
|
assert(m->size > 0);
|
||||||
assert(m->do_unlink);
|
|
||||||
assert(offset < m->size);
|
assert(offset < m->size);
|
||||||
assert(offset+size < m->size);
|
assert(offset+size < m->size);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue