summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-02-15 10:55:14 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-02-15 10:03:24 +0000
commitbfbbdab13f16adf66f1afb9e2a2a103162927ba3 (patch)
tree666df4476917cf0a87427ebb4a215cca56bc3aa0 /svl
parentddf4f82443254d88d9b984c68ed05fa16bb4607a (diff)
osl::Mutex->std::mutex in LockFileCommon
Change-Id: I729b7ecf8280c67e4698b174a6151d1eda41be60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147040 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/misc/documentlockfile.cxx33
-rw-r--r--svl/source/misc/msodocumentlockfile.cxx20
-rw-r--r--svl/source/misc/sharecontrolfile.cxx34
3 files changed, 46 insertions, 41 deletions
diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx
index 0ba862f33098..31cbd1969324 100644
--- a/svl/source/misc/documentlockfile.cxx
+++ b/svl/source/misc/documentlockfile.cxx
@@ -55,10 +55,8 @@ GenDocumentLockFile::~GenDocumentLockFile()
{
}
-uno::Reference< io::XInputStream > GenDocumentLockFile::OpenStream()
+uno::Reference< io::XInputStream > GenDocumentLockFile::OpenStream(std::unique_lock<std::mutex>& /*rGuard*/)
{
- ::osl::MutexGuard aGuard( m_aMutex );
-
uno::Reference < css::ucb::XCommandEnvironment > xEnv;
::ucbhelper::Content aSourceContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
@@ -68,7 +66,7 @@ uno::Reference< io::XInputStream > GenDocumentLockFile::OpenStream()
bool GenDocumentLockFile::CreateOwnLockFile()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
try
{
@@ -84,7 +82,7 @@ bool GenDocumentLockFile::CreateOwnLockFile()
throw uno::RuntimeException();
LockFileEntry aNewEntry = GenerateOwnEntry();
- WriteEntryToStream( aNewEntry, xOutput );
+ WriteEntryToStream( aGuard, aNewEntry, xOutput );
xOutput->closeOutput();
xSeekable->seek( 0 );
@@ -114,6 +112,8 @@ bool GenDocumentLockFile::CreateOwnLockFile()
bool GenDocumentLockFile::OverwriteOwnLockFile()
{
+ std::unique_lock aGuard(m_aMutex);
+
// allows to overwrite the lock file with the current data
try
{
@@ -127,7 +127,7 @@ bool GenDocumentLockFile::OverwriteOwnLockFile()
uno::Reference< io::XTruncate > xTruncate( xOutput, uno::UNO_QUERY_THROW );
xTruncate->truncate();
- WriteEntryToStream( aNewEntry, xOutput );
+ WriteEntryToStream( aGuard, aNewEntry, xOutput );
xOutput->closeOutput();
}
catch( uno::Exception& )
@@ -140,11 +140,11 @@ bool GenDocumentLockFile::OverwriteOwnLockFile()
void GenDocumentLockFile::RemoveFile()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
// TODO/LATER: the removing is not atomic, is it possible in general to make it atomic?
LockFileEntry aNewEntry = GenerateOwnEntry();
- LockFileEntry aFileData = GetLockData();
+ LockFileEntry aFileData = GetLockDataImpl(aGuard);
if ( aFileData[LockFileComponent::SYSUSERNAME] != aNewEntry[LockFileComponent::SYSUSERNAME]
|| aFileData[LockFileComponent::LOCALHOST] != aNewEntry[LockFileComponent::LOCALHOST]
@@ -162,6 +162,11 @@ void GenDocumentLockFile::RemoveFileDirectly()
uno::Any(true));
}
+LockFileEntry GenDocumentLockFile::GetLockData()
+{
+ std::unique_lock aGuard(m_aMutex);
+ return GetLockDataImpl(aGuard);
+}
DocumentLockFile::DocumentLockFile( std::u16string_view aOrigURL )
: GenDocumentLockFile(GenerateOwnLockFileURL(aOrigURL, u".~lock."))
@@ -174,10 +179,10 @@ DocumentLockFile::~DocumentLockFile()
}
-void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const uno::Reference< io::XOutputStream >& xOutput )
+void DocumentLockFile::WriteEntryToStream(
+ std::unique_lock<std::mutex>& /*rGuard*/,
+ const LockFileEntry& aEntry, const uno::Reference< io::XOutputStream >& xOutput )
{
- ::osl::MutexGuard aGuard( m_aMutex );
-
OUStringBuffer aBuffer(256);
for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
@@ -194,11 +199,9 @@ void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const un
xOutput->writeBytes( aData );
}
-LockFileEntry DocumentLockFile::GetLockData()
+LockFileEntry DocumentLockFile::GetLockDataImpl(std::unique_lock<std::mutex>& rGuard)
{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- uno::Reference< io::XInputStream > xInput = OpenStream();
+ uno::Reference< io::XInputStream > xInput = OpenStream(rGuard);
if ( !xInput.is() )
throw uno::RuntimeException();
diff --git a/svl/source/misc/msodocumentlockfile.cxx b/svl/source/misc/msodocumentlockfile.cxx
index 26192c220371..dab0486e439b 100644
--- a/svl/source/misc/msodocumentlockfile.cxx
+++ b/svl/source/misc/msodocumentlockfile.cxx
@@ -86,10 +86,9 @@ MSODocumentLockFile::MSODocumentLockFile(std::u16string_view aOrigURL)
MSODocumentLockFile::~MSODocumentLockFile() {}
void MSODocumentLockFile::WriteEntryToStream(
- const LockFileEntry& aEntry, const css::uno::Reference<css::io::XOutputStream>& xOutput)
+ std::unique_lock<std::mutex>& /*rGuard*/, const LockFileEntry& aEntry,
+ const css::uno::Reference<css::io::XOutputStream>& xOutput)
{
- ::osl::MutexGuard aGuard(m_aMutex);
-
// Reallocate the date with the right size, different lock file size for different components
int nLockFileSize = m_eAppType == AppType::Word ? MSO_WORD_LOCKFILE_SIZE
: MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE;
@@ -181,10 +180,9 @@ void MSODocumentLockFile::WriteEntryToStream(
xOutput->writeBytes(aData);
}
-css::uno::Reference<css::io::XInputStream> MSODocumentLockFile::OpenStream()
+css::uno::Reference<css::io::XInputStream>
+MSODocumentLockFile::OpenStream(std::unique_lock<std::mutex>& /*rGuard*/)
{
- ::osl::MutexGuard aGuard(m_aMutex);
-
css::uno::Reference<css::ucb::XCommandEnvironment> xEnv;
::ucbhelper::Content aSourceContent(GetURL(), xEnv, comphelper::getProcessComponentContext());
@@ -192,12 +190,10 @@ css::uno::Reference<css::io::XInputStream> MSODocumentLockFile::OpenStream()
return aSourceContent.openStreamNoLock();
}
-LockFileEntry MSODocumentLockFile::GetLockData()
+LockFileEntry MSODocumentLockFile::GetLockDataImpl(std::unique_lock<std::mutex>& rGuard)
{
- ::osl::MutexGuard aGuard(m_aMutex);
-
LockFileEntry aResult;
- css::uno::Reference<css::io::XInputStream> xInput = OpenStream();
+ css::uno::Reference<css::io::XInputStream> xInput = OpenStream(rGuard);
if (!xInput.is())
throw css::uno::RuntimeException();
@@ -248,11 +244,11 @@ LockFileEntry MSODocumentLockFile::GetLockData()
void MSODocumentLockFile::RemoveFile()
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
// TODO/LATER: the removing is not atomic, is it possible in general to make it atomic?
LockFileEntry aNewEntry = GenerateOwnEntry();
- LockFileEntry aFileData = GetLockData();
+ LockFileEntry aFileData = GetLockDataImpl(aGuard);
if (aFileData[LockFileComponent::OOOUSERNAME] != aNewEntry[LockFileComponent::OOOUSERNAME])
throw css::io::IOException(); // not the owner, access denied
diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx
index 740e10eaa19c..7c8fd854b294 100644
--- a/svl/source/misc/sharecontrolfile.cxx
+++ b/svl/source/misc/sharecontrolfile.cxx
@@ -139,8 +139,12 @@ void ShareControlFile::Close()
std::vector< o3tl::enumarray< LockFileComponent, OUString > > ShareControlFile::GetUsersData()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard(m_aMutex);
+ return GetUsersDataImpl(aGuard);
+}
+std::vector< o3tl::enumarray< LockFileComponent, OUString > > ShareControlFile::GetUsersDataImpl(std::unique_lock<std::mutex>& /*rGuard*/)
+{
if ( !IsValid() )
throw io::NotConnectedException();
@@ -175,10 +179,8 @@ std::vector< o3tl::enumarray< LockFileComponent, OUString > > ShareControlFile::
}
-void ShareControlFile::SetUsersDataAndStore( std::vector< LockFileEntry >&& aUsersData )
+void ShareControlFile::SetUsersDataAndStore( std::unique_lock<std::mutex>& /*rGuard*/, std::vector< LockFileEntry >&& aUsersData )
{
- ::osl::MutexGuard aGuard( m_aMutex );
-
if ( !IsValid() )
throw io::NotConnectedException();
@@ -210,12 +212,12 @@ void ShareControlFile::SetUsersDataAndStore( std::vector< LockFileEntry >&& aUse
LockFileEntry ShareControlFile::InsertOwnEntry()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
if ( !IsValid() )
throw io::NotConnectedException();
- GetUsersData();
+ GetUsersDataImpl(aGuard);
std::vector< LockFileEntry > aNewData( m_aUsersData );
LockFileEntry aNewEntry = GenerateOwnEntry();
@@ -244,7 +246,7 @@ LockFileEntry ShareControlFile::InsertOwnEntry()
if ( !bExists )
aNewData.push_back( aNewEntry );
- SetUsersDataAndStore( std::move(aNewData) );
+ SetUsersDataAndStore( aGuard, std::move(aNewData) );
return aNewEntry;
}
@@ -252,14 +254,14 @@ LockFileEntry ShareControlFile::InsertOwnEntry()
bool ShareControlFile::HasOwnEntry()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
if ( !IsValid() )
{
throw io::NotConnectedException();
}
- GetUsersData();
+ GetUsersDataImpl(aGuard);
LockFileEntry aEntry = GenerateOwnEntry();
for (LockFileEntry & rEntry : m_aUsersData)
@@ -283,12 +285,12 @@ void ShareControlFile::RemoveEntry()
void ShareControlFile::RemoveEntry( const LockFileEntry& aEntry )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
if ( !IsValid() )
throw io::NotConnectedException();
- GetUsersData();
+ GetUsersDataImpl(aGuard);
std::vector< LockFileEntry > aNewData;
@@ -303,20 +305,24 @@ void ShareControlFile::RemoveEntry( const LockFileEntry& aEntry )
}
const bool bNewDataEmpty = aNewData.empty();
- SetUsersDataAndStore( std::move(aNewData) );
+ SetUsersDataAndStore( aGuard, std::move(aNewData) );
if ( bNewDataEmpty )
{
// try to remove the file if it is empty
- RemoveFile();
+ RemoveFileImpl(aGuard);
}
}
void ShareControlFile::RemoveFile()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard(m_aMutex);
+ return RemoveFileImpl(aGuard);
+}
+void ShareControlFile::RemoveFileImpl(std::unique_lock<std::mutex>& /*rGuard*/)
+{
if ( !IsValid() )
throw io::NotConnectedException();