Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Apr 10, 2020

Replace thread_checker with task_runner_checker, make the weakPtr to be accessed from different threads as long as they are on the same task_runner (thread merging)
flutter/flutter#52253

@chinmaygarde chinmaygarde self-requested a review April 10, 2020 23:50
@cyanglaz cyanglaz changed the title Task runner checker Introduce task_runner_checker, use it on weakPtrs, replace the thread_checker Apr 13, 2020
@cyanglaz cyanglaz requested a review from iskakaushik April 13, 2020 18:31
@cyanglaz cyanglaz marked this pull request as ready for review April 13, 2020 18:31
@auto-assign auto-assign bot requested a review from jason-simmons April 13, 2020 18:33
}

private:
TaskQueueId self_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think self_ is an ambiguous name. Can this be called, initialized_queue_id_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

~TaskRunnerChecker() = default;

bool RunsOnCreationTaskRunner() const {
FML_DCHECK(fml::MessageLoop::IsInitializedForCurrentThread());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be a FML_CHECK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, done!

Comment on lines 31 to 37
auto queues = MessageLoopTaskQueues::GetInstance();
if (queues->Owns(current_queue_id, self_)) {
return true;
}
if (queues->Owns(self_, current_queue_id)) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor to share code with TaskRunner::RunsTasksOnCurrentThread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offline discussion, we will create a TaskRunnerWeakPtr to support the task runner checker

}
};

#if !defined(NDEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this condition be flipped? As it stands it looks like these checks will only be run when NDEBUG is not specified. I think we should rely on FLUTTER_RUNTIME_MODE macro instead and run it on DEBUG builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the current Thread_Runner works. I'm not sure if we should change the behavior in this PR? Maybe we can do it in a separate PR to be more explicit after landing this?

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@cyanglaz cyanglaz changed the title Introduce task_runner_checker, use it on weakPtrs, replace the thread_checker Introduce task_runner_checker, task_runner_weak_ptr Apr 28, 2020
@cyanglaz cyanglaz force-pushed the task_runner_checker branch from f109ddf to 145c604 Compare April 28, 2020 21:13
@cyanglaz
Copy link
Contributor Author

@googlebot I fixed it.

@cyanglaz cyanglaz force-pushed the task_runner_checker branch from 145c604 to 21c0bf6 Compare April 28, 2020 21:19
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

private:
TaskQueueId self_;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
};

#if !defined(NDEBUG)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the current Thread_Runner works. I'm not sure if we should change the behavior in this PR? Maybe we can do it in a separate PR to be more explicit after landing this?

~TaskRunnerChecker() = default;

bool RunsOnCreationTaskRunner() const {
FML_DCHECK(fml::MessageLoop::IsInitializedForCurrentThread());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, done!

Comment on lines 31 to 37
auto queues = MessageLoopTaskQueues::GetInstance();
if (queues->Owns(current_queue_id, self_)) {
return true;
}
if (queues->Owns(self_, current_queue_id)) {
return true;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offline discussion, we will create a TaskRunnerWeakPtr to support the task runner checker


// Copy constructor.
WeakPtr(const WeakPtr<T>& r) = default;
explicit WeakPtr(const WeakPtr<T>& r) = default;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iskakaushik Changed after your last approval:
I found implicit casting could be problematic as someone could want a TaskRunnerAffineWeakPtr but end up getting a WeakPtr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

fml::WeakPtr<Engine> weak_engine_; // to be shared across threads
fml::WeakPtr<Rasterizer> weak_rasterizer_; // to be shared across threads
fml::WeakPtr<Engine> weak_engine_; // to be shared across threads
fml::TaskRunnerAffineWeakPtr<Rasterizer>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iskakaushik Changed after your last approval:
It was implicitly casted from a TaskRunnerAffineWeakPtr to a WeakPtr

@cyanglaz cyanglaz merged commit 2622cb9 into flutter:master May 1, 2020
@cyanglaz cyanglaz deleted the task_runner_checker branch May 1, 2020 18:28
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants