From 5f5821e8c18099ed908d30c483bd5f8909a68fef Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 17 Jun 2019 10:08:45 -0700 Subject: [PATCH] Replace lock_guard with scoped_lock and use class template argument deduction. (flutter/engine#9338) --- engine/src/flutter/flow/skia_gpu_object.cc | 4 ++-- .../src/flutter/fml/concurrent_message_loop.cc | 2 +- engine/src/flutter/fml/message_loop_impl.cc | 2 +- .../src/flutter/fml/message_loop_task_queue.cc | 16 ++++++++-------- .../flutter/fml/synchronization/atomic_object.h | 4 ++-- .../fml/synchronization/waitable_event.cc | 12 ++++++------ .../isolate_name_server/isolate_name_server.cc | 6 +++--- .../src/flutter/lib/ui/plugins/callback_cache.cc | 8 ++++---- .../src/flutter/runtime/dart_service_isolate.cc | 6 +++--- engine/src/flutter/runtime/dart_vm_lifecycle.cc | 16 ++++++++-------- .../src/flutter/shell/common/persistent_cache.cc | 6 +++--- engine/src/flutter/shell/common/pipeline.h | 4 ++-- engine/src/flutter/shell/common/vsync_waiter.cc | 4 ++-- .../platform/embedder/embedder_task_runner.cc | 4 ++-- .../flutter/testing/test_dart_native_resolver.cc | 4 ++-- .../txt/src/minikin/FontCollection.cpp | 4 ++-- .../third_party/txt/src/minikin/FontFamily.cpp | 8 ++++---- .../third_party/txt/src/minikin/Layout.cpp | 6 +++--- .../third_party/txt/src/minikin/MinikinFont.cpp | 2 +- .../txt/tests/FontCollectionItemizeTest.cpp | 4 ++-- .../third_party/txt/tests/FontFamilyTest.cpp | 10 +++++----- .../txt/tests/FontLanguageListCacheTest.cpp | 4 ++-- .../third_party/txt/tests/HbFontCacheTest.cpp | 6 +++--- .../txt/tests/old/perftests/FontCollection.cpp | 2 +- 24 files changed, 72 insertions(+), 72 deletions(-) diff --git a/engine/src/flutter/flow/skia_gpu_object.cc b/engine/src/flutter/flow/skia_gpu_object.cc index bf1b0a1d2a..fa0de8d05c 100644 --- a/engine/src/flutter/flow/skia_gpu_object.cc +++ b/engine/src/flutter/flow/skia_gpu_object.cc @@ -19,7 +19,7 @@ SkiaUnrefQueue::~SkiaUnrefQueue() { } void SkiaUnrefQueue::Unref(SkRefCnt* object) { - std::lock_guard 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 skia_objects; { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); objects_.swap(skia_objects); drain_pending_ = false; } diff --git a/engine/src/flutter/fml/concurrent_message_loop.cc b/engine/src/flutter/fml/concurrent_message_loop.cc index 23c820787f..0c25db2761 100644 --- a/engine/src/flutter/fml/concurrent_message_loop.cc +++ b/engine/src/flutter/fml/concurrent_message_loop.cc @@ -39,7 +39,7 @@ void ConcurrentMessageLoop::Run() { // |fml::MessageLoopImpl| void ConcurrentMessageLoop::Terminate() { - std::lock_guard lock(wait_condition_mutex_); + std::scoped_lock lock(wait_condition_mutex_); shutdown_ = true; wait_condition_.notify_all(); } diff --git a/engine/src/flutter/fml/message_loop_impl.cc b/engine/src/flutter/fml/message_loop_impl.cc index 5ee993778f..8a704e6224 100644 --- a/engine/src/flutter/fml/message_loop_impl.cc +++ b/engine/src/flutter/fml/message_loop_impl.cc @@ -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 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) { diff --git a/engine/src/flutter/fml/message_loop_task_queue.cc b/engine/src/flutter/fml/message_loop_task_queue.cc index ef3ac3348e..21226994d8 100644 --- a/engine/src/flutter/fml/message_loop_task_queue.cc +++ b/engine/src/flutter/fml/message_loop_task_queue.cc @@ -14,26 +14,26 @@ MessageLoopTaskQueue::MessageLoopTaskQueue() : order_(0) {} MessageLoopTaskQueue::~MessageLoopTaskQueue() = default; void MessageLoopTaskQueue::Dispose() { - std::lock_guard 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 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 lock(delayed_tasks_mutex_); + std::scoped_lock lock(delayed_tasks_mutex_); return !delayed_tasks_.empty(); } void MessageLoopTaskQueue::GetTasksToRunNow( FlushType type, std::vector& invocations) { - std::lock_guard 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 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 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 observers_lock(observers_mutex_); + std::scoped_lock observers_lock(observers_mutex_); task_observers_.erase(key); } void MessageLoopTaskQueue::NotifyObservers() { - std::lock_guard observers_lock(observers_mutex_); + std::scoped_lock observers_lock(observers_mutex_); for (const auto& observer : task_observers_) { observer.second(); } diff --git a/engine/src/flutter/fml/synchronization/atomic_object.h b/engine/src/flutter/fml/synchronization/atomic_object.h index 2a06792ff4..9fdbe19c82 100644 --- a/engine/src/flutter/fml/synchronization/atomic_object.h +++ b/engine/src/flutter/fml/synchronization/atomic_object.h @@ -17,12 +17,12 @@ class AtomicObject { AtomicObject(T object) : object_(object) {} T Load() const { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); return object_; } void Store(const T& object) { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); object_ = object; } diff --git a/engine/src/flutter/fml/synchronization/waitable_event.cc b/engine/src/flutter/fml/synchronization/waitable_event.cc index 7064f5db69..2cc272ef74 100644 --- a/engine/src/flutter/fml/synchronization/waitable_event.cc +++ b/engine/src/flutter/fml/synchronization/waitable_event.cc @@ -55,13 +55,13 @@ bool WaitWithTimeoutImpl(std::unique_lock* locker, // AutoResetWaitableEvent ------------------------------------------------------ void AutoResetWaitableEvent::Signal() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); signaled_ = true; cv_.notify_one(); } void AutoResetWaitableEvent::Reset() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); signaled_ = false; } @@ -110,21 +110,21 @@ bool AutoResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) { } bool AutoResetWaitableEvent::IsSignaledForTest() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); return signaled_; } // ManualResetWaitableEvent ---------------------------------------------------- void ManualResetWaitableEvent::Signal() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); signaled_ = true; signal_id_++; cv_.notify_all(); } void ManualResetWaitableEvent::Reset() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); signaled_ = false; } @@ -160,7 +160,7 @@ bool ManualResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) { } bool ManualResetWaitableEvent::IsSignaledForTest() { - std::lock_guard locker(mutex_); + std::scoped_lock locker(mutex_); return signaled_; } diff --git a/engine/src/flutter/lib/ui/isolate_name_server/isolate_name_server.cc b/engine/src/flutter/lib/ui/isolate_name_server/isolate_name_server.cc index 118b00df71..906e166321 100644 --- a/engine/src/flutter/lib/ui/isolate_name_server/isolate_name_server.cc +++ b/engine/src/flutter/lib/ui/isolate_name_server/isolate_name_server.cc @@ -11,7 +11,7 @@ IsolateNameServer::IsolateNameServer() {} IsolateNameServer::~IsolateNameServer() = default; Dart_Port IsolateNameServer::LookupIsolatePortByName(const std::string& name) { - std::lock_guard 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 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 lock(mutex_); + std::scoped_lock lock(mutex_); auto port_iterator = port_mapping_.find(name); if (port_iterator == port_mapping_.end()) { return false; diff --git a/engine/src/flutter/lib/ui/plugins/callback_cache.cc b/engine/src/flutter/lib/ui/plugins/callback_cache.cc index e43772efca..4aaa9c49cb 100644 --- a/engine/src/flutter/lib/ui/plugins/callback_cache.cc +++ b/engine/src/flutter/lib/ui/plugins/callback_cache.cc @@ -36,7 +36,7 @@ void DartCallbackCache::SetCachePath(const std::string& path) { } Dart_Handle DartCallbackCache::GetCallback(int64_t handle) { - std::lock_guard 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 lock(mutex_); + std::scoped_lock lock(mutex_); std::hash 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 DartCallbackCache::GetCallbackInformation(int64_t handle) { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); auto iterator = cache_.find(handle); if (iterator != cache_.end()) { return std::make_unique(iterator->second); @@ -114,7 +114,7 @@ void DartCallbackCache::SaveCacheToDisk() { } void DartCallbackCache::LoadCacheFromDisk() { - std::lock_guard lock(mutex_); + std::scoped_lock lock(mutex_); // Don't reload the cache if it's already populated. if (!cache_.empty()) { diff --git a/engine/src/flutter/runtime/dart_service_isolate.cc b/engine/src/flutter/runtime/dart_service_isolate.cc index 966a31bea8..5d498fc5dd 100644 --- a/engine/src/flutter/runtime/dart_service_isolate.cc +++ b/engine/src/flutter/runtime/dart_service_isolate.cc @@ -70,7 +70,7 @@ void DartServiceIsolate::NotifyServerState(Dart_NativeArguments args) { std::vector callbacks_to_fire; { - std::lock_guard 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(callback_pointer.get()); { - std::lock_guard 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 lock(callbacks_mutex_); + std::scoped_lock lock(callbacks_mutex_); auto found = std::find_if( callbacks_.begin(), callbacks_.end(), [callback_handle](const auto& item) { diff --git a/engine/src/flutter/runtime/dart_vm_lifecycle.cc b/engine/src/flutter/runtime/dart_vm_lifecycle.cc index fc0721a30a..cb2f13634c 100644 --- a/engine/src/flutter/runtime/dart_vm_lifecycle.cc +++ b/engine/src/flutter/runtime/dart_vm_lifecycle.cc @@ -40,7 +40,7 @@ DartVMRef::~DartVMRef() { // pessimization and not required for correctness. return; } - std::lock_guard lifecycle_lock(gVMMutex); + std::scoped_lock lifecycle_lock(gVMMutex); vm_.reset(); } @@ -48,7 +48,7 @@ DartVMRef DartVMRef::Create(Settings settings, fml::RefPtr vm_snapshot, fml::RefPtr isolate_snapshot, fml::RefPtr shared_snapshot) { - std::lock_guard 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 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 lock(gVMMutex); + std::scoped_lock lock(gVMMutex); return !gVM.expired(); } std::shared_ptr DartVMRef::GetVMData() { - std::lock_guard lock(gVMDependentsMutex); + std::scoped_lock lock(gVMDependentsMutex); return gVMData.lock(); } std::shared_ptr DartVMRef::GetServiceProtocol() { - std::lock_guard lock(gVMDependentsMutex); + std::scoped_lock lock(gVMDependentsMutex); return gVMServiceProtocol.lock(); } std::shared_ptr DartVMRef::GetIsolateNameServer() { - std::lock_guard lock(gVMDependentsMutex); + std::scoped_lock lock(gVMDependentsMutex); return gVMIsolateNameServer.lock(); } DartVM* DartVMRef::GetRunningVM() { - std::lock_guard 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; diff --git a/engine/src/flutter/shell/common/persistent_cache.cc b/engine/src/flutter/shell/common/persistent_cache.cc index ce2b380cd1..f4dda15b85 100644 --- a/engine/src/flutter/shell/common/persistent_cache.cc +++ b/engine/src/flutter/shell/common/persistent_cache.cc @@ -180,13 +180,13 @@ void PersistentCache::DumpSkp(const SkData& data) { void PersistentCache::AddWorkerTaskRunner( fml::RefPtr task_runner) { - std::lock_guard lock(worker_task_runners_mutex_); + std::scoped_lock lock(worker_task_runners_mutex_); worker_task_runners_.insert(task_runner); } void PersistentCache::RemoveWorkerTaskRunner( fml::RefPtr task_runner) { - std::lock_guard 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 PersistentCache::GetWorkerTaskRunner() const { fml::RefPtr worker; - std::lock_guard lock(worker_task_runners_mutex_); + std::scoped_lock lock(worker_task_runners_mutex_); if (!worker_task_runners_.empty()) { worker = *worker_task_runners_.begin(); } diff --git a/engine/src/flutter/shell/common/pipeline.h b/engine/src/flutter/shell/common/pipeline.h index 435cf60234..1cf5877353 100644 --- a/engine/src/flutter/shell/common/pipeline.h +++ b/engine/src/flutter/shell/common/pipeline.h @@ -122,7 +122,7 @@ class Pipeline : public fml::RefCountedThreadSafe> { size_t items_count = 0; { - std::lock_guard 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> { void ProducerCommit(ResourcePtr resource, size_t trace_id) { { - std::lock_guard lock(queue_mutex_); + std::scoped_lock lock(queue_mutex_); queue_.emplace(std::move(resource), trace_id); } diff --git a/engine/src/flutter/shell/common/vsync_waiter.cc b/engine/src/flutter/shell/common/vsync_waiter.cc index 97364c581d..aa3637221d 100644 --- a/engine/src/flutter/shell/common/vsync_waiter.cc +++ b/engine/src/flutter/shell/common/vsync_waiter.cc @@ -37,7 +37,7 @@ void VsyncWaiter::AsyncWaitForVsync(Callback callback) { TRACE_EVENT0("flutter", "AsyncWaitForVsync"); { - std::lock_guard 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 lock(callback_mutex_); + std::scoped_lock lock(callback_mutex_); callback = std::move(callback_); } diff --git a/engine/src/flutter/shell/platform/embedder/embedder_task_runner.cc b/engine/src/flutter/shell/platform/embedder/embedder_task_runner.cc index 9a772f47a9..b9b2d092e7 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_task_runner.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder_task_runner.cc @@ -31,7 +31,7 @@ void EmbedderTaskRunner::PostTaskForTime(fml::closure task, { // Release the lock before the jump via the dispatch table. - std::lock_guard 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 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."; diff --git a/engine/src/flutter/testing/test_dart_native_resolver.cc b/engine/src/flutter/testing/test_dart_native_resolver.cc index 1a43994335..e57b0c1be6 100644 --- a/engine/src/flutter/testing/test_dart_native_resolver.cc +++ b/engine/src/flutter/testing/test_dart_native_resolver.cc @@ -44,7 +44,7 @@ Dart_NativeFunction TestDartNativeResolver::DartNativeEntryResolverCallback( bool* auto_setup_scope) { auto name = tonic::StdStringFromDart(dart_name); - std::lock_guard 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 lock(gIsolateResolversMutex); + std::scoped_lock lock(gIsolateResolversMutex); gIsolateResolvers[Dart_CurrentIsolate()] = shared_from_this(); std::vector isolates_with_dead_resolvers; diff --git a/engine/src/flutter/third_party/txt/src/minikin/FontCollection.cpp b/engine/src/flutter/third_party/txt/src/minikin/FontCollection.cpp index db33da1f21..f4d18c0296 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/FontCollection.cpp +++ b/engine/src/flutter/third_party/txt/src/minikin/FontCollection.cpp @@ -66,7 +66,7 @@ FontCollection::FontCollection( void FontCollection::init( const vector>& typefaces) { - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); @@ -406,7 +406,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, return false; } - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); // Currently mRanges can not be used here since it isn't aware of the // variation sequence. diff --git a/engine/src/flutter/third_party/txt/src/minikin/FontFamily.cpp b/engine/src/flutter/third_party/txt/src/minikin/FontFamily.cpp index b301d20c2f..9f66e72f2f 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/FontFamily.cpp +++ b/engine/src/flutter/third_party/txt/src/minikin/FontFamily.cpp @@ -56,7 +56,7 @@ android::hash_t FontStyle::hash() const { // static uint32_t FontStyle::registerLanguageList(const std::string& languages) { - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); return FontLanguageListCache::getId(languages); } @@ -115,7 +115,7 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic) { - std::lock_guard _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 _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::createFamilyWithVariation( std::vector fonts; for (const Font& font : mFonts) { bool supportedVariations = false; - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); std::unordered_set supportedAxes = font.getSupportedAxesLocked(); if (!supportedAxes.empty()) { for (const FontVariation& variation : variations) { diff --git a/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp b/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp index 857c744b93..193d02e86f 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp +++ b/engine/src/flutter/third_party/txt/src/minikin/Layout.cpp @@ -590,7 +590,7 @@ void Layout::doLayout(const uint16_t* buf, const FontStyle& style, const MinikinPaint& paint, const std::shared_ptr& collection) { - std::lock_guard _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& collection, float* advances) { - std::lock_guard _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 _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; layoutCache.clear(); purgeHbFontCacheLocked(); diff --git a/engine/src/flutter/third_party/txt/src/minikin/MinikinFont.cpp b/engine/src/flutter/third_party/txt/src/minikin/MinikinFont.cpp index 5d3715bf08..c44b0a1407 100644 --- a/engine/src/flutter/third_party/txt/src/minikin/MinikinFont.cpp +++ b/engine/src/flutter/third_party/txt/src/minikin/MinikinFont.cpp @@ -21,7 +21,7 @@ namespace minikin { MinikinFont::~MinikinFont() { - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); purgeHbFontLocked(this); } diff --git a/engine/src/flutter/third_party/txt/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/third_party/txt/tests/FontCollectionItemizeTest.cpp index 8315ebea21..cbef889a05 100644 --- a/engine/src/flutter/third_party/txt/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/third_party/txt/tests/FontCollectionItemizeTest.cpp @@ -63,7 +63,7 @@ void itemize(const std::shared_ptr& collection, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); - std::lock_guard _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 _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); return FontLanguageListCache::getById( FontLanguageListCache::getId(lang_string)); } diff --git a/engine/src/flutter/third_party/txt/tests/FontFamilyTest.cpp b/engine/src/flutter/third_party/txt/tests/FontFamilyTest.cpp index eb7cb1752a..2cf823eca0 100644 --- a/engine/src/flutter/third_party/txt/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/third_party/txt/tests/FontFamilyTest.cpp @@ -30,13 +30,13 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static const FontLanguages& createFontLanguages(const std::string& input) { - std::lock_guard _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 _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 family( new FontFamily(std::vector{Font(minikinFont, FontStyle())})); - std::lock_guard _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 family( new FontFamily(std::vector{Font(minikinFont, FontStyle())})); - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } @@ -714,7 +714,7 @@ TEST_F(FontFamilyTest, coverageTableSelectionTest) { std::shared_ptr unicodeEnc4Font = makeFamily(kUnicodeEncoding4Font); - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); EXPECT_TRUE(unicodeEnc1Font->hasGlyph(0x0061, 0)); EXPECT_TRUE(unicodeEnc3Font->hasGlyph(0x0061, 0)); diff --git a/engine/src/flutter/third_party/txt/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/third_party/txt/tests/FontLanguageListCacheTest.cpp index 4a0dfada8f..dccb502061 100644 --- a/engine/src/flutter/third_party/txt/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/third_party/txt/tests/FontLanguageListCacheTest.cpp @@ -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 _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 _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]; diff --git a/engine/src/flutter/third_party/txt/tests/HbFontCacheTest.cpp b/engine/src/flutter/third_party/txt/tests/HbFontCacheTest.cpp index fb886a8bd1..afbe474321 100644 --- a/engine/src/flutter/third_party/txt/tests/HbFontCacheTest.cpp +++ b/engine/src/flutter/third_party/txt/tests/HbFontCacheTest.cpp @@ -33,7 +33,7 @@ namespace minikin { class HbFontCacheTest : public testing::Test { public: virtual void TearDown() { - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); purgeHbFontCacheLocked(); } }; @@ -48,7 +48,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { std::shared_ptr fontC( new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); - std::lock_guard _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 minikinFont( new MinikinFontForTest(kTestFontDir "Regular.ttf")); - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); ASSERT_NE(nullptr, font); diff --git a/engine/src/flutter/third_party/txt/tests/old/perftests/FontCollection.cpp b/engine/src/flutter/third_party/txt/tests/old/perftests/FontCollection.cpp index 1ec4741ddd..eb5592894d 100644 --- a/engine/src/flutter/third_party/txt/tests/old/perftests/FontCollection.cpp +++ b/engine/src/flutter/third_party/txt/tests/old/perftests/FontCollection.cpp @@ -90,7 +90,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) { FontStyle style(FontStyle::registerLanguageList( ITEMIZE_TEST_CASES[testIndex].languageTag)); - std::lock_guard _l(gMinikinLock); + std::scoped_lock _l(gMinikinLock); while (state.KeepRunning()) { result.clear(); collection->itemize(buffer, utf16_length, style, &result);