Created
August 14, 2015 00:40
-
-
Save EricRahm/95213cce34048681278f to your computer and use it in GitHub Desktop.
Example async memory reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pseudo-pythonish-cpp, whatever | |
total_reporters = len(reporters) | |
do_memory_reports: | |
// this is on the main thread | |
for r in reporters: | |
main_thread_dispatch(new DoReportEvent(r)); | |
start_timer(on_report_done); | |
on_report_done(r): | |
total_reporters--; | |
if (total_reporters == 0 || is_timed_out()): | |
// call the finishReporting callback that was registered | |
cancel_timer(); | |
finishReporting(); | |
else: | |
// do nothing, just wait for the next event | |
do_report(r): | |
// this is called on main thread, it's a different event (do_memory_reports has completed) | |
r->report(); // this can dispatch events to other threads etc | |
example_reporter: | |
post_task_to_other_thread(runs_on_other_thread); | |
runs_on_other_thread: | |
// this is on the non-main-thread | |
// do some stuff | |
// signal that this reporter is done | |
main_thread_dispatch(on_report_done); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment