]> code.delx.au - pulseaudio/commitdiff
add new pa_pipe_close() API to close two fds at the same time
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Sep 2007 00:17:51 +0000 (00:17 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Sep 2007 00:17:51 +0000 (00:17 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1812 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/daemon/cpulimit.c
src/daemon/main.c
src/pulse/context.c
src/pulse/mainloop-signal.c
src/pulse/mainloop.c
src/pulsecore/core-util.c
src/pulsecore/core-util.h
src/pulsecore/fdsem.c

index 4f0adc06ac5362af64f042089727ccddd323cd7a..0fe11ea66c89d246a189a982d006d5603a7e9a75 100644 (file)
@@ -222,11 +222,7 @@ void pa_cpu_limit_done(void) {
         api = NULL;
     }
 
-    if (the_pipe[0] >= 0)
-        pa_assert_se(pa_close(the_pipe[0]) == 0);
-    if (the_pipe[1] >= 0)
-        pa_assert_se(pa_close(the_pipe[1]) == 0);
-    the_pipe[0] = the_pipe[1] = -1;
+    pa_close_pipe(the_pipe);
 
     if (installed) {
         pa_assert_se(sigaction(SIGXCPU, &sigaction_prev, NULL) >= 0);
index 0bbddffa6455e9aa7b7f9baca579741dcc84b6a6..93d4eb6b0a518efcaa91c8e7ad4f4cef07338620 100644 (file)
@@ -158,14 +158,6 @@ static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e,
     }
 }
 
-static void close_pipe(int p[2]) {
-    if (p[0] != -1)
-        pa_assert_se(pa_close(p[0]) == 0);
-    if (p[1] != -1)
-        pa_assert_se(pa_close(p[1]) == 0);
-    p[0] = p[1] = -1;
-}
-
 #define set_env(key, value) putenv(pa_sprintf_malloc("%s=%s", (key), (value)))
 
 #if defined(HAVE_PWD_H) && defined(HAVE_GRP_H)
@@ -745,7 +737,7 @@ finish:
     if (valid_pid_file)
         pa_pid_file_remove();
 
-    close_pipe(daemon_pipe);
+    pa_close_pipe(daemon_pipe);
 
 #ifdef OS_IS_WIN32
     WSACleanup();
index 1ed250f9c79c0b635065a9e1490aa286689343e3..a39646d3544210c0290e2a0b7a0d502b041d4928 100644 (file)
@@ -585,10 +585,7 @@ static int context_connect_spawn(pa_context *c) {
     return 0;
 
 fail:
-    if (fds[0] != -1)
-        pa_assert_se(pa_close(fds[0]) == 0);
-    if (fds[1] != -1)
-        pa_assert_se(pa_close(fds[1]) == 0);
+    pa_close_pipe(fds);
 
     unlock_autospawn_lock_file(c);
 
index d2d42d995b8e9a13cba0798ba9cae32726c02cbe..b6414c4e1495d6d6311a85e7ca2f736fd437f19a 100644 (file)
@@ -147,9 +147,7 @@ void pa_signal_done(void) {
     api->io_free(io_event);
     io_event = NULL;
 
-    pa_assert_se(close(signal_pipe[0]) == 0);
-    pa_assert_se(close(signal_pipe[1]) == 0);
-    signal_pipe[0] = signal_pipe[1] = -1;
+    pa_close_pipe(signal_pipe);
 
     api = NULL;
 }
index fc373d978453d03ab93c2e53854393d1da72aa71..641eded424706bb2d7aab1e96d2bfe4e33299025 100644 (file)
@@ -605,10 +605,7 @@ void pa_mainloop_free(pa_mainloop* m) {
 
     pa_xfree(m->pollfds);
 
-    if (m->wakeup_pipe[0] >= 0)
-        pa_assert_se(pa_close(m->wakeup_pipe[0]) == 0);
-    if (m->wakeup_pipe[1] >= 0)
-        pa_assert_se(pa_close(m->wakeup_pipe[1]) == 0);
+    pa_close_pipe(m->wakeup_pipe);
 
     pa_xfree(m);
 }
index 62a63761389930625133d7fec16c910778fb0933..5becdef09b36a30e2e5d62e33a9fdc95e27ef1ba 100644 (file)
@@ -1323,3 +1323,16 @@ void *pa_will_need(const void *p, size_t l) {
 
     return (void*) p;
 }
+
+void pa_close_pipe(int fds[2]) {
+    pa_assert(fds);
+    
+    if (fds[0] >= 0)
+        pa_assert_se(pa_close(fds[0]) == 0);
+    
+    if (fds[1] >= 0)
+        pa_assert_se(pa_close(fds[1]) == 0);
+    
+    fds[0] = fds[1] = -1;
+}
+
index fcafe63d4478d1d0395d57d4d197fd823f522324..efd19f4554de792d7099df873c11bf55d4e24760 100644 (file)
@@ -120,4 +120,6 @@ static inline unsigned pa_make_power_of_two(unsigned n) {
     return n + 1;
 }
 
+void pa_close_pipe(int fds[2]);
+
 #endif
index 710a74f5bd130dbab6417cce458ffe243c2dfc34..68207a76beb2fd82576aa1744d343b77e7343e04 100644 (file)
@@ -67,8 +67,7 @@ pa_fdsem *pa_fdsem_new(void) {
 void pa_fdsem_free(pa_fdsem *f) {
     pa_assert(f);
 
-    pa_assert_se(pa_close(f->fds[0]) == 0);
-    pa_assert_se(pa_close(f->fds[1]) == 0);
+    pa_close_pipe(f->fds);
 
     pa_xfree(f);
 }