[pulseaudio-commits] r1319 - /trunk/src/pulsecore/shm.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Aug 22 05:45:45 PDT 2006


Author: ossman
Date: Tue Aug 22 14:45:43 2006
New Revision: 1319

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1319&root=pulseaudio&view=rev
Log:
Fix up portability of memory pool handling a bit.

Modified:
    trunk/src/pulsecore/shm.c

Modified: trunk/src/pulsecore/shm.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/shm.c?rev=1319&root=pulseaudio&r1=1318&r2=1319&view=diff
==============================================================================
--- trunk/src/pulsecore/shm.c (original)
+++ trunk/src/pulsecore/shm.c Tue Aug 22 14:45:43 2006
@@ -54,8 +54,6 @@
     return fn;
 }
 
-#ifdef HAVE_SHM_OPEN
-
 int pa_shm_create_rw(pa_shm *m, size_t size, int shared, mode_t mode) {
     char fn[32];
     int fd = -1;
@@ -90,9 +88,10 @@
         m->do_unlink = 0;
         
     } else {
+#ifdef HAVE_SHM_OPEN
         pa_random(&m->id, sizeof(m->id));
         segment_name(fn, sizeof(fn), m->id);
-    
+
         if ((fd = shm_open(fn, O_RDWR|O_CREAT|O_EXCL, mode & 0444)) < 0) {
             pa_log("shm_open() failed: %s", pa_cstrerror(errno));
             goto fail;
@@ -110,6 +109,9 @@
 
         close(fd);
         m->do_unlink = 1;
+#else
+		return -1;
+#endif
     }
 
     m->shared = shared;
@@ -118,40 +120,52 @@
     
 fail:
 
+#ifdef HAVE_SHM_OPEN
     if (fd >= 0) {
         shm_unlink(fn);
         close(fd);
     }
+#endif
 
     return -1;
 }
 
 void pa_shm_free(pa_shm *m) {
-    char fn[32];
-    
-    assert(m);
-    assert(m->ptr && m->ptr != MAP_FAILED);
+    assert(m);
+    assert(m->ptr);
     assert(m->size > 0);
 
-#if !defined(MAP_ANONYMOUS) && defined(HAVE_POSIX_MEMALIGN)
-    if (!m->shared)
+#ifdef MAP_FAILED
+	assert(m->ptr != MAP_FAILED);
+#endif
+
+	if (!m->shared) {
+#ifdef MAP_ANONYMOUS
+	    if (munmap(m->ptr, m->size) < 0)
+	        pa_log("munmap() failed: %s", pa_cstrerror(errno));
+#elif defined(HAVE_POSIX_MEMALIGN)
         free(m->ptr);
-    else
-#elif !defined(MAP_ANONYMOUS)
-    if (!m->shared)
+#else
         pa_xfree(m->ptr);
-    else
-#endif        
-    
-    if (munmap(m->ptr, m->size) < 0)
-        pa_log("munmap() failed: %s", pa_cstrerror(errno));
-
-    if (m->do_unlink) {
-        segment_name(fn, sizeof(fn), m->id);
-        
-        if (shm_unlink(fn) < 0)
-            pa_log(__FILE__":shm_unlink(%s) failed: %s", fn, pa_cstrerror(errno));
-    }
+#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(__FILE__":shm_unlink(%s) failed: %s", fn, pa_cstrerror(errno));
+	    }
+#else
+		/* We shouldn't be here without shm support */
+		assert(0);
+#endif
+	}
 
     memset(m, 0, sizeof(*m));
 }
@@ -160,10 +174,14 @@
     void *ptr;
     
     assert(m);
-    assert(m->ptr && m->ptr != MAP_FAILED);
+    assert(m->ptr);
     assert(m->size > 0);
     assert(offset < m->size);
     assert(offset+size < m->size);
+
+#ifdef MAP_FAILED
+	assert(m->ptr != MAP_FAILED);
+#endif
 
     /* You're welcome to implement this as NOOP on systems that don't
      * support it */
@@ -200,6 +218,8 @@
 #endif
 }
 
+#ifdef HAVE_SHM_OPEN
+
 int pa_shm_attach_ro(pa_shm *m, unsigned id) {
     char fn[32];
     int fd = -1;
@@ -247,16 +267,6 @@
 
 #else /* HAVE_SHM_OPEN */
 
-int pa_shm_create_rw(pa_shm *m, size_t size, int shared, mode_t mode) {
-	return -1;
-}
-
-void pa_shm_free(pa_shm *m) {
-}
-
-void pa_shm_punch(pa_shm *m, size_t offset, size_t size) {
-}
-
 int pa_shm_attach_ro(pa_shm *m, unsigned id) {
 	return -1;
 }




More information about the pulseaudio-commits mailing list