Kaydet (Commit) 226f4f03 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Remove CallerThread and use Timer to do the same, on the main thread.

This makes the UI more responsive in general.

Change-Id: I5f8a4fab84a73812af868262cc7daa9d92cb3777
üst 2d283f2e
...@@ -111,37 +111,6 @@ public: ...@@ -111,37 +111,6 @@ public:
namespace datastreams { namespace datastreams {
class CallerThread : public salhelper::Thread
{
DataStream *mpDataStream;
public:
osl::Condition maStart;
bool mbTerminate;
CallerThread(DataStream *pData):
Thread("CallerThread")
,mpDataStream(pData)
,mbTerminate(false)
{}
private:
virtual void execute()
{
while (!mbTerminate)
{
// wait for a small amount of time, so that
// painting methods have a chance to be called.
// And also to make UI more responsive.
TimeValue const aTime = {0, 1000};
maStart.wait();
maStart.reset();
if (!mbTerminate)
while (mpDataStream->ImportData())
wait(aTime);
};
}
};
void emptyLineQueue( std::queue<DataStream::LinesType*>& rQueue ) void emptyLineQueue( std::queue<DataStream::LinesType*>& rQueue )
{ {
while (!rQueue.empty()) while (!rQueue.empty())
...@@ -371,8 +340,8 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const ScRange& ...@@ -371,8 +340,8 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const ScRange&
mfLastRefreshTime(0.0), mfLastRefreshTime(0.0),
mnCurRow(0) mnCurRow(0)
{ {
mxThread = new datastreams::CallerThread( this ); maImportTimer.SetTimeout(0);
mxThread->launch(); maImportTimer.SetTimeoutHdl( LINK(this, DataStream, ImportTimerHdl) );
Decode(rURL, rRange, nLimit, eMove, nSettings); Decode(rURL, rRange, nLimit, eMove, nSettings);
} }
...@@ -381,9 +350,7 @@ DataStream::~DataStream() ...@@ -381,9 +350,7 @@ DataStream::~DataStream()
{ {
if (mbRunning) if (mbRunning)
StopImport(); StopImport();
mxThread->mbTerminate = true;
mxThread->maStart.set();
mxThread->join();
if (mxReaderThread.is()) if (mxReaderThread.is())
{ {
mxReaderThread->endThread(); mxReaderThread->endThread();
...@@ -487,7 +454,8 @@ void DataStream::StartImport() ...@@ -487,7 +454,8 @@ void DataStream::StartImport()
} }
mbRunning = true; mbRunning = true;
maDocAccess.reset(); maDocAccess.reset();
mxThread->maStart.set();
maImportTimer.Start();
} }
void DataStream::StopImport() void DataStream::StopImport()
...@@ -497,6 +465,7 @@ void DataStream::StopImport() ...@@ -497,6 +465,7 @@ void DataStream::StopImport()
mbRunning = false; mbRunning = false;
Refresh(); Refresh();
maImportTimer.Stop();
} }
void DataStream::SetRefreshOnEmptyLine( bool bVal ) void DataStream::SetRefreshOnEmptyLine( bool bVal )
...@@ -618,7 +587,6 @@ void DataStream::Text2Doc() {} ...@@ -618,7 +587,6 @@ void DataStream::Text2Doc() {}
bool DataStream::ImportData() bool DataStream::ImportData()
{ {
SolarMutexGuard aGuard;
if (!mbValuesInLine) if (!mbValuesInLine)
// We no longer support this mode. To be deleted later. // We no longer support this mode. To be deleted later.
return false; return false;
...@@ -630,6 +598,14 @@ bool DataStream::ImportData() ...@@ -630,6 +598,14 @@ bool DataStream::ImportData()
return mbRunning; return mbRunning;
} }
IMPL_LINK_NOARG(DataStream, ImportTimerHdl)
{
if (ImportData())
maImportTimer.Start();
return 0;
}
} // namespace sc } // namespace sc
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <vcl/timer.hxx>
#include <address.hxx> #include <address.hxx>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
...@@ -102,6 +103,8 @@ private: ...@@ -102,6 +103,8 @@ private:
void Text2Doc(); void Text2Doc();
void Refresh(); void Refresh();
DECL_LINK( ImportTimerHdl, void* );
private: private:
ScDocShell* mpDocShell; ScDocShell* mpDocShell;
ScDocument* mpDoc; ScDocument* mpDoc;
...@@ -121,7 +124,9 @@ private: ...@@ -121,7 +124,9 @@ private:
SCROW mnCurRow; SCROW mnCurRow;
ScRange maStartRange; ScRange maStartRange;
ScRange maEndRange; ScRange maEndRange;
rtl::Reference<datastreams::CallerThread> mxThread;
Timer maImportTimer;
rtl::Reference<datastreams::ReaderThread> mxReaderThread; rtl::Reference<datastreams::ReaderThread> mxReaderThread;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment