Skip to content

Commit

Permalink
[fml][embedder] Improve thread-check logging (flutter#47020)
Browse files Browse the repository at this point in the history
Developers working their app's runner code or in the native parts of
plugins are often required to call methods from the platform thread, or
face a crash.
Makes a minor improvement to fml::ThreadChecker's
IsCreationThreadCurrent log message.
This patch originally proposed to emit a much more specific error
message when calling methods that must be called on the platform thread
(typically originating in calls from plugins), however, given that we
don't ship debug engines as part of the SDK, this is really only going
to be useful to engine developpers, or people brave enough to run with
their own local engine build, in any case. 

Issue: flutter/flutter#135345

No changed tests since no functional change, just an error message
cleanup.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I signed the [CLA].
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
  • Loading branch information
cbracken authored Oct 17, 2023
1 parent 5059076 commit 9019122
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fml/memory/thread_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ class ThreadChecker final {
if (0 == pthread_getname_np(current_thread, actual_thread,
buffer_length) &&
0 == pthread_getname_np(self_, expected_thread, buffer_length)) {
FML_DLOG(ERROR) << "IsCreationThreadCurrent expected thread: '"
<< expected_thread << "' actual thread:'"
<< actual_thread << "'";
FML_DLOG(ERROR) << "Object referenced on a thread other than the one "
"on which it was created. Expected thread: '"
<< expected_thread << "'. Actual thread: '"
<< actual_thread << "'.";
}
}
#endif // __APPLE__
Expand Down

0 comments on commit 9019122

Please sign in to comment.