diff options
author | Max Kellermann <max@musicpd.org> | 2018-03-15 20:07:11 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-03-15 20:08:13 +0100 |
commit | b7dc3fae7c87282c4d83bc802137590be697e1a8 (patch) | |
tree | 04ee8bbfc85a2d7b5611783e0ecc14b0a6b9e449 /src/input/ThreadInputStream.hxx | |
parent | d84cd500bbb436fbf9614e3712d2d6b06422279f (diff) | |
parent | a2340c313f49d45abf3ade4645264e45c54918c7 (diff) |
Merge branch 'v0.20.x'
Diffstat (limited to 'src/input/ThreadInputStream.hxx')
-rw-r--r-- | src/input/ThreadInputStream.hxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/input/ThreadInputStream.hxx b/src/input/ThreadInputStream.hxx index c3ab0f653..4883dae24 100644 --- a/src/input/ThreadInputStream.hxx +++ b/src/input/ThreadInputStream.hxx @@ -29,6 +29,7 @@ #include <exception> +#include <assert.h> #include <stdint.h> /** @@ -39,6 +40,11 @@ * manages the thread and the buffer. * * This works only for "streams": unknown length, no seeking, no tags. + * + * The implementation must call Stop() before its destruction + * completes. This cannot be done in ~ThreadInputStream() because at + * this point, the class has been morphed back to #ThreadInputStream + * and the still-running thread will crash due to pure method call. */ class ThreadInputStream : public InputStream { const char *const plugin; @@ -73,7 +79,12 @@ public: const char *_uri, Mutex &_mutex, Cond &_cond, size_t _buffer_size) noexcept; - virtual ~ThreadInputStream() noexcept; +#ifndef NDEBUG + ~ThreadInputStream() override { + /* Stop() must have been called already */ + assert(!thread.IsDefined()); + } +#endif /** * Initialize the object and start the thread. @@ -87,6 +98,12 @@ public: size_t Read(void *ptr, size_t size) override final; protected: + /** + * Stop the thread and free the buffer. This must be called + * before destruction of this object completes. + */ + void Stop() noexcept; + void SetMimeType(const char *_mime) noexcept { assert(thread.IsInside()); |