]> code.delx.au - pulseaudio/commitdiff
if MAP_ANONYMOUS is not supported use posix_memalign if possible to allocate the...
authorLennart Poettering <lennart@poettering.net>
Sat, 19 Aug 2006 17:27:27 +0000 (17:27 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 19 Aug 2006 17:27:27 +0000 (17:27 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1296 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulsecore/shm.c

index 52867d2a947efd731865847935d8b7a36b75f810..02528126ca46c83d1ee6a069ac360010c9a49a1d 100644 (file)
   USA.
 ***/
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -32,6 +36,7 @@
 #include <pulsecore/core-error.h>
 #include <pulsecore/log.h>
 #include <pulsecore/random.h>
+#include <pulse/xmalloc.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));
             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
         m->ptr = pa_xmalloc(m->size);
 #endif
@@ -114,7 +128,11 @@ void pa_shm_free(pa_shm *m) {
     assert(m->ptr && m->ptr != MAP_FAILED);
     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)
         pa_xfree(m->ptr);
     else
@@ -139,7 +157,6 @@ void pa_shm_punch(pa_shm *m, size_t offset, size_t size) {
     assert(m);
     assert(m->ptr && m->ptr != MAP_FAILED);
     assert(m->size > 0);
-    assert(m->do_unlink);
     assert(offset < m->size);
     assert(offset+size < m->size);