Skip to content

Commit

Permalink
Cleanup codebase by running pre-commit. (#4273)
Browse files Browse the repository at this point in the history
b/371604735
  • Loading branch information
briantting authored Oct 16, 2024
1 parent c8b78be commit aaacbee
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 56 deletions.
4 changes: 1 addition & 3 deletions starboard/build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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\"" ]
}
}

Expand Down
42 changes: 22 additions & 20 deletions starboard/common/experimental/concurrency_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions starboard/common/instance_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t> 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)
Expand Down
2 changes: 1 addition & 1 deletion starboard/common/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions starboard/common/spin_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace starboard {

void SpinLockAcquire(std::atomic<int32_t>* 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();
}
Expand Down
6 changes: 4 additions & 2 deletions starboard/elf_loader/elf_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ std::atomic<ElfLoader*> 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());
}

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);
Expand Down
14 changes: 9 additions & 5 deletions starboard/elf_loader/evergreen_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "starboard/elf_loader/evergreen_info.h"

#include <atomic>
#include <string.h>
#include <atomic>

static EvergreenInfo g_evergreen_info;
static bool g_valid_info = false;
Expand All @@ -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.
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
4 changes: 3 additions & 1 deletion starboard/loader_app/drain_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
7 changes: 3 additions & 4 deletions starboard/nplb/media_set_audio_write_duration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "starboard/media.h"

#include <atomic>
#include <unistd.h>
#include <atomic>

#include "starboard/common/optional.h"
#include "starboard/common/spin_lock.h"
Expand Down Expand Up @@ -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<PendingDecoderStatus> pending_decoder_status_;

private:
Expand Down
8 changes: 5 additions & 3 deletions starboard/shared/starboard/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void DeleteStartData(void* data) {
} // namespace

// The next event ID to use for Schedule().
volatile std::atomic<int32_t>g_next_event_id{0};
volatile std::atomic<int32_t> g_next_event_id{0};

std::atomic<Application*> Application::g_instance{NULL};

Expand All @@ -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_);
Expand Down
6 changes: 4 additions & 2 deletions starboard/shared/starboard/lazy_initialization_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion starboard/shared/starboard/media/avc_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion starboard/shared/starboard/thread_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit aaacbee

Please sign in to comment.