summaryrefslogtreecommitdiff
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
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>
-rw-r--r--include/svl/documentlockfile.hxx12
-rw-r--r--include/svl/lockfilecommon.hxx4
-rw-r--r--include/svl/msodocumentlockfile.hxx9
-rw-r--r--include/svl/sharecontrolfile.hxx5
-rw-r--r--svl/source/misc/documentlockfile.cxx33
-rw-r--r--svl/source/misc/msodocumentlockfile.cxx20
-rw-r--r--svl/source/misc/sharecontrolfile.cxx34
7 files changed, 64 insertions, 53 deletions
diff --git a/include/svl/documentlockfile.hxx b/include/svl/documentlockfile.hxx
index b4f731db7fc8..d5dee52561cb 100644
--- a/include/svl/documentlockfile.hxx
+++ b/include/svl/documentlockfile.hxx
@@ -43,23 +43,25 @@ public:
/// Only delete lockfile, disregarding ownership
void RemoveFileDirectly();
- virtual LockFileEntry GetLockData() = 0;
+ LockFileEntry GetLockData();
protected:
- virtual void WriteEntryToStream( const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) = 0;
- virtual css::uno::Reference< css::io::XInputStream > OpenStream();
+ virtual LockFileEntry GetLockDataImpl(std::unique_lock<std::mutex>& rGuard) = 0;
+ virtual void WriteEntryToStream( std::unique_lock<std::mutex>& rGuard, const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) = 0;
+ virtual css::uno::Reference< css::io::XInputStream > OpenStream(std::unique_lock<std::mutex>& rGuard);
};
/// Class implementing reading and writing LO lockfiles.
class SVL_DLLPUBLIC DocumentLockFile final : public GenDocumentLockFile
{
- virtual void WriteEntryToStream( const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) override;
+ virtual void WriteEntryToStream( std::unique_lock<std::mutex>& rGuard, const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) override;
public:
DocumentLockFile( std::u16string_view aOrigURL );
virtual ~DocumentLockFile() override;
- virtual LockFileEntry GetLockData() override;
+protected:
+ virtual LockFileEntry GetLockDataImpl(std::unique_lock<std::mutex>& rGuard) override;
};
}
diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx
index d71cb8262e92..6a19681b6f7a 100644
--- a/include/svl/lockfilecommon.hxx
+++ b/include/svl/lockfilecommon.hxx
@@ -24,10 +24,10 @@
#include <com/sun/star/uno/Sequence.hxx>
-#include <osl/mutex.hxx>
#include <tools/urlobj.hxx>
#include <o3tl/enumarray.hxx>
+#include <mutex>
#include <string_view>
#include <vector>
@@ -47,7 +47,7 @@ private:
OUString m_aURL;
protected:
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
/// This method generates the URL of the lock file based on the document URL and the specified prefix.
static OUString GenerateOwnLockFileURL(std::u16string_view aOrigURL, std::u16string_view aPrefix);
diff --git a/include/svl/msodocumentlockfile.hxx b/include/svl/msodocumentlockfile.hxx
index f91c7ccffe44..282f427b32aa 100644
--- a/include/svl/msodocumentlockfile.hxx
+++ b/include/svl/msodocumentlockfile.hxx
@@ -33,17 +33,18 @@ private:
AppType m_eAppType;
virtual void
- WriteEntryToStream(const LockFileEntry& aEntry,
+ WriteEntryToStream(std::unique_lock<std::mutex>& rGuard, const LockFileEntry& aEntry,
const css::uno::Reference<css::io::XOutputStream>& xStream) override;
- virtual css::uno::Reference<css::io::XInputStream> OpenStream() override;
+ virtual css::uno::Reference<css::io::XInputStream>
+ OpenStream(std::unique_lock<std::mutex>& rGuard) override;
+
+ virtual LockFileEntry GetLockDataImpl(std::unique_lock<std::mutex>& rGuard) override;
public:
MSODocumentLockFile(std::u16string_view aOrigURL);
virtual ~MSODocumentLockFile() override;
- virtual LockFileEntry GetLockData() override;
-
virtual void RemoveFile() override;
static bool IsMSOSupportedFileFormat(std::u16string_view aURL);
diff --git a/include/svl/sharecontrolfile.hxx b/include/svl/sharecontrolfile.hxx
index fe717131262b..a7b9ac1db297 100644
--- a/include/svl/sharecontrolfile.hxx
+++ b/include/svl/sharecontrolfile.hxx
@@ -56,12 +56,15 @@ public:
virtual ~ShareControlFile() override;
std::vector< LockFileEntry > GetUsersData();
- void SetUsersDataAndStore( std::vector< LockFileEntry >&& aUserNames );
+ void SetUsersDataAndStore( std::unique_lock<std::mutex>& rGuard, std::vector< LockFileEntry >&& aUserNames );
LockFileEntry InsertOwnEntry();
bool HasOwnEntry();
void RemoveEntry( const LockFileEntry& aOptionalSpecification );
void RemoveEntry();
void RemoveFile();
+private:
+ void RemoveFileImpl(std::unique_lock<std::mutex>& rGuard);
+ std::vector< LockFileEntry > GetUsersDataImpl(std::unique_lock<std::mutex>& rGuard);
};
}
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();