mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-14 01:26:42 +02:00
fixed deadlock
This commit is contained in:
parent
d0c88e2ce0
commit
280cd10231
2 changed files with 18 additions and 11 deletions
|
@ -54,8 +54,10 @@ const PcmStreamPtr StreamSession::pcmStream() const
|
||||||
|
|
||||||
void StreamSession::start()
|
void StreamSession::start()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> mlock(mutex_);
|
{
|
||||||
active_ = true;
|
std::lock_guard<std::mutex> mlock(mutex_);
|
||||||
|
active_ = true;
|
||||||
|
}
|
||||||
readerThread_.reset(new thread(&StreamSession::reader, this));
|
readerThread_.reset(new thread(&StreamSession::reader, this));
|
||||||
writerThread_.reset(new thread(&StreamSession::writer, this));
|
writerThread_.reset(new thread(&StreamSession::writer, this));
|
||||||
}
|
}
|
||||||
|
@ -63,11 +65,14 @@ void StreamSession::start()
|
||||||
|
|
||||||
void StreamSession::stop()
|
void StreamSession::stop()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> mlock(mutex_);
|
{
|
||||||
if (!active_)
|
std::lock_guard<std::mutex> mlock(mutex_);
|
||||||
return;
|
if (!active_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
active_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
active_ = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
@ -81,12 +86,12 @@ void StreamSession::stop()
|
||||||
if (readerThread_ && readerThread_->joinable())
|
if (readerThread_ && readerThread_->joinable())
|
||||||
{
|
{
|
||||||
logD << "joining readerThread\n";
|
logD << "joining readerThread\n";
|
||||||
messages_.abort_wait();
|
|
||||||
readerThread_->join();
|
readerThread_->join();
|
||||||
}
|
}
|
||||||
if (writerThread_ && writerThread_->joinable())
|
if (writerThread_ && writerThread_->joinable())
|
||||||
{
|
{
|
||||||
logD << "joining writerThread\n";
|
logD << "joining writerThread\n";
|
||||||
|
messages_.abort_wait();
|
||||||
writerThread_->join();
|
writerThread_->join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,9 +144,11 @@ bool StreamSession::send(const msg::BaseMessage* message) const
|
||||||
{
|
{
|
||||||
//TODO on exception: set active = false
|
//TODO on exception: set active = false
|
||||||
// logO << "send: " << message->type << ", size: " << message->getSize() << ", id: " << message->id << ", refers: " << message->refersTo << "\n";
|
// logO << "send: " << message->type << ", size: " << message->getSize() << ", id: " << message->id << ", refers: " << message->refersTo << "\n";
|
||||||
std::lock_guard<std::recursive_mutex> mlock(mutex_);
|
{
|
||||||
if (!socket_ || !active_)
|
std::lock_guard<std::mutex> mlock(mutex_);
|
||||||
return false;
|
if (!socket_ || !active_)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
asio::streambuf streambuf;
|
asio::streambuf streambuf;
|
||||||
std::ostream stream(&streambuf);
|
std::ostream stream(&streambuf);
|
||||||
tv t;
|
tv t;
|
||||||
|
|
|
@ -89,7 +89,7 @@ protected:
|
||||||
void reader();
|
void reader();
|
||||||
void writer();
|
void writer();
|
||||||
|
|
||||||
mutable std::recursive_mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
std::atomic<bool> active_;
|
std::atomic<bool> active_;
|
||||||
|
|
||||||
std::unique_ptr<std::thread> readerThread_;
|
std::unique_ptr<std::thread> readerThread_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue