Switch from fxl::Mutex to std::mutex (flutter/engine#4764)
We're going to remove fxl::Mutex soon.
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
#include "lib/fxl/build_config.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
#include "lib/fxl/synchronization/thread_annotations.h"
|
||||
#include "lib/ui/scenic/client/resources.h"
|
||||
#include "third_party/skia/include/core/SkPoint.h"
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ void MessageLoopImpl::DoRun() {
|
||||
// should be destructed on the message loop's thread. We have just returned
|
||||
// from the implementations |Run| method which we know is on the correct
|
||||
// thread. Drop all pending tasks on the floor.
|
||||
fxl::MutexLocker lock(&delayed_tasks_mutex_);
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
delayed_tasks_ = {};
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ void MessageLoopImpl::RegisterTask(fxl::Closure task,
|
||||
// |task| synchronously within this function.
|
||||
return;
|
||||
}
|
||||
fxl::MutexLocker lock(&delayed_tasks_mutex_);
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
delayed_tasks_.push({++order_, std::move(task), target_time});
|
||||
WakeUp(delayed_tasks_.top().target_time);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void MessageLoopImpl::RunExpiredTasks() {
|
||||
std::vector<fxl::Closure> invocations;
|
||||
|
||||
{
|
||||
fxl::MutexLocker lock(&delayed_tasks_mutex_);
|
||||
std::lock_guard<std::mutex> lock(delayed_tasks_mutex_);
|
||||
|
||||
if (delayed_tasks_.empty()) {
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
@@ -15,8 +16,6 @@
|
||||
#include "lib/fxl/functional/closure.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
#include "lib/fxl/synchronization/thread_annotations.h"
|
||||
#include "lib/fxl/time/time_point.h"
|
||||
|
||||
namespace fml {
|
||||
@@ -73,9 +72,9 @@ class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {
|
||||
priority_queue<DelayedTask, std::deque<DelayedTask>, DelayedTaskCompare>;
|
||||
|
||||
std::set<TaskObserver*> task_observers_;
|
||||
fxl::Mutex delayed_tasks_mutex_;
|
||||
DelayedTaskQueue delayed_tasks_ FXL_GUARDED_BY(delayed_tasks_mutex_);
|
||||
size_t order_ FXL_GUARDED_BY(delayed_tasks_mutex_);
|
||||
std::mutex delayed_tasks_mutex_;
|
||||
DelayedTaskQueue delayed_tasks_;
|
||||
size_t order_;
|
||||
std::atomic_bool terminated_;
|
||||
|
||||
void RegisterTask(fxl::Closure task, fxl::TimePoint target_time);
|
||||
|
||||
@@ -4,24 +4,25 @@
|
||||
|
||||
#include "flutter/lib/ui/painting/resource_context.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
static GrContext* g_context = nullptr;
|
||||
static fxl::Mutex g_mutex;
|
||||
static std::mutex g_mutex;
|
||||
static volatile bool g_freeze = false;
|
||||
|
||||
} // namespace
|
||||
|
||||
ResourceContext::ResourceContext() {
|
||||
g_mutex.Lock();
|
||||
g_mutex.lock();
|
||||
}
|
||||
|
||||
ResourceContext::~ResourceContext() {
|
||||
g_mutex.Unlock();
|
||||
g_mutex.unlock();
|
||||
}
|
||||
|
||||
void ResourceContext::Set(sk_sp<GrContext> context) {
|
||||
@@ -38,12 +39,12 @@ std::unique_ptr<ResourceContext> ResourceContext::Acquire() {
|
||||
}
|
||||
|
||||
void ResourceContext::Freeze() {
|
||||
fxl::MutexLocker lock(&g_mutex);
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
g_freeze = true;
|
||||
}
|
||||
|
||||
void ResourceContext::Unfreeze() {
|
||||
fxl::MutexLocker lock(&g_mutex);
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
g_freeze = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ SkiaUnrefQueue& SkiaUnrefQueue::Get() {
|
||||
}
|
||||
|
||||
void SkiaUnrefQueue::Unref(SkRefCnt* object) {
|
||||
fxl::MutexLocker lock(&mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
objects_.push_back(object);
|
||||
if (!drain_pending_) {
|
||||
drain_pending_ = true;
|
||||
@@ -33,7 +33,7 @@ void SkiaUnrefQueue::Unref(SkRefCnt* object) {
|
||||
void SkiaUnrefQueue::Drain() {
|
||||
std::deque<SkRefCnt*> skia_objects;
|
||||
{
|
||||
fxl::MutexLocker lock(&mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
objects_.swap(skia_objects);
|
||||
drain_pending_ = false;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace blink {
|
||||
@@ -22,9 +22,9 @@ class SkiaUnrefQueue {
|
||||
|
||||
static SkiaUnrefQueue instance_;
|
||||
|
||||
fxl::Mutex mutex_;
|
||||
std::deque<SkRefCnt*> objects_ FXL_GUARDED_BY(mutex_);
|
||||
bool drain_pending_ FXL_GUARDED_BY(mutex_);
|
||||
std::mutex mutex_;
|
||||
std::deque<SkRefCnt*> objects_;
|
||||
bool drain_pending_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -84,7 +84,8 @@ void Shell::InitStandalone(fxl::CommandLine command_line,
|
||||
|
||||
fml::icu::InitializeICU(icu_data_path);
|
||||
|
||||
if (!command_line.HasOption(FlagForSwitch(Switch::SkiaDeterministicRendering)))
|
||||
if (!command_line.HasOption(
|
||||
FlagForSwitch(Switch::SkiaDeterministicRendering)))
|
||||
SkGraphics::Init();
|
||||
|
||||
blink::Settings settings;
|
||||
@@ -203,7 +204,7 @@ void Shell::AddPlatformView(PlatformView* platform_view) {
|
||||
if (platform_view == nullptr) {
|
||||
return;
|
||||
}
|
||||
fxl::MutexLocker lock(&platform_views_mutex_);
|
||||
std::lock_guard<std::mutex> lock(platform_views_mutex_);
|
||||
platform_views_.insert(platform_view);
|
||||
}
|
||||
|
||||
@@ -211,7 +212,7 @@ void Shell::RemovePlatformView(PlatformView* platform_view) {
|
||||
if (platform_view == nullptr) {
|
||||
return;
|
||||
}
|
||||
fxl::MutexLocker lock(&platform_views_mutex_);
|
||||
std::lock_guard<std::mutex> lock(platform_views_mutex_);
|
||||
platform_views_.erase(platform_view);
|
||||
}
|
||||
|
||||
@@ -220,7 +221,7 @@ void Shell::IteratePlatformViews(
|
||||
if (iterator == nullptr) {
|
||||
return;
|
||||
}
|
||||
fxl::MutexLocker lock(&platform_views_mutex_);
|
||||
std::lock_guard<std::mutex> lock(platform_views_mutex_);
|
||||
for (PlatformView* view : platform_views_) {
|
||||
if (!iterator(view)) {
|
||||
return;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef SHELL_COMMON_SHELL_H_
|
||||
#define SHELL_COMMON_SHELL_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "flutter/fml/thread.h"
|
||||
@@ -14,8 +15,6 @@
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_ptr.h"
|
||||
#include "lib/fxl/memory/weak_ptr.h"
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
#include "lib/fxl/synchronization/thread_annotations.h"
|
||||
#include "lib/fxl/synchronization/thread_checker.h"
|
||||
#include "lib/fxl/synchronization/waitable_event.h"
|
||||
#include "lib/fxl/tasks/task_runner.h"
|
||||
@@ -68,9 +67,8 @@ class Shell {
|
||||
std::unique_ptr<fxl::ThreadChecker> gpu_thread_checker_;
|
||||
std::unique_ptr<fxl::ThreadChecker> ui_thread_checker_;
|
||||
TracingController tracing_controller_;
|
||||
mutable fxl::Mutex platform_views_mutex_;
|
||||
std::unordered_set<PlatformView*> platform_views_
|
||||
FXL_GUARDED_BY(platform_views_mutex_);
|
||||
mutable std::mutex platform_views_mutex_;
|
||||
std::unordered_set<PlatformView*> platform_views_;
|
||||
|
||||
static void Init(fxl::CommandLine command_line,
|
||||
const std::string& bundle_path);
|
||||
|
||||
@@ -11,10 +11,9 @@
|
||||
#include "lib/fxl/functional/closure.h"
|
||||
#include "lib/fxl/macros.h"
|
||||
#include "lib/fxl/memory/ref_counted.h"
|
||||
#include "lib/fxl/synchronization/mutex.h"
|
||||
#include "lib/fxl/synchronization/thread_annotations.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace flutter {
|
||||
@@ -120,7 +119,7 @@ class Pipeline : public fxl::RefCountedThreadSafe<Pipeline<R>> {
|
||||
size_t items_count = 0;
|
||||
|
||||
{
|
||||
fxl::MutexLocker lock(&queue_mutex_);
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
std::tie(resource, trace_id) = std::move(queue_.front());
|
||||
queue_.pop();
|
||||
items_count = queue_.size();
|
||||
@@ -142,14 +141,13 @@ class Pipeline : public fxl::RefCountedThreadSafe<Pipeline<R>> {
|
||||
private:
|
||||
Semaphore empty_;
|
||||
Semaphore available_;
|
||||
fxl::Mutex queue_mutex_;
|
||||
std::queue<std::pair<ResourcePtr, size_t>> queue_
|
||||
FXL_GUARDED_BY(queue_mutex_);
|
||||
std::mutex queue_mutex_;
|
||||
std::queue<std::pair<ResourcePtr, size_t>> queue_;
|
||||
std::atomic_size_t last_trace_id_;
|
||||
|
||||
void ProducerCommit(ResourcePtr resource, size_t trace_id) {
|
||||
{
|
||||
fxl::MutexLocker lock(&queue_mutex_);
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
queue_.emplace(std::move(resource), trace_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user