Avoid race between mbTerminate check and wait.

package2.dll!osl::Thread::join() Line 112	C++
 	package2.dll!XBufferedThreadedStream::~XBufferedThreadedStream() Line 68	C++
 	package2.dll!XBufferedThreadedStream::`scalar deleting destructor'(unsigned int)	C++
vs.
 	package2.dll!std::condition_variable::wait<bool <lambda>(void) >...
	package2.dll!XBufferedThreadedStream::produce() Line 95	C++
 	package2.dll!`anonymous namespace'::UnzippingThread::execute() Line 29	C++

Change-Id: Iace86efc5e7fe00a5176380a8a21b2dc5e98d8a5
Reviewed-on: https://gerrit.libreoffice.org/38737
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Michael Meeks
2017-06-13 13:41:15 +01:00
parent 90b083bd8e
commit c573a10a6a

View File

@@ -90,12 +90,11 @@ void XBufferedThreadedStream::produce()
aGuard.lock(); aGuard.lock();
maPendingBuffers.push( pProducedBuffer ); maPendingBuffers.push( pProducedBuffer );
maBufferConsumeResume.notify_one(); maBufferConsumeResume.notify_one();
maBufferProduceResume.wait( aGuard, [&]{return canProduce(); } );
if( mbTerminateThread ) if (!mbTerminateThread)
break; maBufferProduceResume.wait( aGuard, [&]{return canProduce(); } );
} while( hasBytes() ); } while( !mbTerminateThread && hasBytes() );
} }
/** /**
@@ -134,6 +133,7 @@ const Buffer& XBufferedThreadedStream::getNextBlock()
void XBufferedThreadedStream::setTerminateThread() void XBufferedThreadedStream::setTerminateThread()
{ {
std::unique_lock<std::mutex> aGuard( maBufferProtector );
mbTerminateThread = true; mbTerminateThread = true;
maBufferProduceResume.notify_one(); maBufferProduceResume.notify_one();
maBufferConsumeResume.notify_one(); maBufferConsumeResume.notify_one();