From 28e7487bf97aec493c059d2b6aa01325831f676e Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Wed, 20 Nov 2019 17:56:00 -0800 Subject: [PATCH] Made the thread checker print out the thread names on Apple platforms. (flutter/engine#13943) --- .../src/flutter/fml/memory/thread_checker.h | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/fml/memory/thread_checker.h b/engine/src/flutter/fml/memory/thread_checker.h index c6314ca6212..cd972955d30 100644 --- a/engine/src/flutter/fml/memory/thread_checker.h +++ b/engine/src/flutter/fml/memory/thread_checker.h @@ -47,7 +47,25 @@ class ThreadChecker final { // Returns true if the current thread is the thread this object was created // on and false otherwise. bool IsCreationThreadCurrent() const { - return !!pthread_equal(pthread_self(), self_); + pthread_t current_thread = pthread_self(); + bool is_creation_thread_current = !!pthread_equal(current_thread, self_); +#ifdef __APPLE__ + // TODO(https://github.com/flutter/flutter/issues/45272): Implement for + // other platforms. + if (!is_creation_thread_current) { + static const int buffer_length = 128; + char expected_thread[buffer_length]; + char actual_thread[buffer_length]; + if (0 == pthread_getname_np(current_thread, actual_thread, + buffer_length) && + 0 == pthread_getname_np(self_, actual_thread, buffer_length)) { + FML_DLOG(ERROR) << "IsCreationThreadCurrent expected thread: '" + << expected_thread << "' actual thread:'" + << actual_thread << "'"; + } + } +#endif // __APPLE__ + return is_creation_thread_current; } private: