diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-02-10 19:22:13 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-02-18 17:12:46 +0100 |
commit | 8e128726f0eac1982aa75a005554ee5b556b332e (patch) | |
tree | 827c2f478e8fb3196ef411f4941fa4e839642e31 /servers/audio/effects | |
parent | 8870f43d742e0c48ae543d999856f5989170b62d (diff) |
Modernize atomics
- Based on C++11's `atomic`
- Reworked `SafeRefCount` (based on the rewrite by @hpvb)
- Replaced free atomic functions by the new `SafeNumeric<T>`
- Replaced wrong cases of `volatile bool` by the new `SafeFlag`
- Platform-specific implementations no longer needed
Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
Diffstat (limited to 'servers/audio/effects')
-rw-r--r-- | servers/audio/effects/audio_effect_capture.cpp | 8 | ||||
-rw-r--r-- | servers/audio/effects/audio_effect_capture.h | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/servers/audio/effects/audio_effect_capture.cpp b/servers/audio/effects/audio_effect_capture.cpp index f37938eec8..37e4122e50 100644 --- a/servers/audio/effects/audio_effect_capture.cpp +++ b/servers/audio/effects/audio_effect_capture.cpp @@ -106,7 +106,7 @@ int AudioEffectCapture::get_frames_available() const { } int64_t AudioEffectCapture::get_discarded_frames() const { - return discarded_frames; + return discarded_frames.get(); } int AudioEffectCapture::get_buffer_length_frames() const { @@ -115,7 +115,7 @@ int AudioEffectCapture::get_buffer_length_frames() const { } int64_t AudioEffectCapture::get_pushed_frames() const { - return pushed_frames; + return pushed_frames.get(); } void AudioEffectCaptureInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { @@ -129,9 +129,9 @@ void AudioEffectCaptureInstance::process(const AudioFrame *p_src_frames, AudioFr // Add incoming audio frames to the IO ring buffer int32_t ret = buffer.write(p_src_frames, p_frame_count); ERR_FAIL_COND_MSG(ret != p_frame_count, "Failed to add data to effect capture ring buffer despite sufficient space."); - atomic_add(&base->pushed_frames, p_frame_count); + base->pushed_frames.add(p_frame_count); } else { - atomic_add(&base->discarded_frames, p_frame_count); + base->discarded_frames.add(p_frame_count); } } diff --git a/servers/audio/effects/audio_effect_capture.h b/servers/audio/effects/audio_effect_capture.h index b154be85de..81d4ed6b0f 100644 --- a/servers/audio/effects/audio_effect_capture.h +++ b/servers/audio/effects/audio_effect_capture.h @@ -55,8 +55,8 @@ class AudioEffectCapture : public AudioEffect { friend class AudioEffectCaptureInstance; RingBuffer<AudioFrame> buffer; - uint64_t discarded_frames = 0; - uint64_t pushed_frames = 0; + SafeNumeric<uint64_t> discarded_frames; + SafeNumeric<uint64_t> pushed_frames; float buffer_length_seconds = 0.1f; bool buffer_initialized = false; |