Lint fixes for fml, tools subdirs (flutter/engine#19990)

This does lint fixes for the fml and tools subdirs.
This commit is contained in:
Greg Spencer
2020-07-30 19:40:31 +00:00
committed by GitHub
parent 14789402dd
commit d9b08f5411
19 changed files with 137 additions and 98 deletions

View File

@@ -1,7 +1,7 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/ascii_trie.h"
#include "flutter/fml/logging.h"
@@ -38,7 +38,7 @@ bool AsciiTrie::Query(TrieNode* trie, const char* query) {
FML_DCHECK(trie);
const char* char_position = query;
TrieNode* trie_position = trie;
TrieNode* child;
TrieNode* child = nullptr;
int ch;
while ((ch = *char_position) && (child = trie_position->children[ch].get())) {
char_position++;

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/command_line.h"
@@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0,
argv0_(argv0),
options_(options),
positional_args_(positional_args) {
for (size_t i = 0; i < options_.size(); i++)
for (size_t i = 0; i < options_.size(); i++) {
option_index_[options_[i].name] = i;
}
}
CommandLine::~CommandLine() = default;
@@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default;
bool CommandLine::HasOption(std::string_view name, size_t* index) const {
auto it = option_index_.find(name.data());
if (it == option_index_.end())
if (it == option_index_.end()) {
return false;
if (index)
}
if (index) {
*index = it->second;
}
return true;
}
bool CommandLine::GetOptionValue(std::string_view name,
std::string* value) const {
size_t index;
if (!HasOption(name, &index))
if (!HasOption(name, &index)) {
return false;
}
*value = options_[index].value;
return true;
}
@@ -59,8 +62,9 @@ std::vector<std::string_view> CommandLine::GetOptionValues(
std::string_view name) const {
std::vector<std::string_view> ret;
for (const auto& option : options_) {
if (option.name == name)
if (option.name == name) {
ret.push_back(option.value);
}
}
return ret;
}
@@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault(
std::string_view name,
std::string_view default_value) const {
size_t index;
if (!HasOption(name, &index))
if (!HasOption(name, &index)) {
return {default_value.data(), default_value.size()};
}
return options_[index].value;
}
@@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) {
}
CommandLine CommandLineBuilder::Build() const {
if (!has_argv0_)
if (!has_argv0_) {
return CommandLine();
}
return CommandLine(argv0_, options_, positional_args_);
}
} // namespace internal
std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
if (!command_line.has_argv0())
if (!command_line.has_argv0()) {
return std::vector<std::string>();
}
std::vector<std::string> argv;
const std::vector<CommandLine::Option>& options = command_line.options();
@@ -146,17 +153,19 @@ std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
argv.push_back(command_line.argv0());
for (const auto& option : options) {
if (option.value.empty())
if (option.value.empty()) {
argv.push_back("--" + option.name);
else
} else {
argv.push_back("--" + option.name + "=" + option.value);
}
}
if (!positional_args.empty()) {
// Insert a "--" if necessary.
if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
positional_args[0][1] == '-')
positional_args[0][1] == '-') {
argv.push_back("--");
}
argv.insert(argv.end(), positional_args.begin(), positional_args.end());
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/icu_util.h"
@@ -20,11 +19,12 @@ namespace icu {
class ICUContext {
public:
ICUContext(const std::string& icu_data_path) : valid_(false) {
explicit ICUContext(const std::string& icu_data_path) : valid_(false) {
valid_ = SetupMapping(icu_data_path) && SetupICU();
}
ICUContext(std::unique_ptr<Mapping> mapping) : mapping_(std::move(mapping)) {
explicit ICUContext(std::unique_ptr<Mapping> mapping)
: mapping_(std::move(mapping)) {
valid_ = SetupICU();
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include <algorithm>
#include <iostream>
@@ -23,23 +22,26 @@ const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING",
"ERROR", "FATAL"};
const char* GetNameForLogSeverity(LogSeverity severity) {
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES)
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) {
return kLogSeverityNames[severity];
}
return "UNKNOWN";
}
const char* StripDots(const char* path) {
while (strncmp(path, "../", 3) == 0)
while (strncmp(path, "../", 3) == 0) {
path += 3;
}
return path;
}
const char* StripPath(const char* path) {
auto* p = strrchr(path, '/');
if (p)
if (p) {
return p + 1;
else
} else {
return path;
}
}
} // namespace
@@ -50,15 +52,17 @@ LogMessage::LogMessage(LogSeverity severity,
const char* condition)
: severity_(severity), file_(file), line_(line) {
stream_ << "[";
if (severity >= LOG_INFO)
if (severity >= LOG_INFO) {
stream_ << GetNameForLogSeverity(severity);
else
} else {
stream_ << "VERBOSE" << -severity;
}
stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_))
<< "(" << line_ << ")] ";
if (condition)
if (condition) {
stream_ << "Check failed: " << condition << ". ";
}
}
LogMessage::~LogMessage() {

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
// This file tests both ref_counted.h and ref_ptr.h (which the former includes).
// TODO(vtl): Possibly we could separate these tests out better, since a lot of
@@ -47,12 +46,14 @@ class MyClass : public RefCountedThreadSafe<MyClass> {
protected:
MyClass(MyClass** created, bool* was_destroyed)
: was_destroyed_(was_destroyed) {
if (created)
if (created) {
*created = this;
}
}
virtual ~MyClass() {
if (was_destroyed_)
if (was_destroyed_) {
*was_destroyed_ = true;
}
}
private:
@@ -71,8 +72,9 @@ class MySubclass final : public MyClass {
MySubclass(MySubclass** created, bool* was_destroyed)
: MyClass(nullptr, was_destroyed) {
if (created)
if (created) {
*created = this;
}
}
~MySubclass() override {}
@@ -225,7 +227,7 @@ TEST(RefCountedTest, NullAssignmentToNull) {
// No-op null assignment using move constructor.
r1 = std::move(r2);
EXPECT_TRUE(r1.get() == nullptr);
EXPECT_TRUE(r2.get() == nullptr);
EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
EXPECT_FALSE(r1);
EXPECT_FALSE(r2);
@@ -270,7 +272,7 @@ TEST(RefCountedTest, NonNullAssignmentToNull) {
RefPtr<MyClass> r2;
// Move assignment (to null ref pointer).
r2 = std::move(r1);
EXPECT_TRUE(r1.get() == nullptr);
EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
EXPECT_EQ(created, r2.get());
EXPECT_FALSE(r1);
EXPECT_TRUE(r2);
@@ -334,7 +336,7 @@ TEST(RefCountedTest, NullAssignmentToNonNull) {
// Null assignment using move constructor.
r1 = std::move(r2);
EXPECT_TRUE(r1.get() == nullptr);
EXPECT_TRUE(r2.get() == nullptr);
EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
EXPECT_FALSE(r1);
EXPECT_FALSE(r2);
EXPECT_TRUE(was_destroyed);
@@ -387,7 +389,7 @@ TEST(RefCountedTest, NonNullAssignmentToNonNull) {
RefPtr<MyClass> r2(MakeRefCounted<MyClass>(nullptr, &was_destroyed2));
// Move assignment (to non-null ref pointer).
r2 = std::move(r1);
EXPECT_TRUE(r1.get() == nullptr);
EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
EXPECT_FALSE(r2.get() == nullptr);
EXPECT_FALSE(r1);
EXPECT_TRUE(r2);
@@ -596,13 +598,14 @@ TEST(RefCountedTest, PublicCtorAndDtor) {
TEST(RefCountedTest, DebugChecks) {
{
MyPublicClass* p = new MyPublicClass();
EXPECT_DEATH_IF_SUPPORTED(delete p, "!adoption_required_");
EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
delete p, "!adoption_required_");
}
{
MyPublicClass* p = new MyPublicClass();
EXPECT_DEATH_IF_SUPPORTED(RefPtr<MyPublicClass> r(p),
"!adoption_required_");
EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
RefPtr<MyPublicClass> r(p), "!adoption_required_");
}
{

View File

@@ -66,7 +66,8 @@ template <typename T>
class RefPtr final {
public:
RefPtr() : ptr_(nullptr) {}
RefPtr(std::nullptr_t) : ptr_(nullptr) {}
RefPtr(std::nullptr_t)
: ptr_(nullptr) {} // NOLINT(google-explicit-constructor)
// Explicit constructor from a plain pointer (to an object that must have
// already been adopted). (Note that in |T::T()|, references to |this| cannot
@@ -74,34 +75,39 @@ class RefPtr final {
// yet.)
template <typename U>
explicit RefPtr(U* p) : ptr_(p) {
if (ptr_)
if (ptr_) {
ptr_->AddRef();
}
}
// Copy constructor.
RefPtr(const RefPtr<T>& r) : ptr_(r.ptr_) {
if (ptr_)
if (ptr_) {
ptr_->AddRef();
}
}
template <typename U>
RefPtr(const RefPtr<U>& r) : ptr_(r.ptr_) {
if (ptr_)
RefPtr(const RefPtr<U>& r)
: ptr_(r.ptr_) { // NOLINT(google-explicit-constructor)
if (ptr_) {
ptr_->AddRef();
}
}
// Move constructor.
RefPtr(RefPtr<T>&& r) : ptr_(r.ptr_) { r.ptr_ = nullptr; }
template <typename U>
RefPtr(RefPtr<U>&& r) : ptr_(r.ptr_) {
RefPtr(RefPtr<U>&& r) : ptr_(r.ptr_) { // NOLINT(google-explicit-constructor)
r.ptr_ = nullptr;
}
// Destructor.
~RefPtr() {
if (ptr_)
if (ptr_) {
ptr_->Release();
}
}
T* get() const { return ptr_; }
@@ -118,25 +124,34 @@ class RefPtr final {
// Copy assignment.
RefPtr<T>& operator=(const RefPtr<T>& r) {
// Call |AddRef()| first so self-assignments work.
if (r.ptr_)
// Handle self-assignment.
if (r.ptr_ == ptr_) {
return *this;
}
if (r.ptr_) {
r.ptr_->AddRef();
}
T* old_ptr = ptr_;
ptr_ = r.ptr_;
if (old_ptr)
if (old_ptr) {
old_ptr->Release();
}
return *this;
}
template <typename U>
RefPtr<T>& operator=(const RefPtr<U>& r) {
// Call |AddRef()| first so self-assignments work.
if (r.ptr_)
if (reinterpret_cast<T*>(r.ptr_) == ptr_) {
return *this;
}
if (r.ptr_) {
r.ptr_->AddRef();
}
T* old_ptr = ptr_;
ptr_ = r.ptr_;
if (old_ptr)
if (old_ptr) {
old_ptr->Release();
}
return *this;
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#define FML_USED_ON_EMBEDDER
@@ -39,7 +38,7 @@ TEST(WeakPtrTest, MoveConstruction) {
WeakPtrFactory<int> factory(&data);
WeakPtr<int> ptr = factory.GetWeakPtr();
WeakPtr<int> ptr2(std::move(ptr));
EXPECT_EQ(nullptr, ptr.get());
EXPECT_EQ(nullptr, ptr.get()); // NOLINT
EXPECT_EQ(&data, ptr2.get());
}
@@ -61,7 +60,7 @@ TEST(WeakPtrTest, MoveAssignment) {
WeakPtr<int> ptr2;
EXPECT_EQ(nullptr, ptr2.get());
ptr2 = std::move(ptr);
EXPECT_EQ(nullptr, ptr.get());
EXPECT_EQ(nullptr, ptr.get()); // NOLINT
EXPECT_EQ(&data, ptr2.get());
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include <cassert>
#include <string>
@@ -14,7 +13,7 @@
namespace fml {
namespace benchmarking {
static void BM_RegisterAndGetTasks(benchmark::State& state) {
static void BM_RegisterAndGetTasks(benchmark::State& state) { // NOLINT
while (state.KeepRunning()) {
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#define FML_USED_ON_EMBEDDER
@@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable {
public:
using WakeUpCall = std::function<void(const fml::TimePoint)>;
TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); }

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#define FML_USED_ON_EMBEDDER
@@ -16,7 +15,7 @@ class TestWakeable : public fml::Wakeable {
public:
using WakeUpCall = std::function<void(const fml::TimePoint)>;
TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
explicit TestWakeable(WakeUpCall call) : wake_up_call_(call) {}
void WakeUp(fml::TimePoint time_point) override { wake_up_call_(time_point); }

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#define FML_USED_ON_EMBEDDER
@@ -16,7 +15,7 @@
#include "flutter/fml/task_runner.h"
#include "gtest/gtest.h"
#define TIME_SENSITIVE(x) TimeSensitiveTest_##x
#define TIMESENSITIVE(x) TimeSensitiveTest_##x
#if OS_WIN
#define PLATFORM_SPECIFIC_CAPTURE(...) [ __VA_ARGS__, count ]
#else
@@ -154,7 +153,7 @@ TEST(MessageLoop, CheckRunsTaskOnCurrentThread) {
thread.join();
}
TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) {
TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskByDelta)) {
bool checked = false;
std::thread thread([&checked]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
@@ -176,7 +175,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskByDelta)) {
ASSERT_TRUE(checked);
}
TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskForTime)) {
bool checked = false;
std::thread thread([&checked]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
@@ -198,7 +197,7 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
ASSERT_TRUE(checked);
}
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
const auto count = 10;
int checked = false;
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {
@@ -225,7 +224,7 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
ASSERT_EQ(checked, count);
}
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
const auto count = 10;
int checked = false;
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/paths.h"
@@ -35,12 +34,15 @@ std::string SanitizeURIEscapedCharacters(const std::string& str) {
result.reserve(str.size());
for (std::string::size_type i = 0; i < str.size(); ++i) {
if (str[i] == '%') {
if (i > str.size() - 3 || !isxdigit(str[i + 1]) || !isxdigit(str[i + 2]))
if (i > str.size() - 3 || !isxdigit(str[i + 1]) ||
!isxdigit(str[i + 2])) {
return "";
}
const std::string hex = str.substr(i + 1, 2);
const unsigned char c = strtoul(hex.c_str(), nullptr, 16);
if (!c)
if (!c) {
return "";
}
result += c;
i += 2;
} else {

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/platform/darwin/string_range_sanitization.h"

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/paths.h"
@@ -41,16 +40,19 @@ std::string AbsolutePath(const std::string& path) {
std::string GetDirectoryName(const std::string& path) {
size_t separator = path.rfind('/');
if (separator == 0u)
if (separator == 0u) {
return "/";
if (separator == std::string::npos)
}
if (separator == std::string::npos) {
return std::string();
}
return path.substr(0, separator);
}
std::string FromURI(const std::string& uri) {
if (uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix)
if (uri.substr(0, kFileURLPrefixLength) != kFileURLPrefix) {
return uri;
}
std::string file_path = uri.substr(kFileURLPrefixLength);
return SanitizeURIEscapedCharacters(file_path);

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#define FML_USED_ON_EMBEDDER
@@ -43,7 +42,8 @@ bool RasterThreadMerger::IsOnRasterizingThread() const {
void RasterThreadMerger::ExtendLeaseTo(size_t lease_term) {
FML_DCHECK(lease_term > 0) << "lease_term should be positive.";
if (lease_term_ != kLeaseNotSet && (int)lease_term > lease_term_) {
if (lease_term_ != kLeaseNotSet &&
static_cast<int>(lease_term) > lease_term_) {
lease_term_ = lease_term;
}
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/synchronization/waitable_event.h"
@@ -24,29 +23,33 @@ bool WaitWithTimeoutImpl(std::unique_lock<std::mutex>* locker,
TimeDelta timeout) {
FML_DCHECK(locker->owns_lock());
if (condition())
if (condition()) {
return false;
}
// We may get spurious wakeups.
TimeDelta wait_remaining = timeout;
TimePoint start = TimePoint::Now();
while (true) {
if (std::cv_status::timeout ==
cv->wait_for(*locker,
std::chrono::nanoseconds(wait_remaining.ToNanoseconds())))
cv->wait_for(*locker, std::chrono::nanoseconds(
wait_remaining.ToNanoseconds()))) {
return true; // Definitely timed out.
}
// We may have been awoken.
if (condition())
if (condition()) {
return false;
}
// Or the wakeup may have been spurious.
TimePoint now = TimePoint::Now();
FML_DCHECK(now >= start);
TimeDelta elapsed = now - start;
// It's possible that we may have timed out anyway.
if (elapsed >= timeout)
if (elapsed >= timeout) {
return true;
}
// Otherwise, recalculate the amount that we have left to wait.
wait_remaining = timeout - elapsed;
@@ -68,8 +71,9 @@ void AutoResetWaitableEvent::Reset() {
void AutoResetWaitableEvent::Wait() {
std::unique_lock<std::mutex> locker(mutex_);
while (!signaled_)
while (!signaled_) {
cv_.wait(locker);
}
signaled_ = false;
}
@@ -86,21 +90,24 @@ bool AutoResetWaitableEvent::WaitWithTimeout(TimeDelta timeout) {
TimePoint start = TimePoint::Now();
while (true) {
if (std::cv_status::timeout ==
cv_.wait_for(locker,
std::chrono::nanoseconds(wait_remaining.ToNanoseconds())))
cv_.wait_for(
locker, std::chrono::nanoseconds(wait_remaining.ToNanoseconds()))) {
return true; // Definitely timed out.
}
// We may have been awoken.
if (signaled_)
if (signaled_) {
break;
}
// Or the wakeup may have been spurious.
TimePoint now = TimePoint::Now();
FML_DCHECK(now >= start);
TimeDelta elapsed = now - start;
// It's possible that we may have timed out anyway.
if (elapsed >= timeout)
if (elapsed >= timeout) {
return true;
}
// Otherwise, recalculate the amount that we have left to wait.
wait_remaining = timeout - elapsed;
@@ -132,8 +139,9 @@ void ManualResetWaitableEvent::Reset() {
void ManualResetWaitableEvent::Wait() {
std::unique_lock<std::mutex> locker(mutex_);
if (signaled_)
if (signaled_) {
return;
}
auto last_signal_id = signal_id_;
do {

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include "flutter/fml/synchronization/waitable_event.h"
@@ -75,10 +74,11 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) {
std::vector<std::thread> threads;
for (size_t j = 0u; j < 4u; j++) {
threads.push_back(std::thread([&ev, &wake_count]() {
if (rand() % 2 == 0)
if (rand() % 2 == 0) {
ev.Wait();
else
} else {
EXPECT_FALSE(ev.WaitWithTimeout(kActionTimeout));
}
wake_count.fetch_add(1u);
// Note: We can't say anything about the signaled state of |ev| here,
// since the main thread may have already signaled it again.
@@ -98,8 +98,9 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) {
ev.Signal();
// Poll for |wake_count| to change.
while (wake_count.load() == old_wake_count)
while (wake_count.load() == old_wake_count) {
SleepFor(kEpsilonTimeout);
}
EXPECT_FALSE(ev.IsSignaledForTest());
@@ -117,8 +118,9 @@ TEST(AutoResetWaitableEventTest, MultipleWaiters) {
SleepFor(kEpsilonTimeout);
EXPECT_TRUE(ev.IsSignaledForTest());
for (auto& thread : threads)
for (auto& thread : threads) {
thread.join();
}
ev.Reset();
}
@@ -157,10 +159,11 @@ TEST(ManualResetWaitableEventTest, SignalMultiple) {
threads.push_back(std::thread([&ev]() {
EpsilonRandomSleep();
if (rand() % 2 == 0)
if (rand() % 2 == 0) {
ev.Wait();
else
} else {
EXPECT_FALSE(ev.WaitWithTimeout(kActionTimeout));
}
}));
}
@@ -170,8 +173,9 @@ TEST(ManualResetWaitableEventTest, SignalMultiple) {
// The threads will only terminate once they've successfully waited (or
// timed out).
for (auto& thread : threads)
for (auto& thread : threads) {
thread.join();
}
ev.Reset();
}

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include <atomic>
#include <thread>
@@ -14,7 +13,7 @@ namespace {
class Box {
public:
Box(int value, std::atomic_int* destroys = nullptr)
explicit Box(int value, std::atomic_int* destroys = nullptr)
: value_(value), destroys_(destroys) {}
~Box() {
if (destroys_) {

View File

@@ -1,7 +1,6 @@
// 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.
// FLUTTER_NOLINT
#include <hb-subset.h>
#include <cstdlib>
@@ -14,7 +13,7 @@
#include "hb_wrappers.h"
hb_codepoint_t ParseCodepoint(const std::string& arg) {
unsigned long value = 0;
uint64_t value = 0;
// Check for \u123, u123, otherwise let strtoul work it out.
if (arg[0] == 'u') {
value = strtoul(arg.c_str() + 1, nullptr, 16);