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

Allow worker threads to use their own FastParser instances.

To prevent deadlock during threaded sheet stream parsing.  It now
deadlocks at a different place.

Change-Id: I0ba0f2c9a257e71b0a340ab14e369b06d5fd8829
üst 8e5fd4a1
...@@ -56,8 +56,7 @@ namespace oox { ...@@ -56,8 +56,7 @@ namespace oox {
namespace core { namespace core {
class FragmentHandler; class FragmentHandler;
class FastParser;
// ============================================================================
struct TextField { struct TextField {
com::sun::star::uno::Reference< com::sun::star::text::XText > xText; com::sun::star::uno::Reference< com::sun::star::text::XText > xText;
...@@ -107,7 +106,8 @@ public: ...@@ -107,7 +106,8 @@ public:
@return True, if the fragment could be imported. @return True, if the fragment could be imported.
*/ */
bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ); bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler );
bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser );
/** Imports a fragment into an xml::dom::XDocument. /** Imports a fragment into an xml::dom::XDocument.
...@@ -231,6 +231,8 @@ public: ...@@ -231,6 +231,8 @@ public:
void importDocumentProperties(); void importDocumentProperties();
FastParser* createParser() const;
protected: protected:
virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const; implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const;
......
...@@ -143,6 +143,13 @@ struct NamespaceIds: public rtl::StaticWithInit< ...@@ -143,6 +143,13 @@ struct NamespaceIds: public rtl::StaticWithInit<
} }
}; };
void registerNamespaces( FastParser& rParser )
{
const Sequence< beans::Pair<OUString, sal_Int32> > ids = NamespaceIds::get();
for (sal_Int32 i = 0; i < ids.getLength(); ++i)
rParser.registerNamespace(ids[i].Second);
}
} // namespace } // namespace
struct XmlFilterBaseImpl struct XmlFilterBaseImpl
...@@ -164,10 +171,7 @@ XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxCo ...@@ -164,10 +171,7 @@ XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxCo
maVmlSuffix( ".vml" ) maVmlSuffix( ".vml" )
{ {
// register XML namespaces // register XML namespaces
const Sequence< beans::Pair< OUString, sal_Int32 > > ids= registerNamespaces(maFastParser);
NamespaceIds::get();
for( sal_Int32 i=0; i<ids.getLength(); ++i )
maFastParser.registerNamespace( ids[i].Second );
} }
XmlFilterBase::XmlFilterBase( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) : XmlFilterBase::XmlFilterBase( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
...@@ -203,13 +207,25 @@ void XmlFilterBase::importDocumentProperties() ...@@ -203,13 +207,25 @@ void XmlFilterBase::importDocumentProperties()
xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() ); xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() );
} }
FastParser* XmlFilterBase::createParser() const
{
FastParser* pParser = new FastParser(getComponentContext());
registerNamespaces(*pParser);
return pParser;
}
OUString XmlFilterBase::getFragmentPathFromFirstType( const OUString& rType ) OUString XmlFilterBase::getFragmentPathFromFirstType( const OUString& rType )
{ {
// importRelations() caches the relations map for subsequence calls // importRelations() caches the relations map for subsequence calls
return importRelations( OUString() )->getFragmentPathFromFirstType( rType ); return importRelations( OUString() )->getFragmentPathFromFirstType( rType );
} }
bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ) bool XmlFilterBase::importFragment( const rtl::Reference<FragmentHandler>& rxHandler )
{
return importFragment(rxHandler, mxImpl->maFastParser);
}
bool XmlFilterBase::importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser )
{ {
OSL_ENSURE( rxHandler.is(), "XmlFilterBase::importFragment - missing fragment handler" ); OSL_ENSURE( rxHandler.is(), "XmlFilterBase::importFragment - missing fragment handler" );
if( !rxHandler.is() ) if( !rxHandler.is() )
...@@ -263,8 +279,8 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r ...@@ -263,8 +279,8 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r
// own try/catch block for showing parser failure assertion with fragment path // own try/catch block for showing parser failure assertion with fragment path
if( xInStrm.is() ) try if( xInStrm.is() ) try
{ {
mxImpl->maFastParser.setDocumentHandler( xDocHandler ); rParser.setDocumentHandler(xDocHandler);
mxImpl->maFastParser.parseStream( xInStrm, aFragmentPath ); rParser.parseStream(xInStrm, aFragmentPath);
return true; return true;
} }
catch( Exception& ) catch( Exception& )
......
...@@ -53,6 +53,7 @@ namespace oox { namespace core { ...@@ -53,6 +53,7 @@ namespace oox { namespace core {
class FilterBase; class FilterBase;
class FragmentHandler; class FragmentHandler;
class XmlFilterBase; class XmlFilterBase;
class FastParser;
} } } }
class ScDocument; class ScDocument;
...@@ -269,7 +270,10 @@ public: ...@@ -269,7 +270,10 @@ public:
/** Imports a fragment using the passed fragment handler, which contains /** Imports a fragment using the passed fragment handler, which contains
the full path to the fragment stream. */ the full path to the fragment stream. */
bool importOoxFragment( const ::rtl::Reference< ::oox::core::FragmentHandler >& rxHandler ); bool importOoxFragment( const rtl::Reference<oox::core::FragmentHandler>& rxHandler );
bool importOoxFragment( const rtl::Reference<oox::core::FragmentHandler>& rxHandler, oox::core::FastParser& rParser );
// BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) ------- // BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) -------
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "globstr.hrc" #include "globstr.hrc"
#include "calcconfig.hxx" #include "calcconfig.hxx"
#include <oox/core/fastparser.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <officecfg/Office/Calc.hxx> #include <officecfg/Office/Calc.hxx>
#include <salhelper/thread.hxx> #include <salhelper/thread.hxx>
...@@ -240,13 +241,17 @@ class WorkerThread : public salhelper::Thread ...@@ -240,13 +241,17 @@ class WorkerThread : public salhelper::Thread
WorkbookFragment& mrWorkbookHandler; WorkbookFragment& mrWorkbookHandler;
size_t mnID; size_t mnID;
FragmentHandlerRef mxHandler; FragmentHandlerRef mxHandler;
boost::scoped_ptr<oox::core::FastParser> mxParser;
osl::Mutex maMtxAction; osl::Mutex maMtxAction;
osl::Condition maCondActionChanged; osl::Condition maCondActionChanged;
WorkerAction meAction; WorkerAction meAction;
public: public:
WorkerThread( WorkbookFragment& rWorkbookHandler, size_t nID ) : WorkerThread( WorkbookFragment& rWorkbookHandler, size_t nID ) :
salhelper::Thread("sheet-import-worker-thread"), salhelper::Thread("sheet-import-worker-thread"),
mrWorkbookHandler(rWorkbookHandler), mnID(nID), meAction(None) {} mrWorkbookHandler(rWorkbookHandler),
mnID(nID),
mxParser(rWorkbookHandler.getOoxFilter().createParser()),
meAction(None) {}
virtual void execute() virtual void execute()
{ {
...@@ -271,7 +276,7 @@ public: ...@@ -271,7 +276,7 @@ public:
#if 0 #if 0
// TODO : This still deadlocks in the fast parser code. // TODO : This still deadlocks in the fast parser code.
mrWorkbookHandler.importOoxFragment(mxHandler); mrWorkbookHandler.importOoxFragment(mxHandler, *mxParser);
#else #else
double val = rand() / static_cast<double>(RAND_MAX); double val = rand() / static_cast<double>(RAND_MAX);
val *= 1000000; // normalize to 1 second. val *= 1000000; // normalize to 1 second.
......
...@@ -961,11 +961,16 @@ XmlFilterBase& WorkbookHelper::getOoxFilter() const ...@@ -961,11 +961,16 @@ XmlFilterBase& WorkbookHelper::getOoxFilter() const
return mrBookGlob.getOoxFilter(); return mrBookGlob.getOoxFilter();
} }
bool WorkbookHelper::importOoxFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ) bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler )
{ {
return getOoxFilter().importFragment( rxHandler ); return getOoxFilter().importFragment( rxHandler );
} }
bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler, oox::core::FastParser& rParser )
{
return getOoxFilter().importFragment(rxHandler, rParser);
}
// BIFF specific -------------------------------------------------------------- // BIFF specific --------------------------------------------------------------
BiffType WorkbookHelper::getBiff() const BiffType WorkbookHelper::getBiff() const
......
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