summaryrefslogtreecommitdiff
path: root/comphelper/source/streaming/seqoutputstreamserv.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper/source/streaming/seqoutputstreamserv.cxx')
-rw-r--r--comphelper/source/streaming/seqoutputstreamserv.cxx25
1 files changed, 15 insertions, 10 deletions
diff --git a/comphelper/source/streaming/seqoutputstreamserv.cxx b/comphelper/source/streaming/seqoutputstreamserv.cxx
index 477961397413..19ef79002978 100644
--- a/comphelper/source/streaming/seqoutputstreamserv.cxx
+++ b/comphelper/source/streaming/seqoutputstreamserv.cxx
@@ -19,13 +19,13 @@
#include <sal/config.h>
-#include <osl/mutex.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/seqstream.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/io/NotConnectedException.hpp>
#include <com/sun/star/io/XSequenceOutputStream.hpp>
+#include <mutex>
namespace com::sun::star::uno { class XComponentContext; }
@@ -61,9 +61,10 @@ private:
virtual ~SequenceOutputStreamService() override {};
- ::osl::Mutex m_aMutex;
- uno::Reference< io::XOutputStream > m_xOutputStream;
+ std::mutex m_aMutex;
+ // WARNING: dtor of m_xOutputStream writes into m_aSequence so that must live longer!
uno::Sequence< ::sal_Int8 > m_aSequence;
+ uno::Reference< io::XOutputStream > m_xOutputStream;
};
SequenceOutputStreamService::SequenceOutputStreamService()
{
@@ -89,7 +90,7 @@ uno::Sequence< OUString > SAL_CALL SequenceOutputStreamService::getSupportedServ
// css::io::XOutputStream:
void SAL_CALL SequenceOutputStreamService::writeBytes( const uno::Sequence< ::sal_Int8 > & aData )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::scoped_lock aGuard( m_aMutex );
if ( !m_xOutputStream.is() )
throw io::NotConnectedException();
@@ -98,7 +99,7 @@ void SAL_CALL SequenceOutputStreamService::writeBytes( const uno::Sequence< ::sa
void SAL_CALL SequenceOutputStreamService::flush()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::scoped_lock aGuard( m_aMutex );
if ( !m_xOutputStream.is() )
throw io::NotConnectedException();
@@ -107,10 +108,11 @@ void SAL_CALL SequenceOutputStreamService::flush()
void SAL_CALL SequenceOutputStreamService::closeOutput()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::scoped_lock aGuard( m_aMutex );
if ( !m_xOutputStream.is() )
throw io::NotConnectedException();
+ m_xOutputStream->flush();
m_xOutputStream->closeOutput();
m_xOutputStream.clear();
}
@@ -118,11 +120,14 @@ void SAL_CALL SequenceOutputStreamService::closeOutput()
// css::io::XSequenceOutputStream:
uno::Sequence< ::sal_Int8 > SAL_CALL SequenceOutputStreamService::getWrittenBytes()
{
- ::osl::MutexGuard aGuard( m_aMutex );
- if ( !m_xOutputStream.is() )
- throw io::NotConnectedException();
+ std::scoped_lock aGuard( m_aMutex );
+
+ if (m_xOutputStream.is())
+ {
+ m_xOutputStream->flush();
+ }
+ // else: no exception, just return the finished sequence
- m_xOutputStream->flush();
return m_aSequence;
}