From 9c20e63bf3a4cdafcfe224b56970740d42fb91a6 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 20 Mar 2018 19:03:46 -0700 Subject: [PATCH] Updates in flutter/synchronization for the shell refactor (Patch 10) This changes is part of a large patch for easier review. Try the whole patch in one go by checking out https://github.com/chinmaygarde/flutter_engine/tree/shell directly. This patch contains the following changes: * Fix and issue with the dispatch semaphore collection causing a crash due to the semaphore not being at the initial count. This can happen if the shell is torn down when there are frames in flight. Was only an issue on Mac and never surfaced earlier because we never tore down these things. * Remove asserts that relied on access to singletons. The same assertions are now perfored on use of weak pointers vended by factories in FML. --- synchronization/BUILD.gn | 5 +---- synchronization/debug_thread_checker.h | 25 ------------------------- synchronization/semaphore.cc | 6 +++++- 3 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 synchronization/debug_thread_checker.h diff --git a/synchronization/BUILD.gn b/synchronization/BUILD.gn index 977a571c8da30..9ee7680cc1160 100644 --- a/synchronization/BUILD.gn +++ b/synchronization/BUILD.gn @@ -4,16 +4,13 @@ source_set("synchronization") { sources = [ - "debug_thread_checker.h", "pipeline.cc", "pipeline.h", "semaphore.cc", "semaphore.h", ] - public_configs = [ - "$flutter_root:config", - ] + public_configs = [ "$flutter_root:config" ] public_deps = [ "$flutter_root/glue", diff --git a/synchronization/debug_thread_checker.h b/synchronization/debug_thread_checker.h deleted file mode 100644 index 69614eb89d217..0000000000000 --- a/synchronization/debug_thread_checker.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SYNCHRONIZATION_DEBUG_THREAD_CHECKER_H_ -#define FLUTTER_SYNCHRONIZATION_DEBUG_THREAD_CHECKER_H_ - -#ifndef NDEBUG - -#include -#include "lib/fxl/synchronization/thread_checker.h" - -#define FLUTTER_THREAD_CHECKER_DECLARE(x) ::fxl::ThreadChecker x; - -#define FLUTTER_THREAD_CHECKER_CHECK(x) FXL_CHECK(x.IsCreationThreadCurrent()); - -#else // NDEBUG - -#define FLUTTER_THREAD_CHECKER_DECLARE(x) - -#define FLUTTER_THREAD_CHECKER_CHECK(x) - -#endif // NDEBUG - -#endif // FLUTTER_SYNCHRONIZATION_DEBUG_THREAD_CHECKER_H_ diff --git a/synchronization/semaphore.cc b/synchronization/semaphore.cc index c6e0bdf9e2d53..4dc5f6220e350 100644 --- a/synchronization/semaphore.cc +++ b/synchronization/semaphore.cc @@ -15,9 +15,12 @@ namespace flutter { class PlatformSemaphore { public: explicit PlatformSemaphore(uint32_t count) - : _sem(dispatch_semaphore_create(count)) {} + : _sem(dispatch_semaphore_create(count)), _initial(count) {} ~PlatformSemaphore() { + for (uint32_t i = 0; i < _initial; ++i) { + Signal(); + } if (_sem != nullptr) { dispatch_release(reinterpret_cast(_sem)); _sem = nullptr; @@ -42,6 +45,7 @@ class PlatformSemaphore { private: dispatch_semaphore_t _sem; + const uint32_t _initial; FXL_DISALLOW_COPY_AND_ASSIGN(PlatformSemaphore); };