ICU: Mark which functions are threadsafe and which ones aren't

Mark the thread-safe functions with the \threadsafe doc marker. This
includes public API, which should be thread-safe anyway.

The thread-unsafe functions are marked "\nonreentrant" already. In
addition, I renamed the functions that must be called with locked
mutexes to Unlocked, following the convention in other libraries like
libdbus-1.

Change-Id: Ibd93d1266149767f546c8e82959b73c138008469
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
bb10
Thiago Macieira 2012-08-03 11:40:35 +02:00 committed by Qt by Nokia
parent 0715e1e6c2
commit 4e542d958a
3 changed files with 20 additions and 14 deletions

View File

@ -52,8 +52,6 @@
QT_BEGIN_NAMESPACE
extern QMutex *qTextCodecsMutex();
static void qIcuCodecStateFree(QTextCodec::ConverterState *state)
{
ucnv_close(static_cast<UConverter *>(state->d));
@ -376,7 +374,7 @@ static QTextCodec *loadQtCodec(const char *name)
return 0;
}
/// \threadsafe
QList<QByteArray> QIcuCodec::availableCodecs()
{
QList<QByteArray> codecs;
@ -412,6 +410,7 @@ QList<QByteArray> QIcuCodec::availableCodecs()
return codecs;
}
/// \threadsafe
QList<int> QIcuCodec::availableMibs()
{
QList<int> mibs;
@ -424,7 +423,7 @@ QList<int> QIcuCodec::availableMibs()
return mibs;
}
QTextCodec *QIcuCodec::defaultCodec()
QTextCodec *QIcuCodec::defaultCodecUnlocked()
{
QCoreGlobalData *globalData = QCoreGlobalData::instance();
if (!globalData)
@ -438,13 +437,13 @@ QTextCodec *QIcuCodec::defaultCodec()
#else
const char *name = ucnv_getDefaultName();
#endif
c = codecForName(name);
c = codecForNameUnlocked(name);
globalData->codecForLocale.storeRelease(c);
return c;
}
QTextCodec *QIcuCodec::codecForName(const char *name)
QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name)
{
// backwards compatibility with Qt 4.x
if (!qstrcmp(name, "CP949"))
@ -525,11 +524,11 @@ QTextCodec *QIcuCodec::codecForName(const char *name)
}
QTextCodec *QIcuCodec::codecForMib(int mib)
QTextCodec *QIcuCodec::codecForMibUnlocked(int mib)
{
for (int i = 0; i < mibToNameSize; ++i) {
if (mibToName[i].mib == mib)
return codecForName(mibToNameTable + mibToName[i].index);
return codecForNameUnlocked(mibToNameTable + mibToName[i].index);
}
return 0;
}

View File

@ -67,10 +67,10 @@ public:
static QList<QByteArray> availableCodecs();
static QList<int> availableMibs();
static QTextCodec *defaultCodec();
static QTextCodec *defaultCodecUnlocked();
static QTextCodec *codecForName(const char *name);
static QTextCodec *codecForMib(int mib);
static QTextCodec *codecForNameUnlocked(const char *name);
static QTextCodec *codecForMibUnlocked(int mib);
QString convertToUnicode(const char *, int, ConverterState *) const;
QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;

View File

@ -146,6 +146,7 @@ static QTextCodec *checkForCodec(const QByteArray &name) {
static void setup();
// \threadsafe
// this returns the codec the method sets up as locale codec to
// avoid a race condition in codecForLocale() when
// setCodecForLocale(0) is called at the same time.
@ -495,6 +496,7 @@ QTextCodec::~QTextCodec()
*/
/*!
\threadsafe
Searches all installed QTextCodec objects and returns the one
which best matches \a name; the match is case-insensitive. Returns
0 if no codec matching the name \a name could be found.
@ -538,12 +540,13 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name)
return 0;
#else
return QIcuCodec::codecForName(name);
return QIcuCodec::codecForNameUnlocked(name);
#endif
}
/*!
\threadsafe
Returns the QTextCodec which matches the
\l{QTextCodec::mibEnum()}{MIBenum} \a mib.
*/
@ -578,13 +581,14 @@ QTextCodec* QTextCodec::codecForMib(int mib)
}
#ifdef QT_USE_ICU
return QIcuCodec::codecForMib(mib);
return QIcuCodec::codecForMibUnlocked(mib);
#endif
return 0;
}
/*!
\threadsafe
Returns the list of all available codecs, by name. Call
QTextCodec::codecForName() to obtain the QTextCodec for the name.
@ -616,6 +620,7 @@ QList<QByteArray> QTextCodec::availableCodecs()
}
/*!
\threadsafe
Returns the list of MIBs for all available codecs. Call
QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.
@ -659,6 +664,7 @@ void QTextCodec::setCodecForLocale(QTextCodec *c)
}
/*!
\threadsafe
Returns a pointer to the codec most suitable for this locale.
On Windows, the codec will be based on a system locale. On Unix
@ -677,8 +683,9 @@ QTextCodec* QTextCodec::codecForLocale()
QTextCodec *codec = globalData->codecForLocale.loadAcquire();
if (!codec) {
#ifdef QT_USE_ICU
codec = QIcuCodec::defaultCodec();
codec = QIcuCodec::defaultCodecUnlocked();
#else
// setupLocaleMapper locks as necessary
codec = setupLocaleMapper();
#endif
}