diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-11-22 20:57:40 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-11-25 10:55:10 -0500 |
commit | e00562d9835bd82d74ef0301ea7425ff769915df (patch) | |
tree | 60a1b5331b09171a852c318afbcc7f4d7b8870d7 | |
parent | 8e5fd4a15ae2c7d55842b1b768b7807a2d3a298e (diff) |
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
-rw-r--r-- | include/oox/core/xmlfilterbase.hxx | 8 | ||||
-rw-r--r-- | oox/source/core/xmlfilterbase.cxx | 30 | ||||
-rw-r--r-- | sc/source/filter/inc/workbookhelper.hxx | 6 | ||||
-rw-r--r-- | sc/source/filter/oox/workbookfragment.cxx | 9 | ||||
-rw-r--r-- | sc/source/filter/oox/workbookhelper.cxx | 7 |
5 files changed, 46 insertions, 14 deletions
diff --git a/include/oox/core/xmlfilterbase.hxx b/include/oox/core/xmlfilterbase.hxx index 87234fb22328..76eb091b3f2e 100644 --- a/include/oox/core/xmlfilterbase.hxx +++ b/include/oox/core/xmlfilterbase.hxx @@ -56,8 +56,7 @@ namespace oox { namespace core { class FragmentHandler; - -// ============================================================================ +class FastParser; struct TextField { com::sun::star::uno::Reference< com::sun::star::text::XText > xText; @@ -107,7 +106,8 @@ public: @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. @@ -231,6 +231,8 @@ public: void importDocumentProperties(); + FastParser* createParser() const; + protected: virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const; diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index dddc29c7e5a8..30f384898ce9 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -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 struct XmlFilterBaseImpl @@ -164,10 +171,7 @@ XmlFilterBaseImpl::XmlFilterBaseImpl( const Reference< XComponentContext >& rxCo maVmlSuffix( ".vml" ) { // register XML namespaces - const Sequence< beans::Pair< OUString, sal_Int32 > > ids= - NamespaceIds::get(); - for( sal_Int32 i=0; i<ids.getLength(); ++i ) - maFastParser.registerNamespace( ids[i].Second ); + registerNamespaces(maFastParser); } XmlFilterBase::XmlFilterBase( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) : @@ -203,13 +207,25 @@ void XmlFilterBase::importDocumentProperties() xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() ); } +FastParser* XmlFilterBase::createParser() const +{ + FastParser* pParser = new FastParser(getComponentContext()); + registerNamespaces(*pParser); + return pParser; +} + OUString XmlFilterBase::getFragmentPathFromFirstType( const OUString& rType ) { // importRelations() caches the relations map for subsequence calls 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" ); if( !rxHandler.is() ) @@ -263,8 +279,8 @@ bool XmlFilterBase::importFragment( const ::rtl::Reference< FragmentHandler >& r // own try/catch block for showing parser failure assertion with fragment path if( xInStrm.is() ) try { - mxImpl->maFastParser.setDocumentHandler( xDocHandler ); - mxImpl->maFastParser.parseStream( xInStrm, aFragmentPath ); + rParser.setDocumentHandler(xDocHandler); + rParser.parseStream(xInStrm, aFragmentPath); return true; } catch( Exception& ) diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx index abafb20b7421..1f472c3860f6 100644 --- a/sc/source/filter/inc/workbookhelper.hxx +++ b/sc/source/filter/inc/workbookhelper.hxx @@ -53,6 +53,7 @@ namespace oox { namespace core { class FilterBase; class FragmentHandler; class XmlFilterBase; + class FastParser; } } class ScDocument; @@ -269,7 +270,10 @@ public: /** Imports a fragment using the passed fragment handler, which contains 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) ------- diff --git a/sc/source/filter/oox/workbookfragment.cxx b/sc/source/filter/oox/workbookfragment.cxx index e9471cbdd624..81eb2ed62ffd 100644 --- a/sc/source/filter/oox/workbookfragment.cxx +++ b/sc/source/filter/oox/workbookfragment.cxx @@ -49,6 +49,7 @@ #include "globstr.hrc" #include "calcconfig.hxx" +#include <oox/core/fastparser.hxx> #include <comphelper/processfactory.hxx> #include <officecfg/Office/Calc.hxx> #include <salhelper/thread.hxx> @@ -240,13 +241,17 @@ class WorkerThread : public salhelper::Thread WorkbookFragment& mrWorkbookHandler; size_t mnID; FragmentHandlerRef mxHandler; + boost::scoped_ptr<oox::core::FastParser> mxParser; osl::Mutex maMtxAction; osl::Condition maCondActionChanged; WorkerAction meAction; public: WorkerThread( WorkbookFragment& rWorkbookHandler, size_t nID ) : 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() { @@ -271,7 +276,7 @@ public: #if 0 // TODO : This still deadlocks in the fast parser code. - mrWorkbookHandler.importOoxFragment(mxHandler); + mrWorkbookHandler.importOoxFragment(mxHandler, *mxParser); #else double val = rand() / static_cast<double>(RAND_MAX); val *= 1000000; // normalize to 1 second. diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index 33270e5b13a4..66a51b4e0072 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -961,11 +961,16 @@ XmlFilterBase& WorkbookHelper::getOoxFilter() const return mrBookGlob.getOoxFilter(); } -bool WorkbookHelper::importOoxFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ) +bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler ) { return getOoxFilter().importFragment( rxHandler ); } +bool WorkbookHelper::importOoxFragment( const rtl::Reference<FragmentHandler>& rxHandler, oox::core::FastParser& rParser ) +{ + return getOoxFilter().importFragment(rxHandler, rParser); +} + // BIFF specific -------------------------------------------------------------- BiffType WorkbookHelper::getBiff() const |