From db5e90c258f94e65df70830ab1c053debfa15cdb Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 14 Jan 2018 07:43:46 +0100 Subject: Avoid race condition on teardown of pipelined plugins --- src/ModPlugin.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/ModPlugin.h') diff --git a/src/ModPlugin.h b/src/ModPlugin.h index 5635fca..e9cfa21 100644 --- a/src/ModPlugin.h +++ b/src/ModPlugin.h @@ -95,13 +95,6 @@ public: class PipelinedModCodec : public ModCodec, public ModMetadata { public: - PipelinedModCodec(); - PipelinedModCodec(const PipelinedModCodec&) = delete; - PipelinedModCodec& operator=(const PipelinedModCodec&) = delete; - PipelinedModCodec(PipelinedModCodec&&) = delete; - PipelinedModCodec& operator=(PipelinedModCodec&&) = delete; - virtual ~PipelinedModCodec(); - virtual int process(Buffer* const dataIn, Buffer* dataOut) final; virtual const char* name() = 0; @@ -111,6 +104,11 @@ protected: // Once the instance implementing PipelinedModCodec has been constructed, // it must call start_pipeline_thread() void start_pipeline_thread(void); + // To avoid race conditions on teardown, plugins must call + // stop_pipeline_thread in their destructor. + void stop_pipeline_thread(void); + + // The real processing must be implemented in internal_process virtual int internal_process(Buffer* const dataIn, Buffer* dataOut) = 0; private: @@ -121,7 +119,7 @@ private: std::deque m_metadata_fifo; - std::atomic m_running; + std::atomic m_running = ATOMIC_VAR_INIT(false); std::thread m_thread; void process_thread(void); }; -- cgit v1.2.3