Skip to content

Commit

Permalink
OSS: Use std::atomic_flag instead of PauseFlag
Browse files Browse the repository at this point in the history
We couldn't do it before because the functions we need were introduced in C++20.
  • Loading branch information
davidebeatrici committed Mar 23, 2024
1 parent fa57039 commit 5b452a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 45 deletions.
1 change: 0 additions & 1 deletion src/backends/OSS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ target_sources(be_oss
"FileDescriptor.hpp"
"OSS.cpp"
"OSS.hpp"
"PauseFlag.hpp"
)

target_link_libraries(be_oss
Expand Down
19 changes: 13 additions & 6 deletions src/backends/OSS/OSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ ErrorCode Flux::start(FluxConfig &config, const FluxFeedback &feedback) {

ErrorCode Flux::stop() {
m_halt = true;
m_pause.set(false);
m_pause.clear();
m_pause.notify_all();

if (m_thread) {
m_thread->join();
Expand All @@ -380,7 +381,13 @@ ErrorCode Flux::stop() {
}

ErrorCode Flux::pause(const bool on) {
m_pause.set(on);
if (on) {
m_pause.test_and_set();
} else {
m_pause.clear();
}

m_pause.notify_all();

return CROSSAUDIO_EC_OK;
}
Expand Down Expand Up @@ -409,8 +416,8 @@ void Flux::processInput() {
FluxData fluxData = { buffer.data(), static_cast< uint32_t >(bytes / frameSize) };
m_feedback.process(m_feedback.userData, &fluxData);

if (m_pause) {
m_pause.wait(false);
if (m_pause.test()) {
m_pause.wait(true);
}
}

Expand All @@ -431,9 +438,9 @@ void Flux::processOutput() {
break;
}

if (m_pause) {
if (m_pause.test()) {
ioctl(m_fd.get(), SNDCTL_DSP_SILENCE, 0);
m_pause.wait(false);
m_pause.wait(true);
ioctl(m_fd.get(), SNDCTL_DSP_SKIP, 0);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/backends/OSS/OSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define CROSSAUDIO_SRC_BACKENDS_OSS_OSS_HPP

#include "FileDescriptor.hpp"
#include "PauseFlag.hpp"

#include "crossaudio/ErrorCode.h"
#include "crossaudio/Flux.h"
Expand Down Expand Up @@ -86,8 +85,8 @@ class Flux {

FileDescriptor m_fd;

PauseFlag m_pause;
std::atomic_bool m_halt;
std::atomic_flag m_pause;
std::unique_ptr< std::thread > m_thread;
};
} // namespace oss
Expand Down
36 changes: 0 additions & 36 deletions src/backends/OSS/PauseFlag.hpp

This file was deleted.

0 comments on commit 5b452a9

Please sign in to comment.