From aaacbeee59dd6e3c8563d44a7de9c99c4b391e81 Mon Sep 17 00:00:00 2001 From: Brian Ting Date: Tue, 15 Oct 2024 20:57:38 -0700 Subject: [PATCH] Cleanup codebase by running pre-commit. (#4273) b/371604735 --- starboard/build/config/BUILD.gn | 4 +- .../common/experimental/concurrency_debug.cc | 42 ++++++++++--------- starboard/common/instance_counter.h | 22 +++++----- starboard/common/optional.h | 2 +- starboard/common/spin_lock.cc | 4 +- starboard/elf_loader/elf_loader.cc | 6 ++- starboard/elf_loader/evergreen_info.cc | 14 ++++--- starboard/loader_app/drain_file_test.cc | 4 +- .../media_set_audio_write_duration_test.cc | 7 ++-- starboard/shared/starboard/application.cc | 8 ++-- .../starboard/lazy_initialization_internal.h | 6 ++- .../shared/starboard/media/avc_util_test.cc | 4 +- starboard/shared/starboard/thread_checker.h | 3 +- 13 files changed, 70 insertions(+), 56 deletions(-) diff --git a/starboard/build/config/BUILD.gn b/starboard/build/config/BUILD.gn index a4cb0ebad8a07..da2e1f51e5d62 100644 --- a/starboard/build/config/BUILD.gn +++ b/starboard/build/config/BUILD.gn @@ -210,9 +210,7 @@ config("starboard") { defines += [ "SB_IS_EVERGREEN_COMPATIBLE_LIBUNWIND=1" ] } - defines += [ - "STARBOARD_CONFIGURATION_INCLUDE=\"$starboard_path/configuration_public.h\"", - ] + defines += [ "STARBOARD_CONFIGURATION_INCLUDE=\"$starboard_path/configuration_public.h\"" ] } } diff --git a/starboard/common/experimental/concurrency_debug.cc b/starboard/common/experimental/concurrency_debug.cc index 3e93fc2bb4e34..0047da1e9095f 100644 --- a/starboard/common/experimental/concurrency_debug.cc +++ b/starboard/common/experimental/concurrency_debug.cc @@ -57,8 +57,9 @@ ScopedMutexWaitTracker::~ScopedMutexWaitTracker() { if (kMinimumWaitToLog == 0 || acquired_) { return; } - if ((s_mutex_acquire_contention_counter.fetch_add(1, std::memory_order_relaxed) + 1) < - kNumberOfInitialContentionsToIgnore) { + if ((s_mutex_acquire_contention_counter.fetch_add(1, + std::memory_order_relaxed) + + 1) < kNumberOfInitialContentionsToIgnore) { return; } @@ -69,32 +70,33 @@ ScopedMutexWaitTracker::~ScopedMutexWaitTracker() { if (elapsed <= old_value) { break; } - if (s_mutex_max_contention_time.compare_exchange_weak(old_value, elapsed, - std::memory_order_release, std::memory_order_relaxed)) { old_value, elapsed) == old_value) { - break; + if (s_mutex_max_contention_time.compare_exchange_weak( + old_value, elapsed, std::memory_order_release, + std::memory_order_relaxed)) { old_value, elapsed) == old_value) { + break; + } } - } - if (elapsed < kMinimumWaitToLog) { - return; - } + if (elapsed < kMinimumWaitToLog) { + return; + } - SB_LOG(INFO) << "SbMutexAcquire() takes " << elapsed; + SB_LOG(INFO) << "SbMutexAcquire() takes " << elapsed; - if (kStackTraceDepth > 0) { - void* stack[kStackTraceDepth]; - int num_stack = SbSystemGetStack(stack, kStackTraceDepth); + if (kStackTraceDepth > 0) { + void* stack[kStackTraceDepth]; + int num_stack = SbSystemGetStack(stack, kStackTraceDepth); - for (int i = 2; i < std::min(num_stack, 5); ++i) { - char name[kMaxSymbolNameLength + 1]; - if (SbSystemSymbolize(stack[i], name, kMaxSymbolNameLength)) { - SB_LOG(INFO) << " - " << name; - } else { - SB_LOG(INFO) << " - 0x" << stack[i]; + for (int i = 2; i < std::min(num_stack, 5); ++i) { + char name[kMaxSymbolNameLength + 1]; + if (SbSystemSymbolize(stack[i], name, kMaxSymbolNameLength)) { + SB_LOG(INFO) << " - " << name; + } else { + SB_LOG(INFO) << " - 0x" << stack[i]; + } } } } -} } // namespace experimental } // namespace starboard diff --git a/starboard/common/instance_counter.h b/starboard/common/instance_counter.h index 5225dae1a8e27..8dfebc23afe92 100644 --- a/starboard/common/instance_counter.h +++ b/starboard/common/instance_counter.h @@ -27,25 +27,25 @@ #else // defined(COBALT_BUILD_TYPE_GOLD) -#define DECLARE_INSTANCE_COUNTER(class_name) \ - namespace { \ +#define DECLARE_INSTANCE_COUNTER(class_name) \ + namespace { \ std::atomic s_##class_name##_instance_count = 0; \ } -#define ON_INSTANCE_CREATED(class_name) \ - { \ - SB_LOG(INFO) << "New instance of " << #class_name \ - << " is created. We have " \ - << s_##class_name##_instance_count. \ - fetch_add(1, std::memory_order_relaxed) \ - << " instances in total."; \ +#define ON_INSTANCE_CREATED(class_name) \ + { \ + SB_LOG(INFO) << "New instance of " << #class_name \ + << " is created. We have " \ + << s_##class_name##_instance_count.fetch_add( \ + 1, std::memory_order_relaxed) \ + << " instances in total."; \ } #define ON_INSTANCE_RELEASED(class_name) \ { \ SB_LOG(INFO) << "Instance of " << #class_name << " is released. We have " \ - << s_##class_name##_instance_count. \ - fetch_sub(1, std::memory_order_relaxed) \ + << s_##class_name##_instance_count.fetch_sub( \ + 1, std::memory_order_relaxed) \ << " instances in total."; \ } #endif // defined(COBALT_BUILD_TYPE_GOLD) diff --git a/starboard/common/optional.h b/starboard/common/optional.h index af0522365cae1..aeb1cf8d4fc1f 100644 --- a/starboard/common/optional.h +++ b/starboard/common/optional.h @@ -198,7 +198,7 @@ class optional { // == and != are already overloaded for optional, this leaves null tests, // which we use for boolean testing. class PrivateSafeBoolIdiomFakeMemberType; - typedef PrivateSafeBoolIdiomFakeMemberType optional::*SafeBoolIdiomType; + typedef PrivateSafeBoolIdiomFakeMemberType optional::* SafeBoolIdiomType; public: operator const SafeBoolIdiomType() const { diff --git a/starboard/common/spin_lock.cc b/starboard/common/spin_lock.cc index 0d873aa254071..181366ba75a8c 100644 --- a/starboard/common/spin_lock.cc +++ b/starboard/common/spin_lock.cc @@ -20,8 +20,8 @@ namespace starboard { void SpinLockAcquire(std::atomic* atomic) { int expected{kSpinLockStateReleased}; - while (!atomic->compare_exchange_weak(expected, - kSpinLockStateAcquired, std::memory_order_acquire)) { + while (!atomic->compare_exchange_weak(expected, kSpinLockStateAcquired, + std::memory_order_acquire)) { expected = kSpinLockStateReleased; sched_yield(); } diff --git a/starboard/elf_loader/elf_loader.cc b/starboard/elf_loader/elf_loader.cc index f0b2bf5e9676d..48d258552b51f 100644 --- a/starboard/elf_loader/elf_loader.cc +++ b/starboard/elf_loader/elf_loader.cc @@ -35,7 +35,8 @@ std::atomic ElfLoader::g_instance{NULL}; ElfLoader::ElfLoader() { ElfLoader* old_instance{NULL}; - g_instance.compare_exchange_weak(old_instance, this, std::memory_order_acquire); + g_instance.compare_exchange_weak(old_instance, this, + std::memory_order_acquire); SB_DCHECK(!old_instance); impl_.reset(new ElfLoaderImpl()); @@ -43,7 +44,8 @@ ElfLoader::ElfLoader() { ElfLoader::~ElfLoader() { ElfLoader* old_instance{this}; - g_instance.compare_exchange_weak(old_instance, NULL, std::memory_order_acquire); + g_instance.compare_exchange_weak(old_instance, NULL, + std::memory_order_acquire); SB_DCHECK(!old_instance); SB_DCHECK(old_instance); SB_DCHECK(old_instance == this); diff --git a/starboard/elf_loader/evergreen_info.cc b/starboard/elf_loader/evergreen_info.cc index 071cbc9c5d359..ecdef4cbc8d68 100644 --- a/starboard/elf_loader/evergreen_info.cc +++ b/starboard/elf_loader/evergreen_info.cc @@ -14,8 +14,8 @@ #include "starboard/elf_loader/evergreen_info.h" -#include #include +#include static EvergreenInfo g_evergreen_info; static bool g_valid_info = false; @@ -26,7 +26,8 @@ bool SetEvergreenInfo(const EvergreenInfo* evergreen_info) { int32_t busy_state_flag = 1; int32_t ready_state_flag = 0; if (g_busy.compare_exchange_weak(ready_state_flag, busy_state_flag, - std::memory_order_release, std::memory_order_relaxed)) { + std::memory_order_release, + std::memory_order_relaxed)) { // Bailing out is OK as the process crashed // before we launched the application and in that // case the evergreen information is not needed. @@ -44,7 +45,8 @@ bool SetEvergreenInfo(const EvergreenInfo* evergreen_info) { // Clear the busy flag. g_busy.compare_exchange_weak(busy_state_flag, ready_state_flag, - std::memory_order_release, std::memory_order_relaxed); + std::memory_order_release, + std::memory_order_relaxed); return true; } @@ -59,7 +61,8 @@ bool GetEvergreenInfo(EvergreenInfo* evergreen_info) { // Set the busy flag or bail. if (g_busy.compare_exchange_weak(ready_state_flag, busy_state_flag, - std::memory_order_release, std::memory_order_relaxed)) { + std::memory_order_release, + std::memory_order_relaxed)) { return false; } @@ -73,6 +76,7 @@ bool GetEvergreenInfo(EvergreenInfo* evergreen_info) { // Clear the busy flag. g_busy.compare_exchange_weak(busy_state_flag, ready_state_flag, - std::memory_order_release, std::memory_order_relaxed); + std::memory_order_release, + std::memory_order_relaxed); return true; } diff --git a/starboard/loader_app/drain_file_test.cc b/starboard/loader_app/drain_file_test.cc index 5a8b9f5d34e58..887f73b707711 100644 --- a/starboard/loader_app/drain_file_test.cc +++ b/starboard/loader_app/drain_file_test.cc @@ -244,7 +244,9 @@ TEST_F(DrainFileTest, SunnyDayPrepareDirectory) { path.append(kSbFileSepString); path.append(kAppKeyOne); - { ScopedFile file(path.c_str(), O_CREAT | O_WRONLY); } + { + ScopedFile file(path.c_str(), O_CREAT | O_WRONLY); + } EXPECT_TRUE(FileExists(path.c_str())); diff --git a/starboard/nplb/media_set_audio_write_duration_test.cc b/starboard/nplb/media_set_audio_write_duration_test.cc index a59faf6950f60..eeceff9ced52a 100644 --- a/starboard/nplb/media_set_audio_write_duration_test.cc +++ b/starboard/nplb/media_set_audio_write_duration_test.cc @@ -14,8 +14,8 @@ #include "starboard/media.h" -#include #include +#include #include "starboard/common/optional.h" #include "starboard/common/spin_lock.h" @@ -152,9 +152,8 @@ class SbMediaSetAudioWriteDurationTest int index_ = 0; int64_t total_duration_ = kDuration; // Guard access to |pending_decoder_status_|. - mutable std::atomic_int pending_decoder_status_lock_ { - starboard::kSpinLockStateReleased - }; + mutable std::atomic_int pending_decoder_status_lock_{ + starboard::kSpinLockStateReleased}; optional pending_decoder_status_; private: diff --git a/starboard/shared/starboard/application.cc b/starboard/shared/starboard/application.cc index 77699032e22b8..414d497ccec0c 100644 --- a/starboard/shared/starboard/application.cc +++ b/starboard/shared/starboard/application.cc @@ -59,7 +59,7 @@ void DeleteStartData(void* data) { } // namespace // The next event ID to use for Schedule(). -volatile std::atomicg_next_event_id{0}; +volatile std::atomic g_next_event_id{0}; std::atomic Application::g_instance{NULL}; @@ -72,13 +72,15 @@ Application::Application(SbEventHandleCallback sb_event_handle_callback) SB_CHECK(sb_event_handle_callback_) << "sb_event_handle_callback_ has not been set."; Application* old_instance = NULL; - g_instance.compare_exchange_weak(old_instance, this, std::memory_order_acquire); + g_instance.compare_exchange_weak(old_instance, this, + std::memory_order_acquire); SB_DCHECK(!old_instance); } Application::~Application() { Application* old_instance = this; - g_instance.compare_exchange_weak(old_instance, NULL, std::memory_order_acquire); + g_instance.compare_exchange_weak(old_instance, NULL, + std::memory_order_acquire); SB_DCHECK(old_instance); SB_DCHECK(old_instance == this); free(start_link_); diff --git a/starboard/shared/starboard/lazy_initialization_internal.h b/starboard/shared/starboard/lazy_initialization_internal.h index c39f53051b78a..42cf62acaafee 100644 --- a/starboard/shared/starboard/lazy_initialization_internal.h +++ b/starboard/shared/starboard/lazy_initialization_internal.h @@ -42,7 +42,8 @@ static inline bool EnsureInitialized(InitializedState* state) { // simultaneously mark us as initializing and return to the caller. int original{INITIALIZED_STATE_UNINITIALIZED}; state->compare_exchange_weak(original, INITIALIZED_STATE_INITIALIZING, - std::memory_order_release, std::memory_order_relaxed); + std::memory_order_release, + std::memory_order_relaxed); if (original == INITIALIZED_STATE_UNINITIALIZED) { // If we were uninitialized, we are now marked as initializing and so // we relay this information to the caller, so that they may initialize. @@ -52,7 +53,8 @@ static inline bool EnsureInitialized(InitializedState* state) { // initialization is complete, then return. do { sched_yield(); - } while (state->load(std::memory_order_acquire) != INITIALIZED_STATE_INITIALIZED); + } while (state->load(std::memory_order_acquire) != + INITIALIZED_STATE_INITIALIZED); } else { SB_DCHECK(original == INITIALIZED_STATE_INITIALIZED) << "Unexpected original=" << original; diff --git a/starboard/shared/starboard/media/avc_util_test.cc b/starboard/shared/starboard/media/avc_util_test.cc index 35dd92647e990..d9bfda1acc66d 100644 --- a/starboard/shared/starboard/media/avc_util_test.cc +++ b/starboard/shared/starboard/media/avc_util_test.cc @@ -391,7 +391,9 @@ TEST(AvcParameterSetsTest, NaluHeaderWithoutType) { } TEST(AvcParameterSetsTest, InvalidNaluHeader) { - { VerifyAllEmpty(kNaluHeaderOnlyInAnnexB); } + { + VerifyAllEmpty(kNaluHeaderOnlyInAnnexB); + } { auto parameter_sets_in_annex_b = kSpsInAnnexB + kPpsInAnnexB; auto nalus_in_annex_b = parameter_sets_in_annex_b + kNaluHeaderOnlyInAnnexB; diff --git a/starboard/shared/starboard/thread_checker.h b/starboard/shared/starboard/thread_checker.h index 7455b5adfe380..bdae6330dec87 100644 --- a/starboard/shared/starboard/thread_checker.h +++ b/starboard/shared/starboard/thread_checker.h @@ -64,7 +64,8 @@ class ThreadChecker { SbThreadId current_thread_id = SbThreadGetId(); SbThreadId stored_thread_id = kSbThreadInvalidId; thread_id_.compare_exchange_weak(stored_thread_id, current_thread_id, - std::memory_order_relaxed, std::memory_order_relaxed); + std::memory_order_relaxed, + std::memory_order_relaxed); return stored_thread_id == kSbThreadInvalidId || stored_thread_id == current_thread_id; }