Kaydet (Commit) a3c294e6 authored tarafından Noel Grandin's avatar Noel Grandin

convert ReadWriteGuardMode to scoped enum

Change-Id: I21ae815d5bbd7b39cd690168738c21925558585e
Reviewed-on: https://gerrit.libreoffice.org/36452Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 05144427
......@@ -21,6 +21,17 @@
#define INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX
#include <osl/mutex.hxx>
#include <o3tl/typed_flags_set.hxx>
enum class ReadWriteGuardMode {
ReadOnly = 0x00,
Write = 0x01,
CriticalChange = 0x02 | Write,
BlockCritical = 0x04, // only a block, not a read, exclusive flag!
};
namespace o3tl {
template<> struct typed_flags<ReadWriteGuardMode> : is_typed_flags<ReadWriteGuardMode, 0x7> {};
}
namespace utl {
......@@ -41,12 +52,6 @@ public:
{}
};
namespace ReadWriteGuardMode {
const sal_Int32 nWrite = 0x01;
const sal_Int32 nCriticalChange = 0x02 | nWrite;
const sal_Int32 nBlockCritical = 0x04; // only a block, not a read, exclusive flag!
}
/** Enable multiple threads to read simultaneously, but a write blocks all
other reads and writes, and a read blocks any write.
Used in I18N wrappers to be able to maintain a single instance of a wrapper
......@@ -67,11 +72,11 @@ const sal_Int32 nBlockCritical = 0x04; // only a block, not a read, exclusi
class ReadWriteGuard
{
ReadWriteMutex& rMutex;
sal_Int32 nMode;
ReadWriteGuardMode nMode;
public:
ReadWriteGuard(
ReadWriteMutex& rMutex,
sal_Int32 nRequestMode = 0 // read only
ReadWriteGuardMode nRequestMode = ReadWriteGuardMode::ReadOnly // read only
);
~ReadWriteGuard();
......
......@@ -115,7 +115,7 @@ LocaleDataWrapper::~LocaleDataWrapper()
void LocaleDataWrapper::setLanguageTag( const LanguageTag& rLanguageTag )
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nCriticalChange );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::CriticalChange );
maLanguageTag = rLanguageTag;
invalidateData();
}
......@@ -1383,7 +1383,7 @@ sal_Unicode* LocaleDataWrapper::ImplAddFormatNum( sal_Unicode* pBuf,
OUString LocaleDataWrapper::getDate( const Date& rDate ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
//!TODO: leading zeros et al
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
......@@ -1429,7 +1429,7 @@ OUString LocaleDataWrapper::getDate( const Date& rDate ) const
OUString LocaleDataWrapper::getTime( const tools::Time& rTime, bool bSec, bool b100Sec ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
//!TODO: leading zeros et al
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
......@@ -1458,7 +1458,7 @@ OUString LocaleDataWrapper::getTime( const tools::Time& rTime, bool bSec, bool b
OUString LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal,
bool bTwoDigitYear ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
using namespace css::i18n;
sal_Unicode aBuf[20];
sal_Unicode* pBuf;
......@@ -1500,7 +1500,7 @@ OUString LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCa
OUString LocaleDataWrapper::getDuration( const tools::Time& rTime, bool bSec, bool b100Sec ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
......@@ -1544,7 +1544,7 @@ inline size_t ImplGetNumberStringLengthGuess( const LocaleDataWrapper& rLoc, sal
OUString LocaleDataWrapper::getNum( sal_Int64 nNumber, sal_uInt16 nDecimals,
bool bUseThousandSep, bool bTrailingZeros ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
sal_Unicode aBuf[128]; // big enough for 64-bit long and crazy grouping
// check if digits and separators will fit into fixed buffer or allocate
size_t nGuess = ImplGetNumberStringLengthGuess( *this, nDecimals );
......@@ -1563,7 +1563,7 @@ OUString LocaleDataWrapper::getNum( sal_Int64 nNumber, sal_uInt16 nDecimals,
OUString LocaleDataWrapper::getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals,
const OUString& rCurrencySymbol, bool bUseThousandSep ) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
sal_Unicode aBuf[192];
sal_Unicode aNumBuf[128]; // big enough for 64-bit long and crazy grouping
sal_Unicode cZeroChar = getCurrZeroChar();
......@@ -1771,7 +1771,7 @@ LanguageTag LocaleDataWrapper::getLoadedLanguageTag() const
OUString LocaleDataWrapper::appendLocaleInfo(const OUString& rDebugMsg) const
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::BlockCritical );
OUStringBuffer aDebugMsg(rDebugMsg);
aDebugMsg.append('\n');
aDebugMsg.append(maLanguageTag.getBcp47());
......@@ -1872,7 +1872,7 @@ css::uno::Sequence< OUString > LocaleDataWrapper::getDateAcceptancePatterns() co
void LocaleDataWrapper::setDateAcceptancePatterns(
const css::uno::Sequence< OUString > & rPatterns )
{
::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nWrite );
::utl::ReadWriteGuard aGuard( aMutex, ReadWriteGuardMode::Write );
if (!aDateAcceptancePatterns.getLength() || !rPatterns.getLength())
{
......
......@@ -23,14 +23,14 @@
namespace utl {
ReadWriteGuard::ReadWriteGuard( ReadWriteMutex& rMutexP,
sal_Int32 nRequestMode )
ReadWriteGuardMode nRequestMode )
: rMutex( rMutexP )
{
// don't do anything until a pending write completed (or another
// ReadWriteGuard leaves the ctor phase)
::osl::MutexGuard aGuard( rMutex.maWriteMutex );
nMode = nRequestMode;
if ( nMode & ReadWriteGuardMode::nWrite )
if ( nMode & ReadWriteGuardMode::Write )
{
rMutex.maWriteMutex.acquire();
// wait for any read to complete
......@@ -40,12 +40,12 @@ ReadWriteGuard::ReadWriteGuard( ReadWriteMutex& rMutexP,
{
rMutex.maMutex.acquire();
bWait = (rMutex.nReadCount != 0);
if ( nMode & ReadWriteGuardMode::nCriticalChange )
if ( nMode & ReadWriteGuardMode::CriticalChange )
bWait |= (rMutex.nBlockCriticalCount != 0);
rMutex.maMutex.release();
} while ( bWait );
}
else if ( nMode & ReadWriteGuardMode::nBlockCritical )
else if ( nMode & ReadWriteGuardMode::BlockCritical )
{
rMutex.maMutex.acquire();
++rMutex.nBlockCriticalCount;
......@@ -61,9 +61,9 @@ ReadWriteGuard::ReadWriteGuard( ReadWriteMutex& rMutexP,
ReadWriteGuard::~ReadWriteGuard()
{
if ( nMode & ReadWriteGuardMode::nWrite )
if ( nMode & ReadWriteGuardMode::Write )
rMutex.maWriteMutex.release();
else if ( nMode & ReadWriteGuardMode::nBlockCritical )
else if ( nMode & ReadWriteGuardMode::BlockCritical )
{
rMutex.maMutex.acquire();
--rMutex.nBlockCriticalCount;
......@@ -79,7 +79,7 @@ ReadWriteGuard::~ReadWriteGuard()
void ReadWriteGuard::changeReadToWrite()
{
bool bOk = !(nMode & (ReadWriteGuardMode::nWrite | ReadWriteGuardMode::nBlockCritical));
bool bOk = !(nMode & (ReadWriteGuardMode::Write | ReadWriteGuardMode::BlockCritical));
DBG_ASSERT( bOk, "ReadWriteGuard::changeReadToWrite: can't" );
if ( bOk )
{
......@@ -91,7 +91,7 @@ void ReadWriteGuard::changeReadToWrite()
rMutex.maMutex.release();
rMutex.maWriteMutex.acquire();
nMode |= ReadWriteGuardMode::nWrite;
nMode |= ReadWriteGuardMode::Write;
// wait for any other read to complete
// TODO: set up a waiting thread instead of a loop
bool bWait = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment