Replace lock_guard with scoped_lock and use class template argument deduction. (flutter/engine#9338)
This commit is contained in:
@@ -19,7 +19,7 @@ SkiaUnrefQueue::~SkiaUnrefQueue() {
|
||||
}
|
||||
|
||||
void SkiaUnrefQueue::Unref(SkRefCnt* object) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
objects_.push_back(object);
|
||||
if (!drain_pending_) {
|
||||
drain_pending_ = true;
|
||||
@@ -31,7 +31,7 @@ void SkiaUnrefQueue::Unref(SkRefCnt* object) {
|
||||
void SkiaUnrefQueue::Drain() {
|
||||
std::deque<SkRefCnt*> skia_objects;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
objects_.swap(skia_objects);
|
||||
drain_pending_ = false;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ void ConcurrentMessageLoop::Run() {
|
||||
|
||||
// |fml::MessageLoopImpl|
|
||||
void ConcurrentMessageLoop::Terminate() {
|
||||
std::lock_guard<std::mutex> lock(wait_condition_mutex_);
|
||||
std::scoped_lock lock(wait_condition_mutex_);
|
||||
shutdown_ = true;
|
||||
wait_condition_.notify_all();
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ void MessageLoopImpl::FlushTasks(FlushType type) {
|
||||
// where:
|
||||
// gather invocations -> Swap -> execute invocations
|
||||
// will lead us to run invocations on the wrong thread.
|
||||
std::lock_guard<std::mutex> task_flush_lock(tasks_flushing_mutex_);
|
||||
std::scoped_lock task_flush_lock(tasks_flushing_mutex_);
|
||||
task_queue_->GetTasksToRunNow(type, invocations);
|
||||
|
||||
for (const auto& invocation : invocations) {
|
||||
|
||||
@@ -14,26 +14,26 @@ MessageLoopTaskQueue::MessageLoopTaskQueue() : order_(0) {}
|
||||
MessageLoopTaskQueue::~MessageLoopTaskQueue() = default;
|
||||
|
||||
void MessageLoopTaskQueue::Dispose() {
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
std::scoped_lock lock(delayed_tasks_mutex_);
|
||||
delayed_tasks_ = {};
|
||||
}
|
||||
|
||||
void MessageLoopTaskQueue::RegisterTask(fml::closure task,
|
||||
fml::TimePoint target_time) {
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
std::scoped_lock lock(delayed_tasks_mutex_);
|
||||
delayed_tasks_.push({++order_, std::move(task), target_time});
|
||||
WakeUp(delayed_tasks_.top().GetTargetTime());
|
||||
}
|
||||
|
||||
bool MessageLoopTaskQueue::HasPendingTasks() {
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
std::scoped_lock lock(delayed_tasks_mutex_);
|
||||
return !delayed_tasks_.empty();
|
||||
}
|
||||
|
||||
void MessageLoopTaskQueue::GetTasksToRunNow(
|
||||
FlushType type,
|
||||
std::vector<fml::closure>& invocations) {
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
std::scoped_lock lock(delayed_tasks_mutex_);
|
||||
|
||||
const auto now = fml::TimePoint::Now();
|
||||
while (!delayed_tasks_.empty()) {
|
||||
@@ -62,23 +62,23 @@ void MessageLoopTaskQueue::WakeUp(fml::TimePoint time) {
|
||||
}
|
||||
|
||||
size_t MessageLoopTaskQueue::GetNumPendingTasks() {
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
std::scoped_lock lock(delayed_tasks_mutex_);
|
||||
return delayed_tasks_.size();
|
||||
}
|
||||
|
||||
void MessageLoopTaskQueue::AddTaskObserver(intptr_t key,
|
||||
fml::closure callback) {
|
||||
std::lock_guard<std::mutex> observers_lock(observers_mutex_);
|
||||
std::scoped_lock observers_lock(observers_mutex_);
|
||||
task_observers_[key] = std::move(callback);
|
||||
}
|
||||
|
||||
void MessageLoopTaskQueue::RemoveTaskObserver(intptr_t key) {
|
||||
std::lock_guard<std::mutex> observers_lock(observers_mutex_);
|
||||
std::scoped_lock observers_lock(observers_mutex_);
|
||||
task_observers_.erase(key);
|
||||
}
|
||||
|
||||
void MessageLoopTaskQueue::NotifyObservers() {
|
||||
std::lock_guard<std::mutex> observers_lock(observers_mutex_);
|
||||
std::scoped_lock observers_lock(observers_mutex_);
|
||||
for (const auto& observer : task_observers_) {
|
||||
observer.second();
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ class AtomicObject {
|
||||
AtomicObject(T object) : object_(object) {}
|
||||
|
||||
T Load() const {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
return object_;
|
||||
}
|
||||
|
||||
void Store(const T& object) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
object_ = object;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,13 +55,13 @@ bool WaitWithTimeoutImpl(std::unique_lock<std::mutex>* locker,
|
||||
// AutoResetWaitableEvent ------------------------------------------------------
|
||||
|
||||
void AutoResetWaitableEvent::Signal() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
signaled_ = true;
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
void AutoResetWaitableEvent::Reset() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
signaled_ = false;
|
||||
}
|
||||
|
||||
@@ -110,21 +110,21 @@ bool AutoResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) {
|
||||
}
|
||||
|
||||
bool AutoResetWaitableEvent::IsSignaledForTest() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
return signaled_;
|
||||
}
|
||||
|
||||
// ManualResetWaitableEvent ----------------------------------------------------
|
||||
|
||||
void ManualResetWaitableEvent::Signal() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
signaled_ = true;
|
||||
signal_id_++;
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
void ManualResetWaitableEvent::Reset() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
signaled_ = false;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ bool ManualResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) {
|
||||
}
|
||||
|
||||
bool ManualResetWaitableEvent::IsSignaledForTest() {
|
||||
std::lock_guard<std::mutex> locker(mutex_);
|
||||
std::scoped_lock locker(mutex_);
|
||||
return signaled_;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ IsolateNameServer::IsolateNameServer() {}
|
||||
IsolateNameServer::~IsolateNameServer() = default;
|
||||
|
||||
Dart_Port IsolateNameServer::LookupIsolatePortByName(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
return LookupIsolatePortByNameUnprotected(name);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ Dart_Port IsolateNameServer::LookupIsolatePortByNameUnprotected(
|
||||
|
||||
bool IsolateNameServer::RegisterIsolatePortWithName(Dart_Port port,
|
||||
const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
if (LookupIsolatePortByNameUnprotected(name) != ILLEGAL_PORT) {
|
||||
// Name is already registered.
|
||||
return false;
|
||||
@@ -36,7 +36,7 @@ bool IsolateNameServer::RegisterIsolatePortWithName(Dart_Port port,
|
||||
}
|
||||
|
||||
bool IsolateNameServer::RemoveIsolateNameMapping(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
auto port_iterator = port_mapping_.find(name);
|
||||
if (port_iterator == port_mapping_.end()) {
|
||||
return false;
|
||||
|
||||
@@ -36,7 +36,7 @@ void DartCallbackCache::SetCachePath(const std::string& path) {
|
||||
}
|
||||
|
||||
Dart_Handle DartCallbackCache::GetCallback(int64_t handle) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
auto iterator = cache_.find(handle);
|
||||
if (iterator != cache_.end()) {
|
||||
DartCallbackRepresentation cb = iterator->second;
|
||||
@@ -48,7 +48,7 @@ Dart_Handle DartCallbackCache::GetCallback(int64_t handle) {
|
||||
int64_t DartCallbackCache::GetCallbackHandle(const std::string& name,
|
||||
const std::string& class_name,
|
||||
const std::string& library_path) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
std::hash<std::string> hasher;
|
||||
int64_t hash = hasher(name);
|
||||
hash += hasher(class_name);
|
||||
@@ -63,7 +63,7 @@ int64_t DartCallbackCache::GetCallbackHandle(const std::string& name,
|
||||
|
||||
std::unique_ptr<DartCallbackRepresentation>
|
||||
DartCallbackCache::GetCallbackInformation(int64_t handle) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
auto iterator = cache_.find(handle);
|
||||
if (iterator != cache_.end()) {
|
||||
return std::make_unique<DartCallbackRepresentation>(iterator->second);
|
||||
@@ -114,7 +114,7 @@ void DartCallbackCache::SaveCacheToDisk() {
|
||||
}
|
||||
|
||||
void DartCallbackCache::LoadCacheFromDisk() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
// Don't reload the cache if it's already populated.
|
||||
if (!cache_.empty()) {
|
||||
|
||||
@@ -70,7 +70,7 @@ void DartServiceIsolate::NotifyServerState(Dart_NativeArguments args) {
|
||||
std::vector<DartServiceIsolate::ObservatoryServerStateCallback>
|
||||
callbacks_to_fire;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(callbacks_mutex_);
|
||||
std::scoped_lock lock(callbacks_mutex_);
|
||||
for (auto& callback : callbacks_) {
|
||||
callbacks_to_fire.push_back(*callback.get());
|
||||
}
|
||||
@@ -98,7 +98,7 @@ DartServiceIsolate::CallbackHandle DartServiceIsolate::AddServerStatusCallback(
|
||||
auto handle = reinterpret_cast<CallbackHandle>(callback_pointer.get());
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(callbacks_mutex_);
|
||||
std::scoped_lock lock(callbacks_mutex_);
|
||||
callbacks_.insert(std::move(callback_pointer));
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ DartServiceIsolate::CallbackHandle DartServiceIsolate::AddServerStatusCallback(
|
||||
|
||||
bool DartServiceIsolate::RemoveServerStatusCallback(
|
||||
CallbackHandle callback_handle) {
|
||||
std::lock_guard<std::mutex> lock(callbacks_mutex_);
|
||||
std::scoped_lock lock(callbacks_mutex_);
|
||||
auto found = std::find_if(
|
||||
callbacks_.begin(), callbacks_.end(),
|
||||
[callback_handle](const auto& item) {
|
||||
|
||||
@@ -40,7 +40,7 @@ DartVMRef::~DartVMRef() {
|
||||
// pessimization and not required for correctness.
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lifecycle_lock(gVMMutex);
|
||||
std::scoped_lock lifecycle_lock(gVMMutex);
|
||||
vm_.reset();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ DartVMRef DartVMRef::Create(Settings settings,
|
||||
fml::RefPtr<DartSnapshot> vm_snapshot,
|
||||
fml::RefPtr<DartSnapshot> isolate_snapshot,
|
||||
fml::RefPtr<DartSnapshot> shared_snapshot) {
|
||||
std::lock_guard<std::mutex> lifecycle_lock(gVMMutex);
|
||||
std::scoped_lock lifecycle_lock(gVMMutex);
|
||||
|
||||
if (!settings.leak_vm) {
|
||||
FML_CHECK(!gVMLeak)
|
||||
@@ -68,7 +68,7 @@ DartVMRef DartVMRef::Create(Settings settings,
|
||||
return DartVMRef{std::move(vm)};
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> dependents_lock(gVMDependentsMutex);
|
||||
std::scoped_lock dependents_lock(gVMDependentsMutex);
|
||||
|
||||
gVMData.reset();
|
||||
gVMServiceProtocol.reset();
|
||||
@@ -103,27 +103,27 @@ DartVMRef DartVMRef::Create(Settings settings,
|
||||
}
|
||||
|
||||
bool DartVMRef::IsInstanceRunning() {
|
||||
std::lock_guard<std::mutex> lock(gVMMutex);
|
||||
std::scoped_lock lock(gVMMutex);
|
||||
return !gVM.expired();
|
||||
}
|
||||
|
||||
std::shared_ptr<const DartVMData> DartVMRef::GetVMData() {
|
||||
std::lock_guard<std::mutex> lock(gVMDependentsMutex);
|
||||
std::scoped_lock lock(gVMDependentsMutex);
|
||||
return gVMData.lock();
|
||||
}
|
||||
|
||||
std::shared_ptr<ServiceProtocol> DartVMRef::GetServiceProtocol() {
|
||||
std::lock_guard<std::mutex> lock(gVMDependentsMutex);
|
||||
std::scoped_lock lock(gVMDependentsMutex);
|
||||
return gVMServiceProtocol.lock();
|
||||
}
|
||||
|
||||
std::shared_ptr<IsolateNameServer> DartVMRef::GetIsolateNameServer() {
|
||||
std::lock_guard<std::mutex> lock(gVMDependentsMutex);
|
||||
std::scoped_lock lock(gVMDependentsMutex);
|
||||
return gVMIsolateNameServer.lock();
|
||||
}
|
||||
|
||||
DartVM* DartVMRef::GetRunningVM() {
|
||||
std::lock_guard<std::mutex> lock(gVMMutex);
|
||||
std::scoped_lock lock(gVMMutex);
|
||||
auto vm = gVM.lock().get();
|
||||
FML_CHECK(vm) << "Caller assumed VM would be running when it wasn't";
|
||||
return vm;
|
||||
|
||||
@@ -180,13 +180,13 @@ void PersistentCache::DumpSkp(const SkData& data) {
|
||||
|
||||
void PersistentCache::AddWorkerTaskRunner(
|
||||
fml::RefPtr<fml::TaskRunner> task_runner) {
|
||||
std::lock_guard<std::mutex> lock(worker_task_runners_mutex_);
|
||||
std::scoped_lock lock(worker_task_runners_mutex_);
|
||||
worker_task_runners_.insert(task_runner);
|
||||
}
|
||||
|
||||
void PersistentCache::RemoveWorkerTaskRunner(
|
||||
fml::RefPtr<fml::TaskRunner> task_runner) {
|
||||
std::lock_guard<std::mutex> lock(worker_task_runners_mutex_);
|
||||
std::scoped_lock lock(worker_task_runners_mutex_);
|
||||
auto found = worker_task_runners_.find(task_runner);
|
||||
if (found != worker_task_runners_.end()) {
|
||||
worker_task_runners_.erase(found);
|
||||
@@ -196,7 +196,7 @@ void PersistentCache::RemoveWorkerTaskRunner(
|
||||
fml::RefPtr<fml::TaskRunner> PersistentCache::GetWorkerTaskRunner() const {
|
||||
fml::RefPtr<fml::TaskRunner> worker;
|
||||
|
||||
std::lock_guard<std::mutex> lock(worker_task_runners_mutex_);
|
||||
std::scoped_lock lock(worker_task_runners_mutex_);
|
||||
if (!worker_task_runners_.empty()) {
|
||||
worker = *worker_task_runners_.begin();
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class Pipeline : public fml::RefCountedThreadSafe<Pipeline<R>> {
|
||||
size_t items_count = 0;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
std::scoped_lock lock(queue_mutex_);
|
||||
std::tie(resource, trace_id) = std::move(queue_.front());
|
||||
queue_.pop();
|
||||
items_count = queue_.size();
|
||||
@@ -150,7 +150,7 @@ class Pipeline : public fml::RefCountedThreadSafe<Pipeline<R>> {
|
||||
|
||||
void ProducerCommit(ResourcePtr resource, size_t trace_id) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
std::scoped_lock lock(queue_mutex_);
|
||||
queue_.emplace(std::move(resource), trace_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ void VsyncWaiter::AsyncWaitForVsync(Callback callback) {
|
||||
TRACE_EVENT0("flutter", "AsyncWaitForVsync");
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(callback_mutex_);
|
||||
std::scoped_lock lock(callback_mutex_);
|
||||
if (callback_) {
|
||||
// The animator may request a frame more than once within a frame
|
||||
// interval. Multiple calls to request frame must result in a single
|
||||
@@ -55,7 +55,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
|
||||
Callback callback;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(callback_mutex_);
|
||||
std::scoped_lock lock(callback_mutex_);
|
||||
callback = std::move(callback_);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ void EmbedderTaskRunner::PostTaskForTime(fml::closure task,
|
||||
|
||||
{
|
||||
// Release the lock before the jump via the dispatch table.
|
||||
std::lock_guard<std::mutex> lock(tasks_mutex_);
|
||||
std::scoped_lock lock(tasks_mutex_);
|
||||
baton = ++last_baton_;
|
||||
pending_tasks_[baton] = task;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ bool EmbedderTaskRunner::PostTask(uint64_t baton) {
|
||||
fml::closure task;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(tasks_mutex_);
|
||||
std::scoped_lock lock(tasks_mutex_);
|
||||
auto found = pending_tasks_.find(baton);
|
||||
if (found == pending_tasks_.end()) {
|
||||
FML_LOG(ERROR) << "Embedder attempted to post an unknown task.";
|
||||
|
||||
@@ -44,7 +44,7 @@ Dart_NativeFunction TestDartNativeResolver::DartNativeEntryResolverCallback(
|
||||
bool* auto_setup_scope) {
|
||||
auto name = tonic::StdStringFromDart(dart_name);
|
||||
|
||||
std::lock_guard<std::mutex> lock(gIsolateResolversMutex);
|
||||
std::scoped_lock lock(gIsolateResolversMutex);
|
||||
auto found = gIsolateResolvers.find(Dart_CurrentIsolate());
|
||||
if (found == gIsolateResolvers.end()) {
|
||||
FML_LOG(ERROR) << "Could not resolve native method for :" << name;
|
||||
@@ -74,7 +74,7 @@ void TestDartNativeResolver::SetNativeResolverForIsolate() {
|
||||
FML_CHECK(!tonic::LogIfError(result))
|
||||
<< "Could not set native resolver in test.";
|
||||
|
||||
std::lock_guard<std::mutex> lock(gIsolateResolversMutex);
|
||||
std::scoped_lock lock(gIsolateResolversMutex);
|
||||
gIsolateResolvers[Dart_CurrentIsolate()] = shared_from_this();
|
||||
|
||||
std::vector<Dart_Isolate> isolates_with_dead_resolvers;
|
||||
|
||||
@@ -66,7 +66,7 @@ FontCollection::FontCollection(
|
||||
|
||||
void FontCollection::init(
|
||||
const vector<std::shared_ptr<FontFamily>>& typefaces) {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
mId = sNextId++;
|
||||
vector<uint32_t> lastChar;
|
||||
size_t nTypefaces = typefaces.size();
|
||||
@@ -406,7 +406,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
|
||||
// Currently mRanges can not be used here since it isn't aware of the
|
||||
// variation sequence.
|
||||
|
||||
@@ -56,7 +56,7 @@ android::hash_t FontStyle::hash() const {
|
||||
|
||||
// static
|
||||
uint32_t FontStyle::registerLanguageList(const std::string& languages) {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
return FontLanguageListCache::getId(languages);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector<Font>&& fonts)
|
||||
bool FontFamily::analyzeStyle(const std::shared_ptr<MinikinFont>& typeface,
|
||||
int* weight,
|
||||
bool* italic) {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2');
|
||||
HbBlob os2Table(getFontTable(typeface.get(), os2Tag));
|
||||
if (os2Table.get() == nullptr)
|
||||
@@ -175,7 +175,7 @@ bool FontFamily::isColorEmojiFamily() const {
|
||||
}
|
||||
|
||||
void FontFamily::computeCoverage() {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
const FontStyle defaultStyle;
|
||||
const MinikinFont* typeface = getClosestMatch(defaultStyle).font;
|
||||
const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p');
|
||||
@@ -233,7 +233,7 @@ std::shared_ptr<FontFamily> FontFamily::createFamilyWithVariation(
|
||||
std::vector<Font> fonts;
|
||||
for (const Font& font : mFonts) {
|
||||
bool supportedVariations = false;
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
std::unordered_set<AxisTag> supportedAxes = font.getSupportedAxesLocked();
|
||||
if (!supportedAxes.empty()) {
|
||||
for (const FontVariation& variation : variations) {
|
||||
|
||||
@@ -590,7 +590,7 @@ void Layout::doLayout(const uint16_t* buf,
|
||||
const FontStyle& style,
|
||||
const MinikinPaint& paint,
|
||||
const std::shared_ptr<FontCollection>& collection) {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
|
||||
LayoutContext ctx;
|
||||
ctx.style = style;
|
||||
@@ -614,7 +614,7 @@ float Layout::measureText(const uint16_t* buf,
|
||||
const MinikinPaint& paint,
|
||||
const std::shared_ptr<FontCollection>& collection,
|
||||
float* advances) {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
|
||||
LayoutContext ctx;
|
||||
ctx.style = style;
|
||||
@@ -1195,7 +1195,7 @@ void Layout::getBounds(MinikinRect* bounds) const {
|
||||
}
|
||||
|
||||
void Layout::purgeCaches() {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache;
|
||||
layoutCache.clear();
|
||||
purgeHbFontCacheLocked();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
namespace minikin {
|
||||
|
||||
MinikinFont::~MinikinFont() {
|
||||
std::lock_guard<std::recursive_mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
purgeHbFontLocked(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ void itemize(const std::shared_ptr<FontCollection>& collection,
|
||||
|
||||
result->clear();
|
||||
ParseUnicode(buf, BUF_SIZE, str, &len, NULL);
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
collection->itemize(buf, len, style, result);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ const std::string& getFontPath(const FontCollection::Run& run) {
|
||||
// Utility function to obtain FontLanguages from string.
|
||||
const FontLanguages& registerAndGetFontLanguages(
|
||||
const std::string& lang_string) {
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
return FontLanguageListCache::getById(
|
||||
FontLanguageListCache::getId(lang_string));
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ typedef ICUTestBase FontLanguagesTest;
|
||||
typedef ICUTestBase FontLanguageTest;
|
||||
|
||||
static const FontLanguages& createFontLanguages(const std::string& input) {
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
uint32_t langId = FontLanguageListCache::getId(input);
|
||||
return FontLanguageListCache::getById(langId);
|
||||
}
|
||||
|
||||
static FontLanguage createFontLanguage(const std::string& input) {
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
uint32_t langId = FontLanguageListCache::getId(input);
|
||||
return FontLanguageListCache::getById(langId)[0];
|
||||
}
|
||||
@@ -575,7 +575,7 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) {
|
||||
std::shared_ptr<FontFamily> family(
|
||||
new FontFamily(std::vector<Font>{Font(minikinFont, FontStyle())}));
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
|
||||
const uint32_t kVS1 = 0xFE00;
|
||||
const uint32_t kVS2 = 0xFE01;
|
||||
@@ -630,7 +630,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) {
|
||||
new MinikinFontForTest(testCase.fontPath));
|
||||
std::shared_ptr<FontFamily> family(
|
||||
new FontFamily(std::vector<Font>{Font(minikinFont, FontStyle())}));
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
EXPECT_EQ(testCase.hasVSTable, family->hasVSTable());
|
||||
}
|
||||
}
|
||||
@@ -714,7 +714,7 @@ TEST_F(FontFamilyTest, coverageTableSelectionTest) {
|
||||
std::shared_ptr<FontFamily> unicodeEnc4Font =
|
||||
makeFamily(kUnicodeEncoding4Font);
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
|
||||
EXPECT_TRUE(unicodeEnc1Font->hasGlyph(0x0061, 0));
|
||||
EXPECT_TRUE(unicodeEnc3Font->hasGlyph(0x0061, 0));
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(FontLanguageListCacheTest, getId) {
|
||||
EXPECT_NE(0UL, FontStyle::registerLanguageList("jp"));
|
||||
EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans"));
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
EXPECT_EQ(0UL, FontLanguageListCache::getId(""));
|
||||
|
||||
EXPECT_EQ(FontLanguageListCache::getId("en"),
|
||||
@@ -52,7 +52,7 @@ TEST_F(FontLanguageListCacheTest, getId) {
|
||||
}
|
||||
|
||||
TEST_F(FontLanguageListCacheTest, getById) {
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
uint32_t enLangId = FontLanguageListCache::getId("en");
|
||||
uint32_t jpLangId = FontLanguageListCache::getId("jp");
|
||||
FontLanguage english = FontLanguageListCache::getById(enLangId)[0];
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace minikin {
|
||||
class HbFontCacheTest : public testing::Test {
|
||||
public:
|
||||
virtual void TearDown() {
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
purgeHbFontCacheLocked();
|
||||
}
|
||||
};
|
||||
@@ -48,7 +48,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) {
|
||||
std::shared_ptr<MinikinFontForTest> fontC(
|
||||
new MinikinFontForTest(kTestFontDir "BoldItalic.ttf"));
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
// Never return NULL.
|
||||
EXPECT_NE(nullptr, getHbFontLocked(fontA.get()));
|
||||
EXPECT_NE(nullptr, getHbFontLocked(fontB.get()));
|
||||
@@ -71,7 +71,7 @@ TEST_F(HbFontCacheTest, purgeCacheTest) {
|
||||
std::shared_ptr<MinikinFontForTest> minikinFont(
|
||||
new MinikinFontForTest(kTestFontDir "Regular.ttf"));
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
hb_font_t* font = getHbFontLocked(minikinFont.get());
|
||||
ASSERT_NE(nullptr, font);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) {
|
||||
FontStyle style(FontStyle::registerLanguageList(
|
||||
ITEMIZE_TEST_CASES[testIndex].languageTag));
|
||||
|
||||
std::lock_guard<std::mutex> _l(gMinikinLock);
|
||||
std::scoped_lock _l(gMinikinLock);
|
||||
while (state.KeepRunning()) {
|
||||
result.clear();
|
||||
collection->itemize(buffer, utf16_length, style, &result);
|
||||
|
||||
Reference in New Issue
Block a user