Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
fml::ThreadChecker Class Referencefinal

#include <thread_checker.h>

Public Member Functions

 ThreadChecker ()
 
 ~ThreadChecker ()
 
bool IsCreationThreadCurrent () const
 

Static Public Member Functions

static void DisableNextThreadCheckFailure ()
 

Detailed Description

Definition at line 31 of file thread_checker.h.

Constructor & Destructor Documentation

◆ ThreadChecker()

fml::ThreadChecker::ThreadChecker ( )
inline

Definition at line 56 of file thread_checker.h.

56: self_(pthread_self()) {}

◆ ~ThreadChecker()

fml::ThreadChecker::~ThreadChecker ( )
inline

Definition at line 57 of file thread_checker.h.

57{}

Member Function Documentation

◆ DisableNextThreadCheckFailure()

static void fml::ThreadChecker::DisableNextThreadCheckFailure ( )
inlinestatic

Definition at line 33 of file thread_checker.h.

33{ disable_next_failure_ = true; }

◆ IsCreationThreadCurrent()

bool fml::ThreadChecker::IsCreationThreadCurrent ( ) const
inline

Definition at line 61 of file thread_checker.h.

61 {
62 pthread_t current_thread = pthread_self();
63 bool is_creation_thread_current = !!pthread_equal(current_thread, self_);
64 if (disable_next_failure_ && !is_creation_thread_current) {
65 disable_next_failure_ = false;
66 return true;
67 }
68#ifdef __APPLE__
69 // TODO(https://github.com/flutter/flutter/issues/45272): Implement for
70 // other platforms.
71 if (!is_creation_thread_current) {
72 static const int buffer_length = 128;
73 char expected_thread[buffer_length];
74 char actual_thread[buffer_length];
75 if (0 == pthread_getname_np(current_thread, actual_thread,
76 buffer_length) &&
77 0 == pthread_getname_np(self_, expected_thread, buffer_length)) {
78 FML_DLOG(ERROR) << "Object referenced on a thread other than the one "
79 "on which it was created. Expected thread: '"
80 << expected_thread << "'. Actual thread: '"
81 << actual_thread << "'.";
82 }
83 }
84#endif // __APPLE__
85 return is_creation_thread_current;
86 }
#define FML_DLOG(severity)
Definition: logging.h:102
#define ERROR(message)
Definition: elf_loader.cc:260

The documentation for this class was generated from the following files: