[PATCH 3/3] pcm_local: assert() when using mutexes incorrectly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This makes it easier to find pcm mutex handling errors.

Signed-off-by: Ben Russell <thematrixeatsyou@xxxxxxxxx>
---
 src/pcm/pcm_local.h | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
index 649d84f2..c1f881a6 100644
--- a/src/pcm/pcm_local.h
+++ b/src/pcm/pcm_local.h
@@ -1153,23 +1153,39 @@ static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val)
  */
 static inline void __snd_pcm_lock(snd_pcm_t *pcm)
 {
-	if (pcm->lock_enabled)
-		pthread_mutex_lock(&pcm->lock);
+	int lock_err;
+
+	if (pcm->lock_enabled) {
+		lock_err = pthread_mutex_lock(&pcm->lock);
+		assert(lock_err == 0);
+	}
 }
 static inline void __snd_pcm_unlock(snd_pcm_t *pcm)
 {
-	if (pcm->lock_enabled)
-		pthread_mutex_unlock(&pcm->lock);
+	int unlock_err;
+
+	if (pcm->lock_enabled) {
+		unlock_err = pthread_mutex_unlock(&pcm->lock);
+		assert(unlock_err == 0);
+	}
 }
 static inline void snd_pcm_lock(snd_pcm_t *pcm)
 {
-	if (pcm->lock_enabled && pcm->need_lock)
-		pthread_mutex_lock(&pcm->lock);
+	int lock_err;
+
+	if (pcm->lock_enabled && pcm->need_lock) {
+		lock_err = pthread_mutex_lock(&pcm->lock);
+		assert(lock_err == 0);
+	}
 }
 static inline void snd_pcm_unlock(snd_pcm_t *pcm)
 {
-	if (pcm->lock_enabled && pcm->need_lock)
-		pthread_mutex_unlock(&pcm->lock);
+	int unlock_err;
+
+	if (pcm->lock_enabled && pcm->need_lock) {
+		unlock_err = pthread_mutex_unlock(&pcm->lock);
+		assert(unlock_err == 0);
+	}
 }
 
 /*
-- 
2.23.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux