summaryrefslogtreecommitdiff
path: root/sc/source/ui/docshell/datastream.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-12-27 22:40:14 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-12-30 12:33:27 -0500
commitbb19d62a27ae5a321c1b0c9c9f7250fc4d2a27e5 (patch)
treedf872bb1b20f98103222ceaef829896449210307 /sc/source/ui/docshell/datastream.cxx
parent2c795105213a28eb5188374a672eb128191df07d (diff)
Protect access to the terminate flag.
Change-Id: I9c47e8f114f3d4dcdd5e62b1fffd2b65e7bfb00e
Diffstat (limited to 'sc/source/ui/docshell/datastream.cxx')
-rw-r--r--sc/source/ui/docshell/datastream.cxx42
1 files changed, 28 insertions, 14 deletions
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index d71233b42376..6a8e61a7af24 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -108,20 +108,19 @@ void emptyLineQueue( std::queue<LinesList*>& rQueue )
class ReaderThread : public salhelper::Thread
{
SvStream *mpStream;
+ bool mbTerminate;
+ osl::Mutex maMtxTerminate;
public:
- bool mbTerminateReading;
osl::Condition maProduceResume;
osl::Condition maConsumeResume;
- osl::Mutex maLinesProtector;
+ osl::Mutex maMtxLines;
std::queue<LinesList* > maPendingLines;
std::queue<LinesList* > maUsedLines;
ReaderThread(SvStream *pData):
- Thread("ReaderThread")
- ,mpStream(pData)
- ,mbTerminateReading(false)
- {
- }
+ Thread("ReaderThread"),
+ mpStream(pData),
+ mbTerminate(false) {}
virtual ~ReaderThread()
{
@@ -130,19 +129,31 @@ public:
emptyLineQueue(maUsedLines);
}
+ bool isTerminateRequested()
+ {
+ osl::MutexGuard aGuard(maMtxTerminate);
+ return mbTerminate;
+ }
+
+ void requestTerminate()
+ {
+ osl::MutexGuard aGuard(maMtxTerminate);
+ mbTerminate = true;
+ }
+
void endThread()
{
- mbTerminateReading = true;
+ requestTerminate();
maProduceResume.set();
}
private:
virtual void execute() SAL_OVERRIDE
{
- while (!mbTerminateReading)
+ while (!isTerminateRequested())
{
LinesList* pLines = NULL;
- osl::ResettableMutexGuard aGuard(maLinesProtector);
+ osl::ResettableMutexGuard aGuard(maMtxLines);
if (!maUsedLines.empty())
{
@@ -160,7 +171,7 @@ private:
mpStream->ReadLine( pLines->at(i) );
aGuard.reset(); // lock
- while (!mbTerminateReading && maPendingLines.size() >= 8)
+ while (!isTerminateRequested() && maPendingLines.size() >= 8)
{
// pause reading for a bit
aGuard.clear(); // unlock
@@ -171,7 +182,7 @@ private:
maPendingLines.push(pLines);
maConsumeResume.set();
if (!mpStream->good())
- mbTerminateReading = true;
+ requestTerminate();
}
}
};
@@ -267,11 +278,13 @@ OString DataStream::ConsumeLine()
if (!mpLines || mnLinesCount >= mpLines->size())
{
mnLinesCount = 0;
- if (mxReaderThread->mbTerminateReading)
+ if (mxReaderThread->isTerminateRequested())
return OString();
- osl::ResettableMutexGuard aGuard(mxReaderThread->maLinesProtector);
+
+ osl::ResettableMutexGuard aGuard(mxReaderThread->maMtxLines);
if (mpLines)
mxReaderThread->maUsedLines.push(mpLines);
+
while (mxReaderThread->maPendingLines.empty())
{
aGuard.clear(); // unlock
@@ -279,6 +292,7 @@ OString DataStream::ConsumeLine()
mxReaderThread->maConsumeResume.reset();
aGuard.reset(); // lock
}
+
mpLines = mxReaderThread->maPendingLines.front();
mxReaderThread->maPendingLines.pop();
if (mxReaderThread->maPendingLines.size() <= 4)