Add mutex lock/unlock count for debugging purpose 32/192432/2 accepted/tizen/unified/20181107.082053 submit/tizen/20181106.060307
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 5 Nov 2018 11:11:27 +0000 (20:11 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 5 Nov 2018 11:19:20 +0000 (20:19 +0900)
Sometimes pthread mutex lock/unlock is getting failed but it should not be failed at any situation except memory corruption is happened.
To get more information of cause of fail, we can start by adding errno prints with counts for chance of memory interferrence.

[Version] 11.1-51
[Issue Type] Debug

Change-Id: I0c904fc579b76beff506a2398be7b1465869dffc

packaging/pulseaudio.spec
src/pulsecore/mutex-posix.c

index 6bd70cd..b67c578 100644 (file)
@@ -3,7 +3,7 @@
 Name:             pulseaudio
 Summary:          Improved Linux sound server
 Version:          11.1
-Release:          50
+Release:          51
 Group:            Multimedia/Audio
 License:          LGPL-2.1
 URL:              http://pulseaudio.org
index a835be1..b8f4b5b 100644 (file)
 
 #include "mutex.h"
 
+#ifdef __TIZEN__
 struct pa_mutex {
+    unsigned int lock;
     pthread_mutex_t mutex;
+    unsigned int unlock;
 };
+#else
+struct pa_mutex {
+    pthread_mutex_t mutex;
+};
+#endif
 
 struct pa_cond {
     pthread_cond_t cond;
@@ -74,20 +82,40 @@ pa_mutex* pa_mutex_new(bool recursive, bool inherit_priority) {
     }
 #endif
 
+#ifdef __TIZEN__
+    m->lock = 0;
+    m->unlock = 0;
+#endif
+
     return m;
 }
 
 void pa_mutex_free(pa_mutex *m) {
     pa_assert(m);
 
+#ifdef __TIZEN__
+    int ret = pthread_mutex_destroy(&m->mutex);
+    if (ret != 0)
+        pa_log_error("pthread_mutex_destroy [%p] error [%d], (%d/%d)", &m->mutex, ret, m->lock, m->unlock);
+    pa_assert_se(ret == 0);
+#else
     pa_assert_se(pthread_mutex_destroy(&m->mutex) == 0);
+#endif
     pa_xfree(m);
 }
 
 void pa_mutex_lock(pa_mutex *m) {
     pa_assert(m);
 
+#ifdef __TIZEN__
+    int ret = pthread_mutex_lock(&m->mutex);
+    if (ret != 0)
+        pa_log_error("pthread_mutex_lock [%p] error [%d], (%d/%d)", &m->mutex, ret, m->lock, m->unlock);
+    pa_assert_se(ret == 0);
+    m->lock++;
+#else
     pa_assert_se(pthread_mutex_lock(&m->mutex) == 0);
+#endif
 }
 
 bool pa_mutex_try_lock(pa_mutex *m) {
@@ -105,7 +133,15 @@ bool pa_mutex_try_lock(pa_mutex *m) {
 void pa_mutex_unlock(pa_mutex *m) {
     pa_assert(m);
 
+#ifdef __TIZEN__
+    int ret = pthread_mutex_unlock(&m->mutex);
+    if (ret != 0)
+        pa_log_error("pthread_mutex_unlock [%p] error [%d], (%d/%d)", &m->mutex, ret, m->lock, m->unlock);
+    pa_assert_se(ret == 0);
+    m->unlock++;
+#else
     pa_assert_se(pthread_mutex_unlock(&m->mutex) == 0);
+#endif
 }
 
 pa_cond *pa_cond_new(void) {