Commit 97d45bc0 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use std::atomic for DeferredTaskHandler::audio_thread_ and all other atomics in webaudio.

These are the ones that didn't explicitly include wtf/atomics.h and so were missed earlier.

Bug: 736037,247328
Change-Id: I407d1ad6f53c058866bb4a98ca910768fe9ce6c5
Reviewed-on: https://chromium-review.googlesource.com/c/1370187Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615536}
parent a82bda82
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_BUFFER_SOURCE_NODE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_BUFFER_SOURCE_NODE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_BUFFER_SOURCE_NODE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_BUFFER_SOURCE_NODE_H_
#include <atomic>
#include <memory> #include <memory>
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h" #include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
...@@ -133,10 +134,12 @@ class AudioBufferSourceHandler final : public AudioScheduledSourceHandler { ...@@ -133,10 +134,12 @@ class AudioBufferSourceHandler final : public AudioScheduledSourceHandler {
scoped_refptr<AudioParamHandler> playback_rate_; scoped_refptr<AudioParamHandler> playback_rate_;
scoped_refptr<AudioParamHandler> detune_; scoped_refptr<AudioParamHandler> detune_;
bool DidSetLooping() const { return AcquireLoad(&did_set_looping_); } bool DidSetLooping() const {
return did_set_looping_.load(std::memory_order_acquire);
}
void SetDidSetLooping(bool loop) { void SetDidSetLooping(bool loop) {
bool new_looping = DidSetLooping() || loop; if (loop)
ReleaseStore(&did_set_looping_, new_looping); did_set_looping_.store(true, std::memory_order_release);
} }
// If m_isLooping is false, then this node will be done playing and become // If m_isLooping is false, then this node will be done playing and become
...@@ -146,7 +149,7 @@ class AudioBufferSourceHandler final : public AudioScheduledSourceHandler { ...@@ -146,7 +149,7 @@ class AudioBufferSourceHandler final : public AudioScheduledSourceHandler {
bool is_looping_; bool is_looping_;
// True if the source .loop attribute was ever set. // True if the source .loop attribute was ever set.
int did_set_looping_; std::atomic_bool did_set_looping_;
double loop_start_; double loop_start_;
double loop_end_; double loop_end_;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_SCHEDULED_SOURCE_NODE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_SCHEDULED_SOURCE_NODE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_SCHEDULED_SOURCE_NODE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_SCHEDULED_SOURCE_NODE_H_
#include <atomic>
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/modules/webaudio/audio_node.h" #include "third_party/blink/renderer/modules/webaudio/audio_node.h"
...@@ -67,11 +68,11 @@ class AudioScheduledSourceHandler : public AudioHandler { ...@@ -67,11 +68,11 @@ class AudioScheduledSourceHandler : public AudioHandler {
double LatencyTime() const override { return 0; } double LatencyTime() const override { return 0; }
PlaybackState GetPlaybackState() const { PlaybackState GetPlaybackState() const {
return static_cast<PlaybackState>(AcquireLoad(&playback_state_)); return playback_state_.load(std::memory_order_acquire);
} }
void SetPlaybackState(PlaybackState new_state) { void SetPlaybackState(PlaybackState new_state) {
ReleaseStore(&playback_state_, new_state); playback_state_.store(new_state, std::memory_order_release);
} }
bool IsPlayingOrScheduled() const { bool IsPlayingOrScheduled() const {
...@@ -137,7 +138,7 @@ class AudioScheduledSourceHandler : public AudioHandler { ...@@ -137,7 +138,7 @@ class AudioScheduledSourceHandler : public AudioHandler {
private: private:
// This is accessed by both the main thread and audio thread. Use the setter // This is accessed by both the main thread and audio thread. Use the setter
// and getter to protect the access to this. // and getter to protect the access to this.
int playback_state_; std::atomic<PlaybackState> playback_state_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
}; };
......
...@@ -350,8 +350,7 @@ void DeferredTaskHandler::ClearHandlersToBeDeleted() { ...@@ -350,8 +350,7 @@ void DeferredTaskHandler::ClearHandlersToBeDeleted() {
void DeferredTaskHandler::SetAudioThreadToCurrentThread() { void DeferredTaskHandler::SetAudioThreadToCurrentThread() {
DCHECK(!IsMainThread()); DCHECK(!IsMainThread());
ThreadIdentifier thread = CurrentThread(); audio_thread_.store(CurrentThread(), std::memory_order_relaxed);
ReleaseStore(&audio_thread_, thread);
} }
void DeferredTaskHandler::DisableOutputsForTailProcessing() { void DeferredTaskHandler::DisableOutputsForTailProcessing() {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_DEFERRED_TASK_HANDLER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_DEFERRED_TASK_HANDLER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_DEFERRED_TASK_HANDLER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_DEFERRED_TASK_HANDLER_H_
#include <atomic>
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
...@@ -134,15 +135,12 @@ class MODULES_EXPORT DeferredTaskHandler final ...@@ -134,15 +135,12 @@ class MODULES_EXPORT DeferredTaskHandler final
// Thread Safety and Graph Locking: // Thread Safety and Graph Locking:
// //
void SetAudioThreadToCurrentThread(); void SetAudioThreadToCurrentThread();
ThreadIdentifier AudioThread() const { return AcquireLoad(&audio_thread_); }
// TODO(hongchan): Use no-barrier load here. (crbug.com/247328)
//
// It is okay to use a relaxed (no-barrier) load here. Because the data // It is okay to use a relaxed (no-barrier) load here. Because the data
// referenced by m_audioThread is not actually being used, thus we do not // referenced by m_audioThread is not actually being used, thus we do not
// need a barrier between the load of m_audioThread and of that data. // need a barrier between the load of m_audioThread and of that data.
bool IsAudioThread() const { bool IsAudioThread() const {
return CurrentThread() == AcquireLoad(&audio_thread_); return CurrentThread() == audio_thread_.load(std::memory_order_relaxed);
} }
void lock(); void lock();
...@@ -245,7 +243,7 @@ class MODULES_EXPORT DeferredTaskHandler final ...@@ -245,7 +243,7 @@ class MODULES_EXPORT DeferredTaskHandler final
// Graph locking. // Graph locking.
RecursiveMutex context_graph_mutex_; RecursiveMutex context_graph_mutex_;
volatile ThreadIdentifier audio_thread_; std::atomic<ThreadIdentifier> audio_thread_;
}; };
} // namespace blink } // namespace blink
......
...@@ -48,7 +48,6 @@ const unsigned RealtimeAnalyser::kInputBufferSize = ...@@ -48,7 +48,6 @@ const unsigned RealtimeAnalyser::kInputBufferSize =
RealtimeAnalyser::RealtimeAnalyser() RealtimeAnalyser::RealtimeAnalyser()
: input_buffer_(kInputBufferSize), : input_buffer_(kInputBufferSize),
write_index_(0),
down_mix_bus_(AudioBus::Create(1, audio_utilities::kRenderQuantumFrames)), down_mix_bus_(AudioBus::Create(1, audio_utilities::kRenderQuantumFrames)),
fft_size_(kDefaultFFTSize), fft_size_(kDefaultFFTSize),
magnitude_buffer_(kDefaultFFTSize / 2), magnitude_buffer_(kDefaultFFTSize / 2),
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_REALTIME_ANALYSER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_REALTIME_ANALYSER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_REALTIME_ANALYSER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_REALTIME_ANALYSER_H_
#include <atomic>
#include <memory> #include <memory>
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/platform/audio/audio_array.h" #include "third_party/blink/renderer/platform/audio/audio_array.h"
...@@ -77,11 +78,13 @@ class RealtimeAnalyser final { ...@@ -77,11 +78,13 @@ class RealtimeAnalyser final {
private: private:
// The audio thread writes the input audio here. // The audio thread writes the input audio here.
AudioFloatArray input_buffer_; AudioFloatArray input_buffer_;
unsigned write_index_; std::atomic_uint write_index_{0};
unsigned GetWriteIndex() const { return AcquireLoad(&write_index_); } unsigned GetWriteIndex() const {
return write_index_.load(std::memory_order_acquire);
}
void SetWriteIndex(unsigned new_index) { void SetWriteIndex(unsigned new_index) {
ReleaseStore(&write_index_, new_index); write_index_.store(new_index, std::memory_order_release);
} }
// Input audio is downmixed to this bus before copying to m_inputBuffer. // Input audio is downmixed to this bus before copying to m_inputBuffer.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment