[pulseaudio-commits] r1743 - /branches/lennart/src/pulsecore/shm.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Sep 2 13:35:36 PDT 2007


Author: lennart
Date: Sun Sep  2 22:35:36 2007
New Revision: 1743

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1743&root=3Dpulseaudio&vi=
ew=3Drev
Log:
make use of new memory page alignment macros, reindent

Modified:
    branches/lennart/src/pulsecore/shm.c

Modified: branches/lennart/src/pulsecore/shm.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
shm.c?rev=3D1743&root=3Dpulseaudio&r1=3D1742&r2=3D1743&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/shm.c (original)
+++ branches/lennart/src/pulsecore/shm.c Sun Sep  2 22:35:36 2007
@@ -43,6 +43,7 @@
 #include <pulsecore/log.h>
 #include <pulsecore/random.h>
 #include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
 #include <pulse/xmalloc.h>
 =

 #include "shm.h"
@@ -80,7 +81,7 @@
         {
             int r;
 =

-            if ((r =3D posix_memalign(&m->ptr, sysconf(_SC_PAGESIZE), size=
)) < 0) {
+            if ((r =3D posix_memalign(&m->ptr, PA_PAGE_SIZE, size)) < 0) {
                 pa_log("posix_memalign() failed: %s", pa_cstrerror(r));
                 goto fail;
             }
@@ -140,42 +141,43 @@
     assert(m->size > 0);
 =

 #ifdef MAP_FAILED
-        assert(m->ptr !=3D MAP_FAILED);
-#endif
-
-        if (!m->shared) {
+    assert(m->ptr !=3D MAP_FAILED);
+#endif
+    =

+    if (!m->shared) {
 #ifdef MAP_ANONYMOUS
-            if (munmap(m->ptr, m->size) < 0)
-                pa_log("munmap() failed: %s", pa_cstrerror(errno));
+        if (munmap(m->ptr, m->size) < 0)
+            pa_log("munmap() failed: %s", pa_cstrerror(errno));
 #elif defined(HAVE_POSIX_MEMALIGN)
         free(m->ptr);
 #else
         pa_xfree(m->ptr);
 #endif
-        } else {
-#ifdef HAVE_SHM_OPEN
-            if (munmap(m->ptr, m->size) < 0)
-                pa_log("munmap() failed: %s", pa_cstrerror(errno));
-
-            if (m->do_unlink) {
-                    char fn[32];
-
-                    segment_name(fn, sizeof(fn), m->id);
-
-                    if (shm_unlink(fn) < 0)
-                        pa_log(" shm_unlink(%s) failed: %s", fn, pa_cstrer=
ror(errno));
-            }
-#else
-                /* We shouldn't be here without shm support */
-                assert(0);
-#endif
-        }
+    } else {
+#ifdef HAVE_SHM_OPEN
+        if (munmap(m->ptr, m->size) < 0)
+            pa_log("munmap() failed: %s", pa_cstrerror(errno));
+        =

+        if (m->do_unlink) {
+            char fn[32];
+            =

+            segment_name(fn, sizeof(fn), m->id);
+            =

+            if (shm_unlink(fn) < 0)
+                pa_log(" shm_unlink(%s) failed: %s", fn, pa_cstrerror(errn=
o));
+        }
+#else
+        /* We shouldn't be here without shm support */
+        pa_assert_not_reached();
+#endif
+    }
 =

     memset(m, 0, sizeof(*m));
 }
 =

 void pa_shm_punch(pa_shm *m, size_t offset, size_t size) {
     void *ptr;
+    size_t o, ps;
 =

     assert(m);
     assert(m->ptr);
@@ -183,28 +185,21 @@
     assert(offset+size <=3D m->size);
 =

 #ifdef MAP_FAILED
-        assert(m->ptr !=3D MAP_FAILED);
+    assert(m->ptr !=3D MAP_FAILED);
 #endif
 =

     /* You're welcome to implement this as NOOP on systems that don't
      * support it */
 =

+    /* Align this to multiples of the page size */
     ptr =3D (uint8_t*) m->ptr + offset;
-
-#ifdef __linux__
-{
-    /* On Linux ptr must be page aligned */
-    long psz =3D sysconf(_SC_PAGESIZE);
-    unsigned o;
-
-    o =3D ((unsigned long) ptr) - ((((unsigned long) ptr)/psz) * psz);
-
+    o =3D (uint8_t*) ptr - (uint8_t*) PA_PAGE_ALIGN_PTR(ptr);
+    =

     if (o > 0) {
-        ptr =3D (uint8_t*) ptr + (psz - o);
-        size -=3D psz - o;
-    }
-}
-#endif
+        ps =3D PA_PAGE_SIZE;
+        ptr =3D (uint8_t*) ptr + (ps - o);
+        size -=3D ps - o;
+    }
 =

 #ifdef MADV_REMOVE
     if (madvise(ptr, size, MADV_REMOVE) >=3D 0)
@@ -217,7 +212,9 @@
 #endif
 =

 #ifdef MADV_DONTNEED
-    madvise(ptr, size, MADV_DONTNEED);
+    pa_assert_se(madvise(ptr, size, MADV_DONTNEED) =3D=3D 0);
+#elif defined(POSIX_MADV_DONTNEED)
+    pa_assert_se(posix_madvise(ptr, size, POSIX_MADV_DONTNEED) =3D=3D 0);
 #endif
 }
 =





More information about the pulseaudio-commits mailing list