-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.Technical debt, code quality, testing, etc.engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
now we use global mutex creation_mutex_ lock single instance of MessageLoopTaskQueues and tls_task_source_grade
fml::RefPtr<MessageLoopTaskQueues> MessageLoopTaskQueues::GetInstance() {
std::scoped_lock creation(creation_mutex_);
if (!instance_) {
instance_ = fml::MakeRefCounted<MessageLoopTaskQueues>();
tls_task_source_grade.reset(
new TaskSourceGradeHolder{TaskSourceGrade::kUnspecified});
}
return instance_;
}
TaskSourceGrade MessageLoopTaskQueues::GetCurrentTaskSourceGrade() {
std::scoped_lock creation(creation_mutex_);
return tls_task_source_grade.get()->task_source_grade;
}
these code really makes me confused, tls_task_source_grade is thread local, why we need lock?
if we need create a tls tls_task_source_grade when create instance, we can add to constructor.
MessageLoopTaskQueues::MessageLoopTaskQueues()
: task_queue_id_counter_(0), order_(0) {
tls_task_source_grade.reset(
new TaskSourceGradeHolder{TaskSourceGrade::kUnspecified});
}
then we just use a static local variable to initialize instance and remove creation_mutex_.
fml::RefPtr<MessageLoopTaskQueues> MessageLoopTaskQueues::GetInstance() {
static fml::RefPtr<MessageLoopTaskQueues> instance =
fml::MakeRefCounted<MessageLoopTaskQueues>();
return instance;
}
TaskSourceGrade MessageLoopTaskQueues::GetCurrentTaskSourceGrade() {
return tls_task_source_grade.get()->task_source_grade;
}
also, MessageLoopTaskQueues is a single instance, we not need a refptr, just use a raw pointer is ok.
MessageLoopTaskQueues* MessageLoopTaskQueues::GetInstance() {
static MessageLoopTaskQueues* instance = new MessageLoopTaskQueues;
return instance;
}
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.Technical debt, code quality, testing, etc.engineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version