make SkExecutor::GetDefault() a little threadsafe
We note SetDefault() isn't threadsafe, but don't mention anything about GetDefault(). So it feels like it ought to be thread safe. But it's not threadsafe as-is, since it writes to gDefaultExecutor. With tiny tweaks we can make it instead only read gDefaultExecutor. Change-Id: If229afda3d0bfb4fe491137fd2fc2226d0eafafa Reviewed-on: https://skia-review.googlesource.com/c/skia/+/377918 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
a950fef9db
commit
c5582317b3
@ -36,24 +36,22 @@ class SkTrivialExecutor final : public SkExecutor {
|
||||
}
|
||||
};
|
||||
|
||||
static SkExecutor& trivial_executor() {
|
||||
static auto* executor = new SkTrivialExecutor();
|
||||
return *executor;
|
||||
}
|
||||
|
||||
static SkExecutor* gDefaultExecutor = nullptr;
|
||||
|
||||
void SetDefaultTrivialExecutor() {
|
||||
static SkTrivialExecutor *gTrivial = new SkTrivialExecutor();
|
||||
gDefaultExecutor = gTrivial;
|
||||
}
|
||||
SkExecutor& SkExecutor::GetDefault() {
|
||||
if (!gDefaultExecutor) {
|
||||
SetDefaultTrivialExecutor();
|
||||
if (gDefaultExecutor) {
|
||||
return *gDefaultExecutor;
|
||||
}
|
||||
return *gDefaultExecutor;
|
||||
return trivial_executor();
|
||||
}
|
||||
|
||||
void SkExecutor::SetDefault(SkExecutor* executor) {
|
||||
if (executor) {
|
||||
gDefaultExecutor = executor;
|
||||
} else {
|
||||
SetDefaultTrivialExecutor();
|
||||
}
|
||||
gDefaultExecutor = executor;
|
||||
}
|
||||
|
||||
// We'll always push_back() new work, but pop from the front of deques or the back of SkTArray.
|
||||
|
Loading…
Reference in New Issue
Block a user