Revert "Revert "Added a bionic systrace class and tracing to pthread_mutex.cpp.""
This reverts commit 26c1420fbb68916d66a8621b5efe8bb25cfdad7b.
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 5461661..e00ffb4 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -39,6 +39,8 @@
#include "private/bionic_futex.h"
#include "private/bionic_tls.h"
+#include "private/bionic_systrace.h"
+
extern void pthread_debug_mutex_lock_check(pthread_mutex_t *mutex);
extern void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex);
@@ -333,6 +335,10 @@
* that the mutex is in state 2 when we go to sleep on it, which
* guarantees a wake-up call.
*/
+
+ ScopedTrace trace("Contending for pthread mutex");
+
+
while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
__futex_wait_ex(&mutex->value, shared, locked_contended, NULL);
}
@@ -473,6 +479,8 @@
mvalue = mutex->value;
}
+ ScopedTrace trace("Contending for pthread mutex");
+
for (;;) {
int newval;
@@ -626,6 +634,8 @@
return 0;
}
+ ScopedTrace trace("Contending for timed pthread mutex");
+
// Loop while needed.
while (__bionic_swap(locked_contended, &mutex->value) != unlocked) {
if (__timespec_from_absolute(&ts, abs_timeout, clock) < 0) {
@@ -658,6 +668,8 @@
mvalue = mutex->value;
}
+ ScopedTrace trace("Contending for timed pthread mutex");
+
while (true) {
// If the value is 'unlocked', try to acquire it directly.
// NOTE: put state to 2 since we know there is contention.