From 587bb4d04bfeed40ba744e8230dd5acdcad39bd6 Mon Sep 17 00:00:00 2001 From: Stefan Pöschel Date: Sun, 28 Jan 2018 14:49:02 +0100 Subject: C++11: use atomic bool instead of mutex --- src/odr-padenc.cpp | 15 +-------------- src/odr-padenc.h | 7 +++---- 2 files changed, 4 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp index 319a037..d7f6a86 100644 --- a/src/odr-padenc.cpp +++ b/src/odr-padenc.cpp @@ -279,12 +279,6 @@ int main(int argc, char *argv[]) { // --- PadEncoder ----------------------------------------------------------------- -void PadEncoder::DoExit() { - std::lock_guard lock(status_mutex); - - do_exit = true; -} - int PadEncoder::Main() { output_fd = open(options.output, O_WRONLY); if (output_fd == -1) { @@ -314,14 +308,7 @@ int PadEncoder::Main() { // invoke actual encoder int result = 0; - for (;;) { - { - std::lock_guard lock(status_mutex); - - if(do_exit) - break; - } - + while (!do_exit) { result = Encode(); // abort on error diff --git a/src/odr-padenc.h b/src/odr-padenc.h index fe5d375..022ae9c 100644 --- a/src/odr-padenc.h +++ b/src/odr-padenc.h @@ -29,7 +29,7 @@ #include "common.h" -#include +#include #include #include #include @@ -92,8 +92,7 @@ protected: int output_fd; steady_clock::time_point run_timeline; - std::mutex status_mutex; - bool do_exit; + std::atomic do_exit; PadEncoder(PadEncoderOptions options) : options(options), @@ -113,7 +112,7 @@ public: virtual ~PadEncoder() {} int Main(); - void DoExit(); + void DoExit() {do_exit = true;} }; -- cgit v1.2.3