Skip to content

Commit

Permalink
Code clean up to remove starboard/common/atomic usage (#3944)
Browse files Browse the repository at this point in the history
Code clean up to remove starboard/common/atomic usage

Test-On-Device: true

b/353387554
  • Loading branch information
iuriionishchenko authored and kaidokert committed Aug 15, 2024
1 parent 4cd9ffc commit ce763ba
Show file tree
Hide file tree
Showing 37 changed files with 97 additions and 105 deletions.
1 change: 0 additions & 1 deletion chrome/updater/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "cobalt/network/network_module.h"
#include "components/update_client/configurator.h"
#include "components/update_client/persisted_data.h"
#include "starboard/common/atomic.h"

class GURL;
class PrefService;
Expand Down
5 changes: 2 additions & 3 deletions starboard/android/shared/android_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/android/shared/jni_utils.h"
#include "starboard/android/shared/log_internal.h"
#include "starboard/common/atomic.h"
#include "starboard/common/file.h"
#include "starboard/common/semaphore.h"
#include "starboard/common/string.h"
Expand All @@ -40,7 +39,7 @@ namespace starboard {
namespace android {
namespace shared {

atomic_bool g_block_swapbuffers;
std::atomic_bool g_block_swapbuffers{false};

namespace {

Expand All @@ -54,7 +53,7 @@ Semaphore* g_app_created_semaphore = nullptr;
// Safeguard to avoid sending AndroidCommands either when there is no instance
// of the Starboard application, or after the run loop has exited and the
// ALooper receiving the commands is no longer being polled.
atomic_bool g_app_running;
std::atomic_bool g_app_running{false};

std::vector<std::string> GetArgs() {
std::vector<std::string> args;
Expand Down
6 changes: 3 additions & 3 deletions starboard/android/shared/application_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <android/looper.h>
#include <android/native_window.h>
#include <atomic>
#include <memory>
#include <string>
#include <unordered_map>
Expand All @@ -26,7 +27,6 @@
#include "starboard/android/shared/input_events_generator.h"
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/atomic.h"
#include "starboard/common/atomic.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"
#include "starboard/configuration.h"
Expand Down Expand Up @@ -129,7 +129,7 @@ class ApplicationAndroid

// In certain situations, the Starboard thread should not try to process new
// system events (e.g. while one is being processed).
atomic_bool handle_system_events_;
std::atomic_bool handle_system_events_{false};

// Synchronization for commands that change availability of Android resources
// such as the input and/or native_window_.
Expand All @@ -141,7 +141,7 @@ class ApplicationAndroid
SbAtomic32 android_stop_count_ = 0;

// Set to true in the destructor to ensure other threads stop waiting.
atomic_bool application_destroying_;
std::atomic_bool application_destroying_{false};

// The last Activity lifecycle state command received.
AndroidCommand::CommandType activity_state_;
Expand Down
6 changes: 3 additions & 3 deletions starboard/android/shared/audio_renderer_passthrough.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class AudioRendererPassthrough
EndedCB ended_cb_;

int frames_per_input_buffer_ = 0; // Set once before all uses.
atomic_bool can_accept_more_data_{true};
atomic_bool prerolled_;
atomic_bool end_of_stream_played_;
std::atomic_bool can_accept_more_data_{true};
std::atomic_bool prerolled_{false};
std::atomic_bool end_of_stream_played_{false};

bool end_of_stream_written_ = false; // Only accessed on PlayerWorker thread.

Expand Down
1 change: 0 additions & 1 deletion starboard/android/shared/drm_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/android/shared/jni_utils.h"
#include "starboard/android/shared/media_common.h"
#include "starboard/common/atomic.h"
#include "starboard/common/instance_counter.h"
#include "starboard/common/thread.h"

Expand Down
4 changes: 2 additions & 2 deletions starboard/android/shared/drm_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include <jni.h>
#include <memory>

#include <atomic>
#include <string>
#include <unordered_map>
#include <vector>

#include "starboard/android/shared/jni_utils.h"
#include "starboard/android/shared/media_common.h"
#include "starboard/common/atomic.h"
#include "starboard/common/log.h"
#include "starboard/common/mutex.h"
#include "starboard/common/thread.h"
Expand Down Expand Up @@ -128,7 +128,7 @@ class DrmSystem : public ::SbDrmSystemPrivate, private Thread {
Mutex mutex_;
std::unordered_map<std::string, std::vector<SbDrmKeyId>> cached_drm_key_ids_;
bool hdcp_lost_;
atomic_bool created_media_crypto_session_;
std::atomic_bool created_media_crypto_session_{false};

std::vector<uint8_t> metrics_;
};
Expand Down
5 changes: 3 additions & 2 deletions starboard/android/shared/egl_swap_buffers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
#include <EGL/egl.h>
#include <GLES2/gl2.h>

#include <atomic>

#include "starboard/android/shared/video_window.h"
#include "starboard/common/atomic.h"
#include "starboard/shared/gles/gl_call.h"

namespace starboard {
namespace android {
namespace shared {
extern atomic_bool g_block_swapbuffers;
extern std::atomic_bool g_block_swapbuffers;
} // namespace shared
} // namespace android
} // namespace starboard
Expand Down
4 changes: 2 additions & 2 deletions starboard/android/shared/media_codec_bridge_eradicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#define STARBOARD_ANDROID_SHARED_MEDIA_CODEC_BRIDGE_ERADICATOR_H_

#include <jni.h>
#include <atomic>
#include <set>

#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/common/atomic.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"

Expand Down Expand Up @@ -52,7 +52,7 @@ class MediaCodecBridgeEradicator {
private:
static void* DestroyMediaCodecBridge(void* context);

atomic_bool is_enabled_{false};
std::atomic_bool is_enabled_{false};
// Maximum wait time when creating a new MediaCodecBridge if the background
// cleanup thread (MediaCodecBridgeEradicator::DestroyMediaCodecBridge) is
// unresponsive.
Expand Down
8 changes: 4 additions & 4 deletions starboard/android/shared/media_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ MediaDecoder::MediaDecoder(Host* host,
if (audio_stream_info.codec != kSbMediaAudioCodecOpus &&
!audio_stream_info.audio_specific_config.empty()) {
pending_tasks_.push_back(Event(audio_stream_info.audio_specific_config));
number_of_pending_tasks_.increment();
++number_of_pending_tasks_;
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ void MediaDecoder::WriteInputBuffers(const InputBuffers& input_buffers) {
bool need_signal = pending_tasks_.empty();
for (const auto& input_buffer : input_buffers) {
pending_tasks_.push_back(Event(input_buffer));
number_of_pending_tasks_.increment();
++number_of_pending_tasks_;
}
if (need_signal) {
condition_variable_.Signal();
Expand All @@ -220,7 +220,7 @@ void MediaDecoder::WriteEndOfStream() {
stream_ended_.store(true);
ScopedLock scoped_lock(mutex_);
pending_tasks_.push_back(Event(Event::kWriteEndOfStream));
number_of_pending_tasks_.increment();
++number_of_pending_tasks_;
if (pending_tasks_.size() == 1) {
condition_variable_.Signal();
}
Expand Down Expand Up @@ -431,7 +431,7 @@ bool MediaDecoder::ProcessOneInputBuffer(
input_buffer_indices->erase(input_buffer_indices->begin());
event = pending_tasks->front();
pending_tasks->pop_front();
number_of_pending_tasks_.decrement();
--number_of_pending_tasks_;
}

SB_DCHECK(event.type == Event::kWriteCodecConfig ||
Expand Down
8 changes: 4 additions & 4 deletions starboard/android/shared/media_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

#include <jni.h>

#include <atomic>
#include <deque>
#include <memory>
#include <string>
#include <vector>

#include "starboard/android/shared/drm_system.h"
#include "starboard/android/shared/media_codec_bridge.h"
#include "starboard/common/atomic.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"
#include "starboard/common/optional.h"
Expand Down Expand Up @@ -188,13 +188,13 @@ class MediaDecoder final
SbPlayerError error_;
std::string error_message_;

atomic_bool stream_ended_;
std::atomic_bool stream_ended_{false};

atomic_bool destroying_;
std::atomic_bool destroying_{false};

optional<QueueInputBufferTask> pending_queue_input_buffer_task_;

atomic_int32_t number_of_pending_tasks_;
std::atomic<int32_t> number_of_pending_tasks_{0};

Mutex mutex_;
ConditionVariable condition_variable_;
Expand Down
3 changes: 2 additions & 1 deletion starboard/android/shared/player_components_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef STARBOARD_ANDROID_SHARED_PLAYER_COMPONENTS_FACTORY_H_
#define STARBOARD_ANDROID_SHARED_PLAYER_COMPONENTS_FACTORY_H_

#include <atomic>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -150,7 +151,7 @@ class AudioRendererSinkCallbackStub
error_occurred_.store(true);
}

atomic_bool error_occurred_;
std::atomic_bool error_occurred_{false};
};

class PlayerComponentsPassthrough
Expand Down
8 changes: 4 additions & 4 deletions starboard/android/shared/video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class VideoDecoder
std::unique_ptr<VideoFrameTracker> video_frame_tracker_;

// Preroll in tunnel mode is handled in this class instead of in the renderer.
atomic_bool tunnel_mode_prerolling_{true};
atomic_bool tunnel_mode_frame_rendered_;
std::atomic_bool tunnel_mode_prerolling_{true};
std::atomic_bool tunnel_mode_frame_rendered_{false};

// If decode-to-texture is enabled, then we store the decode target texture
// inside of this |decode_target_| member.
Expand All @@ -193,14 +193,14 @@ class VideoDecoder

std::unique_ptr<MediaDecoder> media_decoder_;

atomic_int32_t number_of_frames_being_decoded_;
std::atomic<int32_t> number_of_frames_being_decoded_{0};
scoped_refptr<Sink> sink_;

int input_buffer_written_ = 0;
bool first_texture_received_ = false;
bool end_of_stream_written_ = false;
volatile int64_t first_buffer_timestamp_; // microseconds
atomic_bool has_new_texture_available_;
std::atomic_bool has_new_texture_available_{false};

// Use |owns_video_surface_| only on decoder thread, to avoid unnecessary
// invocation of ReleaseVideoSurface(), though ReleaseVideoSurface() would
Expand Down
8 changes: 4 additions & 4 deletions starboard/common/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

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

#include "starboard/common/atomic.h"
#include "starboard/common/log.h"
#include "starboard/common/mutex.h"
#include "starboard/common/optional.h"
Expand All @@ -30,8 +30,8 @@ namespace starboard {
struct Thread::Data {
std::string name_;
pthread_t thread_ = 0;
atomic_bool started_;
atomic_bool join_called_;
std::atomic_bool started_{false};
std::atomic_bool join_called_{false};
Semaphore join_sema_;
};

Expand Down Expand Up @@ -74,7 +74,7 @@ starboard::Semaphore* Thread::join_sema() {
return &d_->join_sema_;
}

starboard::atomic_bool* Thread::joined_bool() {
std::atomic_bool* Thread::joined_bool() {
return &d_->join_called_;
}

Expand Down
4 changes: 2 additions & 2 deletions starboard/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef STARBOARD_COMMON_THREAD_H_
#define STARBOARD_COMMON_THREAD_H_

#include <atomic>
#include <functional>
#include <memory>
#include <string>
Expand All @@ -28,7 +29,6 @@
namespace starboard {

class Semaphore;
class atomic_bool;

class Thread {
public:
Expand Down Expand Up @@ -64,7 +64,7 @@ class Thread {
// Join() was called then return |true|, else |false|.
bool WaitForJoin(int64_t timeout);
Semaphore* join_sema();
atomic_bool* joined_bool();
std::atomic_bool* joined_bool();

struct Data;
std::unique_ptr<Data> d_;
Expand Down
4 changes: 2 additions & 2 deletions starboard/nplb/player_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#include "starboard/nplb/player_test_util.h"

#include <atomic>
#include <functional>

#include "starboard/audio_sink.h"
#include "starboard/common/atomic.h"
#include "starboard/common/string.h"
#include "starboard/extension/enhanced_audio.h"
#include "starboard/nplb/drm_helpers.h"
Expand Down Expand Up @@ -79,7 +79,7 @@ void ErrorFunc(SbPlayer player,
void* context,
SbPlayerError error,
const char* message) {
atomic_bool* error_occurred = static_cast<atomic_bool*>(context);
std::atomic_bool* error_occurred = static_cast<std::atomic_bool*>(context);
error_occurred->exchange(true);
}

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

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

#include "starboard/common/atomic.h"
#include "starboard/common/log.h"
#include "starboard/common/time.h"

Expand All @@ -41,7 +41,7 @@ class CountingThread : public posix::AbstractTestThread {

void Run() override {
while (!stop_.load()) {
counter_.increment();
++counter_;
usleep(1000);
}
}
Expand All @@ -65,8 +65,8 @@ class CountingThread : public posix::AbstractTestThread {
}

private:
atomic_bool stop_;
atomic_int32_t counter_;
std::atomic_bool stop_{false};
std::atomic_int counter_{0};
};

TEST(ThreadSamplerTest, RainyDayCreateSamplerInvalidThread) {
Expand Down
6 changes: 3 additions & 3 deletions starboard/nplb/thread_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include <unistd.h>

#include <atomic>
#include <functional>

#include "starboard/common/atomic.h"
#include "starboard/common/semaphore.h"
#include "starboard/common/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -27,14 +27,14 @@ namespace {

class TestRunThread : public Thread {
public:
TestRunThread() : Thread("TestThread"), finished_(false) {}
TestRunThread() : Thread("TestThread") {}

void Run() override {
while (!WaitForJoin(1000)) {
}
finished_.store(true);
}
atomic_bool finished_;
std::atomic_bool finished_{false};
};

// Tests the expectation that a thread subclass will have the expected
Expand Down
Loading

0 comments on commit ce763ba

Please sign in to comment.