8#ifndef FLUTTER_FML_MEMORY_THREAD_CHECKER_H_
9#define FLUTTER_FML_MEMORY_THREAD_CHECKER_H_
11#include "flutter/fml/build_config.h"
12#include "flutter/fml/logging.h"
13#include "flutter/fml/macros.h"
15#if defined(FML_OS_WIN)
36 static thread_local bool disable_next_failure_;
39#if defined(FML_OS_WIN)
44 bool result = GetCurrentThreadId() == self_;
45 if (!
result && disable_next_failure_) {
46 disable_next_failure_ =
false;
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;
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,
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 <<
"'.";
85 return is_creation_thread_current;
94#define FML_DECLARE_THREAD_CHECKER(c) fml::ThreadChecker c
95#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) \
96 FML_DCHECK((c).IsCreationThreadCurrent())
98#define FML_DECLARE_THREAD_CHECKER(c)
99#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) ((void)0)
bool IsCreationThreadCurrent() const
static void DisableNextThreadCheckFailure()
#define FML_DLOG(severity)