]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/once.c
alsa: throw timing data away after device resume
[pulseaudio] / src / pulsecore / once.c
index 198bd41e6cba43fc35613cfbd3d010018f9ba213..05a3ad2c839f4750adbf43a2bcec330c0337e220 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -7,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 
 #include "once.h"
 
-int pa_once_begin(pa_once *control) {
+pa_bool_t pa_once_begin(pa_once *control) {
     pa_mutex *m;
 
     pa_assert(control);
 
     if (pa_atomic_load(&control->done))
-        return 0;
+        return FALSE;
 
     pa_atomic_inc(&control->ref);
 
     /* Caveat: We have to make sure that the once func has completed
      * before returning, even if the once func is not actually
      * executed by us. Hence the awkward locking. */
-    
+
     for (;;) {
 
         if ((m = pa_atomic_ptr_load(&control->mutex))) {
@@ -52,15 +50,17 @@ int pa_once_begin(pa_once *control) {
              * wait until it is unlocked */
             pa_mutex_lock(m);
 
+            pa_assert(pa_atomic_load(&control->done));
+
             pa_once_end(control);
-            return 0;
+            return FALSE;
         }
 
         pa_assert_se(m = pa_mutex_new(FALSE, FALSE));
         pa_mutex_lock(m);
 
         if (pa_atomic_ptr_cmpxchg(&control->mutex, NULL, m))
-            return 1;
+            return TRUE;
 
         pa_mutex_unlock(m);
         pa_mutex_free(m);
@@ -69,7 +69,7 @@ int pa_once_begin(pa_once *control) {
 
 void pa_once_end(pa_once *control) {
     pa_mutex *m;
-    
+
     pa_assert(control);
 
     pa_atomic_store(&control->done, 1);
@@ -93,4 +93,3 @@ void pa_run_once(pa_once *control, pa_once_func_t func) {
         pa_once_end(control);
     }
 }
-