summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorEike Rathke <er@openoffice.org>2001-07-05 13:58:36 +0000
committerEike Rathke <er@openoffice.org>2001-07-05 13:58:36 +0000
commitdd60e56d7fc50b15b9a3b18937b2f98020495dd2 (patch)
treef174782086818ebc8d510c48b57b05ebcbf6aef5 /unotools
parent738731209bff5c1d713e1c495102137eba3ad7b0 (diff)
#89253# use ReadWriteMutex/ReadWriteGuard
Diffstat (limited to 'unotools')
-rw-r--r--unotools/inc/unotools/charclass.hxx11
-rw-r--r--unotools/inc/unotools/localedatawrapper.hxx28
-rw-r--r--unotools/source/i18n/charclass.cxx46
-rw-r--r--unotools/source/i18n/localedatawrapper.cxx118
4 files changed, 61 insertions, 142 deletions
diff --git a/unotools/inc/unotools/charclass.hxx b/unotools/inc/unotools/charclass.hxx
index 7d055c3a100e..3436effaac72 100644
--- a/unotools/inc/unotools/charclass.hxx
+++ b/unotools/inc/unotools/charclass.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: charclass.hxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: fs $ $Date: 2001-05-17 13:04:24 $
+ * last change: $Author: er $ $Date: 2001-07-05 14:58:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -87,6 +87,10 @@
#include <com/sun/star/i18n/XCharacterClassification.hpp>
#endif
+#ifndef INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX
+#include <unotools/readwritemutexguard.hxx>
+#endif
+
class String;
namespace com { namespace sun { namespace star {
namespace lang {
@@ -126,6 +130,7 @@ class CharClass
::com::sun::star::lang::Locale aLocale;
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > xCC;
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr;
+ mutable ::utl::ReadWriteMutex aMutex;
// not implemented, prevent usage
CharClass( const CharClass& );
@@ -153,7 +158,7 @@ public:
void setLocale( const ::com::sun::star::lang::Locale& rLocale );
/// get current Locale
- const ::com::sun::star::lang::Locale& getLocale() const { return aLocale; }
+ const ::com::sun::star::lang::Locale& getLocale() const;
/// isdigit() on ascii values
diff --git a/unotools/inc/unotools/localedatawrapper.hxx b/unotools/inc/unotools/localedatawrapper.hxx
index f0b878fdcd11..add64e46e929 100644
--- a/unotools/inc/unotools/localedatawrapper.hxx
+++ b/unotools/inc/unotools/localedatawrapper.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: localedatawrapper.hxx,v $
*
- * $Revision: 1.15 $
+ * $Revision: 1.16 $
*
- * last change: $Author: er $ $Date: 2001-07-02 09:51:07 $
+ * last change: $Author: er $ $Date: 2001-07-05 14:58:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -79,25 +79,9 @@
#include <com/sun/star/i18n/reservedWords.hpp>
#endif
-
-class LocaleDataWrapperGuard;
-class LocaleDataWrapperMutex
-{
- friend class LocaleDataWrapperGuard;
-
- sal_Int32 nReadCount;
- ::osl::Mutex* pMutex;
- ::osl::Mutex* pWriteMutex;
-
-public:
- LocaleDataWrapperMutex()
- : nReadCount(0)
- , pMutex( new ::osl::Mutex )
- , pWriteMutex( new ::osl::Mutex )
- {}
- ~LocaleDataWrapperMutex()
- { delete pMutex; delete pWriteMutex; }
-};
+#ifndef INCLUDED_UNOTOOLS_READWRITEMUTEXGUARD_HXX
+#include <unotools/readwritemutexguard.hxx>
+#endif
namespace com { namespace sun { namespace star {
@@ -131,7 +115,7 @@ class LocaleDataWrapper
USHORT nCurrDigits;
BOOL bLocaleDataItemValid;
BOOL bReservedWordValid;
- mutable LocaleDataWrapperMutex aMutex;
+ mutable ::utl::ReadWriteMutex aMutex;
// dummies, to be implemented or provided by XML locale data
sal_Unicode cCurrZeroChar;
diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx
index b793d0900e9f..7bfa1b792689 100644
--- a/unotools/source/i18n/charclass.cxx
+++ b/unotools/source/i18n/charclass.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: charclass.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: fs $ $Date: 2001-05-17 13:05:17 $
+ * last change: $Author: er $ $Date: 2001-07-05 14:57:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -156,12 +156,20 @@ void CharClass::getComponentInstance()
void CharClass::setLocale( const ::com::sun::star::lang::Locale& rLocale )
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nCriticalChange );
aLocale.Language = rLocale.Language;
aLocale.Country = rLocale.Country;
aLocale.Variant = rLocale.Variant;
}
+const ::com::sun::star::lang::Locale& CharClass::getLocale() const
+{
+ ::utl::ReadWriteGuard aGuard( aMutex );
+ return aLocale;
+}
+
+
// static
sal_Bool CharClass::isAsciiNumeric( const String& rStr )
{
@@ -215,7 +223,7 @@ sal_Bool CharClass::isAlpha( const String& rStr, xub_StrLen nPos ) const
try
{
if ( xCC.is() )
- return (xCC->getCharacterType( rStr, nPos, aLocale ) &
+ return (xCC->getCharacterType( rStr, nPos, getLocale() ) &
nCharClassAlphaType) != 0;
else
return sal_False;
@@ -233,7 +241,7 @@ sal_Bool CharClass::isAlpha( const String& rStr ) const
try
{
if ( xCC.is() )
- return isAlphaType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) );
+ return isAlphaType( xCC->getStringType( rStr, 0, rStr.Len(), getLocale() ) );
else
return sal_False;
}
@@ -250,7 +258,7 @@ sal_Bool CharClass::isLetter( const String& rStr, xub_StrLen nPos ) const
try
{
if ( xCC.is() )
- return (xCC->getCharacterType( rStr, nPos, aLocale ) &
+ return (xCC->getCharacterType( rStr, nPos, getLocale() ) &
nCharClassLetterType) != 0;
else
return sal_False;
@@ -268,7 +276,7 @@ sal_Bool CharClass::isLetter( const String& rStr ) const
try
{
if ( xCC.is() )
- return isLetterType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) );
+ return isLetterType( xCC->getStringType( rStr, 0, rStr.Len(), getLocale() ) );
else
return sal_False;
}
@@ -285,7 +293,7 @@ sal_Bool CharClass::isDigit( const String& rStr, xub_StrLen nPos ) const
try
{
if ( xCC.is() )
- return (xCC->getCharacterType( rStr, nPos, aLocale ) &
+ return (xCC->getCharacterType( rStr, nPos, getLocale() ) &
KCharacterType::DIGIT) != 0;
else
return sal_False;
@@ -303,7 +311,7 @@ sal_Bool CharClass::isNumeric( const String& rStr ) const
try
{
if ( xCC.is() )
- return isNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) );
+ return isNumericType( xCC->getStringType( rStr, 0, rStr.Len(), getLocale() ) );
else
return sal_False;
}
@@ -320,7 +328,7 @@ sal_Bool CharClass::isAlphaNumeric( const String& rStr, xub_StrLen nPos ) const
try
{
if ( xCC.is() )
- return (xCC->getCharacterType( rStr, nPos, aLocale ) &
+ return (xCC->getCharacterType( rStr, nPos, getLocale() ) &
(nCharClassAlphaType | KCharacterType::DIGIT)) != 0;
else
return sal_False;
@@ -338,7 +346,7 @@ sal_Bool CharClass::isAlphaNumeric( const String& rStr ) const
try
{
if ( xCC.is() )
- return isAlphaNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) );
+ return isAlphaNumericType( xCC->getStringType( rStr, 0, rStr.Len(), getLocale() ) );
else
return sal_False;
}
@@ -355,7 +363,7 @@ sal_Bool CharClass::isLetterNumeric( const String& rStr, xub_StrLen nPos ) const
try
{
if ( xCC.is() )
- return (xCC->getCharacterType( rStr, nPos, aLocale ) &
+ return (xCC->getCharacterType( rStr, nPos, getLocale() ) &
(nCharClassLetterType | KCharacterType::DIGIT)) != 0;
else
return sal_False;
@@ -373,7 +381,7 @@ sal_Bool CharClass::isLetterNumeric( const String& rStr ) const
try
{
if ( xCC.is() )
- return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) );
+ return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.Len(), getLocale() ) );
else
return sal_False;
}
@@ -402,7 +410,7 @@ String CharClass::toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCoun
try
{
if ( xCC.is() )
- return xCC->toTitle( rStr, nPos, nCount, aLocale );
+ return xCC->toTitle( rStr, nPos, nCount, getLocale() );
else
return rStr.Copy( nPos, nCount );
}
@@ -419,7 +427,7 @@ String CharClass::toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCoun
try
{
if ( xCC.is() )
- return xCC->toUpper( rStr, nPos, nCount, aLocale );
+ return xCC->toUpper( rStr, nPos, nCount, getLocale() );
else
return rStr.copy( nPos, nCount );
}
@@ -436,7 +444,7 @@ String CharClass::toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCoun
try
{
if ( xCC.is() )
- return xCC->toLower( rStr, nPos, nCount, aLocale );
+ return xCC->toLower( rStr, nPos, nCount, getLocale() );
else
return rStr.copy( nPos, nCount );
}
@@ -504,7 +512,7 @@ sal_Int32 CharClass::getCharacterType( const String& rStr, xub_StrLen nPos ) con
try
{
if ( xCC.is() )
- return xCC->getCharacterType( rStr, nPos, aLocale );
+ return xCC->getCharacterType( rStr, nPos, getLocale() );
else
return 0;
}
@@ -521,7 +529,7 @@ sal_Int32 CharClass::getStringType( const String& rStr, xub_StrLen nPos, xub_Str
try
{
if ( xCC.is() )
- return xCC->getStringType( rStr, nPos, nCount, aLocale );
+ return xCC->getStringType( rStr, nPos, nCount, getLocale() );
else
return 0;
}
@@ -544,7 +552,7 @@ sal_Int32 CharClass::getStringType( const String& rStr, xub_StrLen nPos, xub_Str
try
{
if ( xCC.is() )
- return xCC->parseAnyToken( rStr, nPos, aLocale,
+ return xCC->parseAnyToken( rStr, nPos, getLocale(),
nStartCharFlags, userDefinedCharactersStart,
nContCharFlags, userDefinedCharactersCont );
else
@@ -570,7 +578,7 @@ sal_Int32 CharClass::getStringType( const String& rStr, xub_StrLen nPos, xub_Str
try
{
if ( xCC.is() )
- return xCC->parsePredefinedToken( nTokenType, rStr, nPos, aLocale,
+ return xCC->parsePredefinedToken( nTokenType, rStr, nPos, getLocale(),
nStartCharFlags, userDefinedCharactersStart,
nContCharFlags, userDefinedCharactersCont );
else
diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx
index 7ccc8108b70c..d579aa8da366 100644
--- a/unotools/source/i18n/localedatawrapper.cxx
+++ b/unotools/source/i18n/localedatawrapper.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: localedatawrapper.cxx,v $
*
- * $Revision: 1.17 $
+ * $Revision: 1.18 $
*
- * last change: $Author: er $ $Date: 2001-07-02 09:51:22 $
+ * last change: $Author: er $ $Date: 2001-07-05 14:57:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -109,90 +109,6 @@
#include <com/sun/star/i18n/CalendarDisplayIndex.hpp>
#endif
-
-// ====================================================================
-
-// Enable multiple threads to read simultaneously, but a write blocks all other
-// reads and writes, and a read blocks any write.
-class LocaleDataWrapperGuard
-{
- LocaleDataWrapperMutex& rMutex;
- ::osl::MutexGuard* pGuard;
-public:
- LocaleDataWrapperGuard(
- LocaleDataWrapperMutex& rMutex,
- sal_Bool bRequestWrite = sal_False );
- ~LocaleDataWrapperGuard();
-
- void changeReadToWrite();
-};
-
-
-LocaleDataWrapperGuard::LocaleDataWrapperGuard(
- LocaleDataWrapperMutex& rMutexP, sal_Bool bRequestWrite )
- : rMutex( rMutexP )
-{
- // don't do anything until a pending write completed
- ::osl::MutexGuard aGuard( rMutex.pWriteMutex );
- if ( bRequestWrite )
- {
- pGuard = new ::osl::MutexGuard( rMutex.pWriteMutex );
- // wait for any read to complete
-// TODO: set up a waiting thread instead of a loop
- sal_Bool bWait = TRUE;
- do
- {
- ::osl::MutexGuard aGuard( rMutex.pMutex );
- bWait = (rMutex.nReadCount != 0);
- } while ( bWait );
- }
- else
- {
- pGuard = NULL;
- ::osl::MutexGuard aGuard( rMutex.pMutex );
- ++rMutex.nReadCount;
- }
-}
-
-
-LocaleDataWrapperGuard::~LocaleDataWrapperGuard()
-{
- if ( pGuard )
- delete pGuard;
- else
- {
- ::osl::MutexGuard aGuard( rMutex.pMutex );
- --rMutex.nReadCount;
- }
-}
-
-
-void LocaleDataWrapperGuard::changeReadToWrite()
-{
- DBG_ASSERT( !pGuard, "LocaleDataWrapperGuard::changeReadToWrite: already write" );
- if ( !pGuard )
- {
- // MUST release read before acquiring write mutex or dead lock would
- // occur if there was another write waiting for this read to complete.
- { // own scope
- ::osl::MutexGuard aGuard( rMutex.pMutex );
- --rMutex.nReadCount;
- }
- pGuard = new ::osl::MutexGuard( rMutex.pWriteMutex );
- // wait for any other read to complete
-// TODO: set up a waiting thread instead of a loop
- sal_Bool bWait = TRUE;
- do
- {
- ::osl::MutexGuard aGuard( rMutex.pMutex );
- bWait = (rMutex.nReadCount != 0);
- } while ( bWait );
- }
-}
-
-
-// ====================================================================
-
#define LOCALEDATA_LIBRARYNAME "i18n"
#define LOCALEDATA_SERVICENAME "com.sun.star.i18n.LocaleData"
@@ -270,7 +186,7 @@ LocaleDataWrapper::~LocaleDataWrapper()
void LocaleDataWrapper::setLocale( const ::com::sun::star::lang::Locale& rLocale )
{
- LocaleDataWrapperGuard aGuard( aMutex, sal_True );
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nCriticalChange );
aLocale = rLocale;
invalidateData();
}
@@ -278,7 +194,7 @@ void LocaleDataWrapper::setLocale( const ::com::sun::star::lang::Locale& rLocale
const ::com::sun::star::lang::Locale& LocaleDataWrapper::getLocale() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
return aLocale;
}
@@ -613,7 +529,7 @@ void LocaleDataWrapper::invalidateData()
const String& LocaleDataWrapper::getOneLocaleItem( sal_Int16 nItem ) const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nItem >= LocaleItem::COUNT )
{
DBG_ERRORFILE( "getOneLocaleItem: bounds" );
@@ -709,7 +625,7 @@ void LocaleDataWrapper::getOneReservedWordImpl( sal_Int16 nWord )
const String& LocaleDataWrapper::getOneReservedWord( sal_Int16 nWord ) const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nWord < 0 || nWord >= reservedWords::COUNT )
{
DBG_ERRORFILE( "getOneReservedWord: bounds" );
@@ -738,7 +654,7 @@ MeasurementSystem LocaleDataWrapper::mapMeasurementStringToEnum( const String& r
const String& LocaleDataWrapper::getCurrSymbol() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( !aCurrSymbol.Len() )
{
aGuard.changeReadToWrite();
@@ -750,7 +666,7 @@ const String& LocaleDataWrapper::getCurrSymbol() const
const String& LocaleDataWrapper::getCurrBankSymbol() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( !aCurrBankSymbol.Len() )
{
aGuard.changeReadToWrite();
@@ -762,7 +678,7 @@ const String& LocaleDataWrapper::getCurrBankSymbol() const
USHORT LocaleDataWrapper::getCurrPositiveFormat() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nCurrPositiveFormat == nCurrFormatInvalid )
{
aGuard.changeReadToWrite();
@@ -774,7 +690,7 @@ USHORT LocaleDataWrapper::getCurrPositiveFormat() const
USHORT LocaleDataWrapper::getCurrNegativeFormat() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nCurrNegativeFormat == nCurrFormatInvalid )
{
aGuard.changeReadToWrite();
@@ -786,7 +702,7 @@ USHORT LocaleDataWrapper::getCurrNegativeFormat() const
USHORT LocaleDataWrapper::getCurrDigits() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nCurrDigits == nCurrFormatInvalid )
{
aGuard.changeReadToWrite();
@@ -1040,7 +956,7 @@ void LocaleDataWrapper::getCurrFormatsImpl()
DateFormat LocaleDataWrapper::getDateFormat() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nDateFormat == nDateFormatInvalid )
{
aGuard.changeReadToWrite();
@@ -1052,7 +968,7 @@ DateFormat LocaleDataWrapper::getDateFormat() const
DateFormat LocaleDataWrapper::getLongDateFormat() const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex );
if ( nLongDateFormat == nDateFormatInvalid )
{
aGuard.changeReadToWrite();
@@ -1426,6 +1342,7 @@ sal_Unicode* LocaleDataWrapper::ImplAddFormatNum( sal_Unicode* pBuf,
String LocaleDataWrapper::getDate( const Date& rDate ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
//!TODO: leading zeros et al
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
@@ -1472,6 +1389,7 @@ String LocaleDataWrapper::getDate( const Date& rDate ) const
String LocaleDataWrapper::getTime( const Time& rTime, BOOL bSec, BOOL b100Sec ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
//!TODO: leading zeros et al
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
@@ -1526,6 +1444,7 @@ String LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal,
sal_Int16 nDisplayDayOfWeek, sal_Bool bDayOfMonthWithLeadingZero,
sal_Int16 nDisplayMonth, sal_Bool bTwoDigitYear ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
using namespace ::com::sun::star::i18n;
sal_Unicode aBuf[20];
sal_Unicode* pBuf;
@@ -1580,6 +1499,7 @@ String LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal,
String LocaleDataWrapper::getDuration( const Time& rTime, BOOL bSec, BOOL b100Sec ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
sal_Unicode aBuf[128];
sal_Unicode* pBuf = aBuf;
@@ -1624,6 +1544,7 @@ inline long ImplGetNumberStringLengthGuess( const LocaleDataWrapper& rLoc, USHOR
String LocaleDataWrapper::getNum( long nNumber, USHORT nDecimals, BOOL bUseThousandSep ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
sal_Unicode aBuf[48]; // big enough for 64-bit long
// check if digits and separators will fit into fixed buffer or allocate
long nGuess = ImplGetNumberStringLengthGuess( *this, nDecimals );
@@ -1651,6 +1572,7 @@ String LocaleDataWrapper::getNum( long nNumber, USHORT nDecimals ) const
String LocaleDataWrapper::getCurr( long nNumber, USHORT nDecimals,
const String& rCurrencySymbol, BOOL bUseThousandSep ) const
{
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
sal_Unicode aBuf[75];
sal_Unicode aNumBuf[48]; // big enough for 64-bit long
sal_Unicode cZeroChar = getCurrZeroChar();
@@ -1861,7 +1783,7 @@ String LocaleDataWrapper::getCurr( long nNumber, USHORT nDecimals,
#ifndef PRODUCT
ByteString& LocaleDataWrapper::AppendLocaleInfo( ByteString& rDebugMsg ) const
{
- LocaleDataWrapperGuard aGuard( aMutex );
+ ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical );
rDebugMsg += '\n';
rDebugMsg += ByteString( String( aLocale.Language ), RTL_TEXTENCODING_UTF8 );
rDebugMsg += '_';