Skip to content

Commit

Permalink
Switch from fxl::Mutex to std::mutex (flutter#4764)
Browse files Browse the repository at this point in the history
We're going to remove fxl::Mutex soon.
  • Loading branch information
abarth authored Mar 9, 2018
1 parent debf82c commit 14c940e
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 38 deletions.
2 changes: 0 additions & 2 deletions flow/export_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions fml/message_loop_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = {};
}

Expand All @@ -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);
}
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions fml/message_loop_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <atomic>
#include <deque>
#include <mutex>
#include <queue>
#include <set>
#include <utility>
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions lib/ui/painting/resource_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ui/painting/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/painting/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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>
Expand Down
9 changes: 5 additions & 4 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -203,15 +204,15 @@ 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);
}

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);
}

Expand All @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef SHELL_COMMON_SHELL_H_
#define SHELL_COMMON_SHELL_H_

#include <mutex>
#include <unordered_set>

#include "flutter/fml/thread.h"
Expand All @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions synchronization/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down

0 comments on commit 14c940e

Please sign in to comment.