未验证 提交 a925df18 编写于 作者: C Chinmay Garde 提交者: GitHub

Remove incomplete static thread safety annotations. (#13151)

Fixes https://github.com/flutter/flutter/issues/42704.
上级 ee1a140f
......@@ -203,8 +203,6 @@ FILE: ../../../flutter/fml/synchronization/semaphore_unittest.cc
FILE: ../../../flutter/fml/synchronization/shared_mutex.h
FILE: ../../../flutter/fml/synchronization/shared_mutex_std.cc
FILE: ../../../flutter/fml/synchronization/shared_mutex_std.h
FILE: ../../../flutter/fml/synchronization/thread_annotations.h
FILE: ../../../flutter/fml/synchronization/thread_annotations_unittest.cc
FILE: ../../../flutter/fml/synchronization/waitable_event.cc
FILE: ../../../flutter/fml/synchronization/waitable_event.h
FILE: ../../../flutter/fml/synchronization/waitable_event_unittest.cc
......
......@@ -60,7 +60,6 @@ source_set("fml") {
"synchronization/semaphore.cc",
"synchronization/semaphore.h",
"synchronization/shared_mutex.h",
"synchronization/thread_annotations.h",
"synchronization/waitable_event.cc",
"synchronization/waitable_event.h",
"task_runner.cc",
......@@ -212,7 +211,6 @@ executable("fml_unittests") {
"platform/darwin/string_range_sanitization_unittests.mm",
"synchronization/count_down_latch_unittests.cc",
"synchronization/semaphore_unittest.cc",
"synchronization/thread_annotations_unittest.cc",
"synchronization/waitable_event_unittest.cc",
"thread_local_unittests.cc",
"thread_unittests.cc",
......
......@@ -11,7 +11,6 @@
#include "flutter/fml/closure.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
namespace fml {
......
......@@ -18,7 +18,6 @@
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/message_loop_task_queues.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_point.h"
#include "flutter/fml/wakeable.h"
......
......@@ -14,7 +14,6 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/wakeable.h"
namespace fml {
......@@ -146,8 +145,7 @@ class MessageLoopTaskQueues
fml::TimePoint GetNextWakeTimeUnlocked(TaskQueueId queue_id) const;
static std::mutex creation_mutex_;
static fml::RefPtr<MessageLoopTaskQueues> instance_
FML_GUARDED_BY(creation_mutex_);
static fml::RefPtr<MessageLoopTaskQueues> instance_;
std::unique_ptr<fml::SharedMutex> queue_meta_mutex_;
std::map<TaskQueueId, std::unique_ptr<TaskQueueEntry>> queue_entries_;
......
......@@ -7,6 +7,7 @@
#include <iostream>
#include <thread>
#include "flutter/fml/build_config.h"
#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/synchronization/count_down_latch.h"
......
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Macros for static thread-safety analysis.
//
// These are from http://clang.llvm.org/docs/ThreadSafetyAnalysis.html (and thus
// really derive from google3's thread_annotations.h).
//
// TODO(vtl): We're still using the old-fashioned, deprecated annotations
// ("locks" instead of "capabilities"), since the new ones don't work yet (in
// particular, |TRY_ACQUIRE()| doesn't work: b/19264527).
// https://github.com/domokit/mojo/issues/314
#ifndef FLUTTER_FML_SYNCHRONIZATION_THREAD_ANNOTATIONS_H_
#define FLUTTER_FML_SYNCHRONIZATION_THREAD_ANNOTATIONS_H_
#include "flutter/fml/build_config.h"
// Enable thread-safety attributes only with clang.
// The attributes can be safely erased when compiling with other compilers.
#if defined(__clang__) && !defined(OS_ANDROID)
#define FML_THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
#define FML_THREAD_ANNOTATION_ATTRIBUTE__(x)
#endif
#define FML_GUARDED_BY(x) FML_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
#define FML_PT_GUARDED_BY(x) FML_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
#define FML_ACQUIRE(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
#define FML_RELEASE(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
#define FML_ACQUIRED_AFTER(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
#define FML_ACQUIRED_BEFORE(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
#define FML_EXCLUSIVE_LOCKS_REQUIRED(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
#define FML_SHARED_LOCKS_REQUIRED(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
#define FML_LOCKS_EXCLUDED(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
#define FML_LOCK_RETURNED(x) FML_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
#define FML_LOCKABLE FML_THREAD_ANNOTATION_ATTRIBUTE__(lockable)
#define FML_SCOPED_LOCKABLE FML_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
#define FML_EXCLUSIVE_LOCK_FUNCTION(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
#define FML_SHARED_LOCK_FUNCTION(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
#define FML_ASSERT_EXCLUSIVE_LOCK(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
#define FML_ASSERT_SHARED_LOCK(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
#define FML_EXCLUSIVE_TRYLOCK_FUNCTION(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
#define FML_SHARED_TRYLOCK_FUNCTION(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
#define FML_UNLOCK_FUNCTION(...) \
FML_THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
#define FML_NO_THREAD_SAFETY_ANALYSIS \
FML_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
// Use this in the header to annotate a function/method as not being
// thread-safe. This is equivalent to |FML_NO_THREAD_SAFETY_ANALYSIS|, but
// semantically different: it declares that the caller must abide by additional
// restrictions. Limitation: Unfortunately, you can't apply this to a method in
// an interface (i.e., pure virtual method) and have it applied automatically to
// implementations.
#define FML_NOT_THREAD_SAFE FML_NO_THREAD_SAFETY_ANALYSIS
#endif // FLUTTER_FML_SYNCHRONIZATION_THREAD_ANNOTATIONS_H_
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests of the static thread annotation macros. These fall into two categories,
// positive tests (testing that correct code compiles and works) and negative
// tests (testing that incorrect code does not compile).
//
// Unfortunately, we don't have systematic/automated negative compilation tests.
// So instead we have some cheesy macros that you can define to enable
// individual compilation failures.
#include "flutter/fml/synchronization/thread_annotations.h"
#include <mutex>
#include "flutter/fml/macros.h"
#include "gtest/gtest.h"
// Uncomment these to enable particular compilation failure tests.
// #define NC_GUARDED_BY
// TODO(vtl): |ACQUIRED_{BEFORE,AFTER}()| are currently unimplemented in clang
// as of 2015-07-06 ("To be fixed in a future update."). So this actually
// compiles!
// #define NC_ACQUIRED_BEFORE
namespace fml {
namespace {
// Test FML_GUARDED_BY ---------------------------------------------------------
class GuardedByClass {
public:
GuardedByClass() : x_() {}
~GuardedByClass() {}
void GoodSet(int x) {
mu_.lock();
x_ = x;
mu_.unlock();
}
#ifdef NC_GUARDED_BY
void BadSet(int x) { x_ = x; }
#endif
private:
std::mutex mu_;
int x_ FML_GUARDED_BY(mu_);
FML_DISALLOW_COPY_AND_ASSIGN(GuardedByClass);
};
TEST(ThreadAnnotationsTest, GuardedBy) {
GuardedByClass c;
c.GoodSet(123);
}
// Test FML_ACQUIRED_BEFORE ----------------------------------------------------
class AcquiredBeforeClass2;
class AcquiredBeforeClass1 {
public:
AcquiredBeforeClass1() {}
~AcquiredBeforeClass1() {}
void NoOp() {
mu_.lock();
mu_.unlock();
}
#ifdef NC_ACQUIRED_BEFORE
void BadMethod(AcquiredBeforeClass2* c2);
#endif
private:
friend class AcquiredBeforeClass2;
std::mutex mu_;
FML_DISALLOW_COPY_AND_ASSIGN(AcquiredBeforeClass1);
};
class AcquiredBeforeClass2 {
public:
AcquiredBeforeClass2() {}
~AcquiredBeforeClass2() {}
void NoOp() {
mu_.lock();
mu_.unlock();
}
void GoodMethod(AcquiredBeforeClass1* c1) {
mu_.lock();
c1->NoOp();
mu_.unlock();
}
private:
std::mutex mu_ FML_ACQUIRED_BEFORE(AcquiredBeforeClass1::mu_);
FML_DISALLOW_COPY_AND_ASSIGN(AcquiredBeforeClass2);
};
#ifdef NC_ACQUIRED_BEFORE
void AcquiredBeforeClass1::BadMethod(AcquiredBeforeClass2* c2) {
mu_.lock();
c2->NoOp();
mu_.unlock();
}
#endif
TEST(ThreadAnnotationsTest, AcquiredBefore) {
AcquiredBeforeClass1 c1;
AcquiredBeforeClass2 c2;
c2.GoodMethod(&c1);
#ifdef NC_ACQUIRED_BEFORE
c1.BadMethod(&c2);
#endif
}
// TODO(vtl): Test more things.
} // namespace
} // namespace fml
......@@ -150,7 +150,7 @@ bool ManualResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) {
// holding |mutex_|.
bool rv = WaitWithTimeoutImpl(
&locker, &cv_,
[this, last_signal_id]() FML_NO_THREAD_SAFETY_ANALYSIS {
[this, last_signal_id]() {
// Also check |signaled_| in case we're already signaled.
return signaled_ || signal_id_ != last_signal_id;
},
......
......@@ -14,7 +14,6 @@
#include <mutex>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_delta.h"
namespace fml {
......
......@@ -10,7 +10,6 @@
#include <string>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "third_party/dart/runtime/include/dart_api.h"
namespace flutter {
......@@ -23,25 +22,21 @@ class IsolateNameServer {
// Looks up the Dart_Port associated with a given name. Returns ILLEGAL_PORT
// if the name does not exist.
Dart_Port LookupIsolatePortByName(const std::string& name)
FML_LOCKS_EXCLUDED(mutex_);
Dart_Port LookupIsolatePortByName(const std::string& name);
// Registers a Dart_Port with a given name. Returns true if registration is
// successful, false if the name entry already exists.
bool RegisterIsolatePortWithName(Dart_Port port, const std::string& name)
FML_LOCKS_EXCLUDED(mutex_);
bool RegisterIsolatePortWithName(Dart_Port port, const std::string& name);
// Removes a name to Dart_Port mapping given a name. Returns true if the
// mapping was successfully removed, false if the mapping does not exist.
bool RemoveIsolateNameMapping(const std::string& name)
FML_LOCKS_EXCLUDED(mutex_);
bool RemoveIsolateNameMapping(const std::string& name);
private:
Dart_Port LookupIsolatePortByNameUnprotected(const std::string& name)
FML_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Dart_Port LookupIsolatePortByNameUnprotected(const std::string& name);
mutable std::mutex mutex_;
std::map<std::string, Dart_Port> port_mapping_ FML_GUARDED_BY(mutex_);
std::map<std::string, Dart_Port> port_mapping_;
FML_DISALLOW_COPY_AND_ASSIGN(IsolateNameServer);
};
......
......@@ -11,7 +11,6 @@
#include <string>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "third_party/dart/runtime/include/dart_api.h"
namespace flutter {
......@@ -29,28 +28,26 @@ class DartCallbackCache {
static int64_t GetCallbackHandle(const std::string& name,
const std::string& class_name,
const std::string& library_path)
FML_LOCKS_EXCLUDED(mutex_);
const std::string& library_path);
static Dart_Handle GetCallback(int64_t handle) FML_LOCKS_EXCLUDED(mutex_);
static Dart_Handle GetCallback(int64_t handle);
static std::unique_ptr<DartCallbackRepresentation> GetCallbackInformation(
int64_t handle) FML_LOCKS_EXCLUDED(mutex_);
int64_t handle);
static void LoadCacheFromDisk() FML_LOCKS_EXCLUDED(mutex_);
static void LoadCacheFromDisk();
private:
static Dart_Handle LookupDartClosure(const std::string& name,
const std::string& class_name,
const std::string& library_path);
static void SaveCacheToDisk() FML_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
static void SaveCacheToDisk();
static std::mutex mutex_;
static std::string cache_path_;
static std::map<int64_t, DartCallbackRepresentation> cache_
FML_GUARDED_BY(mutex_);
static std::map<int64_t, DartCallbackRepresentation> cache_;
FML_DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallbackCache);
};
......
......@@ -50,7 +50,6 @@ const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
std::mutex DartServiceIsolate::callbacks_mutex_;
FML_GUARDED_BY(DartServiceIsolate::callbacks_mutex_)
std::set<std::unique_ptr<DartServiceIsolate::ObservatoryServerStateCallback>>
DartServiceIsolate::callbacks_;
......
......@@ -11,7 +11,6 @@
#include <string>
#include "flutter/fml/compiler_specific.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "third_party/dart/runtime/include/dart_api.h"
......@@ -46,8 +45,7 @@ class DartServiceIsolate {
static void Shutdown(Dart_NativeArguments args);
static std::mutex callbacks_mutex_;
static std::set<std::unique_ptr<ObservatoryServerStateCallback>> callbacks_
FML_GUARDED_BY(callbacks_mutex_);
static std::set<std::unique_ptr<ObservatoryServerStateCallback>> callbacks_;
};
} // namespace flutter
......
......@@ -17,7 +17,6 @@
#include "flutter/fml/mapping.h"
#include "flutter/fml/size.h"
#include "flutter/fml/synchronization/count_down_latch.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/io/dart_io.h"
......
......@@ -12,8 +12,8 @@ namespace flutter {
// critical section. All accesses (not just const members) to the global VM
// object weak pointer are behind this mutex.
static std::mutex gVMMutex;
static std::weak_ptr<DartVM> gVM FML_GUARDED_BY(gVMMutex);
static std::shared_ptr<DartVM>* gVMLeak FML_GUARDED_BY(gVMMutex);
static std::weak_ptr<DartVM> gVM;
static std::shared_ptr<DartVM>* gVMLeak;
// We are going to be modifying more than just the control blocks of the
// following weak pointers (in the |Create| case where an old VM could not be
......@@ -21,12 +21,9 @@ static std::shared_ptr<DartVM>* gVMLeak FML_GUARDED_BY(gVMMutex);
// but that is only available since C++20. We don't expect contention on these
// locks so we just use one mutex for all.
static std::mutex gVMDependentsMutex;
static std::weak_ptr<const DartVMData> gVMData
FML_GUARDED_BY(gVMDependentsMutex);
static std::weak_ptr<ServiceProtocol> gVMServiceProtocol
FML_GUARDED_BY(gVMDependentsMutex);
static std::weak_ptr<IsolateNameServer> gVMIsolateNameServer
FML_GUARDED_BY(gVMDependentsMutex);
static std::weak_ptr<const DartVMData> gVMData;
static std::weak_ptr<ServiceProtocol> gVMServiceProtocol;
static std::weak_ptr<IsolateNameServer> gVMIsolateNameServer;
DartVMRef::DartVMRef(std::shared_ptr<DartVM> vm) : vm_(vm) {}
......
......@@ -14,7 +14,6 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/atomic_object.h"
#include "flutter/fml/synchronization/shared_mutex.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/task_runner.h"
#include "rapidjson/document.h"
......
......@@ -10,7 +10,6 @@
#include <set>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/task_runner.h"
#include "flutter/fml/unique_fd.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
......@@ -66,8 +65,7 @@ class PersistentCache : public GrContextOptions::PersistentCache {
static std::string cache_base_path_;
static std::mutex instance_mutex_;
static std::unique_ptr<PersistentCache> gPersistentCache
FML_GUARDED_BY(instance_mutex_);
static std::unique_ptr<PersistentCache> gPersistentCache;
// Mutable static switch that can be set before GetCacheForProcess is called
// and GrContextOptions.fShaderCacheStrategy is set. If true, it means that
......@@ -83,8 +81,7 @@ class PersistentCache : public GrContextOptions::PersistentCache {
const std::shared_ptr<fml::UniqueFD> cache_directory_;
const std::shared_ptr<fml::UniqueFD> sksl_cache_directory_;
mutable std::mutex worker_task_runners_mutex_;
std::multiset<fml::RefPtr<fml::TaskRunner>> worker_task_runners_
FML_GUARDED_BY(worker_task_runners_mutex_);
std::multiset<fml::RefPtr<fml::TaskRunner>> worker_task_runners_;
bool stored_new_shaders_ = false;
bool is_dumping_skp_ = false;
......
......@@ -18,7 +18,6 @@
#include "flutter/fml/memory/thread_checker.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/status.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/fml/thread.h"
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
......
......@@ -10,7 +10,6 @@
#include "flutter/common/settings.h"
#include "flutter/flow/layers/container_layer.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell.h"
......@@ -101,8 +100,8 @@ class ShellTestVsyncClock {
private:
std::mutex mutex_;
std::vector<std::promise<int>> vsync_promised_ FML_GUARDED_BY(mutex_);
size_t vsync_issued_ FML_GUARDED_BY(mutex_) = 0;
std::vector<std::promise<int>> vsync_promised_;
size_t vsync_issued_ = 0;
};
class ShellTestVsyncWaiter : public VsyncWaiter {
......
......@@ -10,7 +10,6 @@
#include <mutex>
#include "flutter/common/task_runners.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_point.h"
namespace flutter {
......@@ -58,10 +57,10 @@ class VsyncWaiter : public std::enable_shared_from_this<VsyncWaiter> {
private:
std::mutex callback_mutex_;
Callback callback_ FML_GUARDED_BY(callback_mutex_);
Callback callback_;
std::mutex secondary_callback_mutex_;
fml::closure secondary_callback_ FML_GUARDED_BY(callback_mutex_);
fml::closure secondary_callback_;
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiter);
};
......
......@@ -66,7 +66,7 @@ class PlatformViewIOS final : public PlatformView {
// Since the `ios_surface_` is created on the platform thread but
// used on the GPU thread we need to protect it with a mutex.
std::mutex ios_surface_mutex_;
std::unique_ptr<IOSSurface> ios_surface_ FML_GUARDED_BY(ios_surface_mutex_);
std::unique_ptr<IOSSurface> ios_surface_;
std::shared_ptr<IOSGLContext> gl_context_;
PlatformMessageRouter platform_message_router_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
......
......@@ -9,7 +9,6 @@
#include <unordered_map>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/task_runner.h"
namespace flutter {
......@@ -76,9 +75,8 @@ class EmbedderTaskRunner final : public fml::TaskRunner {
const size_t embedder_identifier_;
DispatchTable dispatch_table_;
std::mutex tasks_mutex_;
uint64_t last_baton_ FML_GUARDED_BY(tasks_mutex_);
std::unordered_map<uint64_t, fml::closure> pending_tasks_
FML_GUARDED_BY(tasks_mutex_);
uint64_t last_baton_;
std::unordered_map<uint64_t, fml::closure> pending_tasks_;
fml::TaskQueueId placeholder_id_;
// |fml::TaskRunner|
......
......@@ -8,7 +8,6 @@
#include <vector>
#include "flutter/fml/logging.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "third_party/tonic/logging/dart_error.h"
#include "tonic/converter/dart_converter.h"
......@@ -36,7 +35,7 @@ Dart_NativeFunction TestDartNativeResolver::ResolveCallback(
static std::mutex gIsolateResolversMutex;
static std::map<Dart_Isolate, std::weak_ptr<TestDartNativeResolver>>
gIsolateResolvers FML_GUARDED_BY(gIsolateResolversMutex);
gIsolateResolvers;
Dart_NativeFunction TestDartNativeResolver::DartNativeEntryResolverCallback(
Dart_Handle dart_name,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册