summaryrefslogtreecommitdiff
path: root/package/source/zipapi/ZipOutputStream.cxx
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-21 15:17:13 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-11-17 10:49:23 +0100
commitfbf714b45625c50bb1c736ef231b5dbbab0016a1 (patch)
tree0e1a9e9002a8ce8ca46d7a7071f40c08ffea77e4 /package/source/zipapi/ZipOutputStream.cxx
parentdb5552631b13e5a1d330929cd5093bd0f9894ec8 (diff)
package: Finally implement parallel zip entries deflating
For that: 1, create ZipPackageStream::successfullyWritten to be called after the content is written 2, Do not take mutex when reading from WrapStreamForShare - threads should be using different streams anyway, but there is only one common mutex. :-/ Change-Id: I90303e49206b19454dd4141e24cc8be29c433045
Diffstat (limited to 'package/source/zipapi/ZipOutputStream.cxx')
-rw-r--r--package/source/zipapi/ZipOutputStream.cxx37
1 files changed, 27 insertions, 10 deletions
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index c9b6e08cfad7..fcfe35f82070 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -27,6 +27,7 @@
#include <PackageConstants.hxx>
#include <ZipEntry.hxx>
+#include <ZipOutputEntry.hxx>
#include <ZipPackageStream.hxx>
using namespace com::sun::star;
@@ -39,15 +40,13 @@ using namespace com::sun::star::packages::zip::ZipConstants;
ZipOutputStream::ZipOutputStream( const uno::Reference < io::XOutputStream > &xOStream )
: m_xStream(xOStream)
, m_aChucker(xOStream)
-, m_bFinished(false)
, m_pCurrentEntry(NULL)
+, m_rSharedThreadPool(comphelper::ThreadPool::getSharedOptimalPool())
{
}
ZipOutputStream::~ZipOutputStream( void )
{
- for (sal_Int32 i = 0, nEnd = m_aZipList.size(); i < nEnd; i++)
- delete m_aZipList[i];
}
void ZipOutputStream::setEntry( ZipEntry *pEntry )
@@ -66,6 +65,12 @@ void ZipOutputStream::setEntry( ZipEntry *pEntry )
}
}
+void ZipOutputStream::addDeflatingThread( ZipOutputEntry *pEntry, comphelper::ThreadTask *pThread )
+{
+ m_rSharedThreadPool.pushTask(pThread);
+ m_aEntries.push_back(pEntry);
+}
+
void ZipOutputStream::rawWrite( Sequence< sal_Int8 >& rBuffer, sal_Int32 /*nNewOffset*/, sal_Int32 nNewLength )
throw(IOException, RuntimeException)
{
@@ -85,21 +90,33 @@ void ZipOutputStream::rawCloseEntry( bool bEncrypt )
m_pCurrentEntry = NULL;
}
-void ZipOutputStream::finish( )
+void ZipOutputStream::finish()
throw(IOException, RuntimeException)
{
- if (m_bFinished)
- return;
+ assert(!m_aZipList.empty() && "Zip file must have at least one entry!");
+
+ // Wait for all threads to finish & write
+ m_rSharedThreadPool.waitUntilEmpty();
+ for (size_t i = 0; i < m_aEntries.size(); i++)
+ {
+ writeLOC(m_aEntries[i]->getZipEntry(), m_aEntries[i]->isEncrypt());
+ uno::Sequence< sal_Int8 > aCompressedData = m_aEntries[i]->getData();
+ rawWrite(aCompressedData, 0, aCompressedData.getLength());
+ rawCloseEntry(m_aEntries[i]->isEncrypt());
- if (m_aZipList.size() < 1)
- OSL_FAIL("Zip file must have at least one entry!\n");
+ m_aEntries[i]->getZipPackageStream()->successfullyWritten(m_aEntries[i]->getZipEntry());
+ delete m_aEntries[i];
+ }
sal_Int32 nOffset= static_cast < sal_Int32 > (m_aChucker.GetPosition());
- for (sal_Int32 i =0, nEnd = m_aZipList.size(); i < nEnd; i++)
+ for (size_t i = 0; i < m_aZipList.size(); i++)
+ {
writeCEN( *m_aZipList[i] );
+ delete m_aZipList[i];
+ }
writeEND( nOffset, static_cast < sal_Int32 > (m_aChucker.GetPosition()) - nOffset);
- m_bFinished = true;
m_xStream->flush();
+ m_aZipList.clear();
}
void ZipOutputStream::writeEND(sal_uInt32 nOffset, sal_uInt32 nLength)