ICU-770 More data cleanup

X-SVN-Rev: 5619
This commit is contained in:
George Rhoten 2001-08-30 02:59:19 +00:00
parent e48995b111
commit e3be3468c0
6 changed files with 150 additions and 72 deletions

View File

@ -17,9 +17,35 @@
#include "unicode/uclean.h"
#include "ucln_cmn.h"
#include "umutex.h"
#include "ucln.h"
static cleanupFunc *gCleanupFunctions[UCLN_COMMON] = {
NULL,
NULL,
NULL
};
U_CAPI void U_EXPORT2
ucln_registerCleanup(ECleanupLibraryType type,
cleanupFunc *func)
{
if (UCLN_START < type && type < UCLN_COMMON)
{
gCleanupFunctions[type] = func;
}
}
void u_cleanup(void)
{
ECleanupLibraryType libType = UCLN_START;
while (++libType < UCLN_COMMON)
{
if (gCleanupFunctions[libType])
{
gCleanupFunctions[libType]();
}
}
uloc_cleanup();
ustring_cleanup();
ucnv_cleanup();

View File

@ -19,16 +19,20 @@
#include "unicode/utypes.h"
U_CAPI UBool U_EXPORT2 ucnv_cleanup(void);
/* These are the cleanup functions for various APIs. */
U_CAPI UBool U_EXPORT2 ures_cleanup(void);
U_CFUNC UBool unorm_cleanup(void);
U_CAPI UBool U_EXPORT2 uloc_cleanup(void);
U_CFUNC UBool uloc_cleanup(void);
U_CAPI UBool U_EXPORT2 ustring_cleanup(void);
U_CFUNC UBool ustring_cleanup(void);
U_CAPI UBool U_EXPORT2 udata_cleanup(void);
U_CFUNC UBool ucnv_cleanup(void);
U_CAPI UBool U_EXPORT2 ucnv_io_cleanup(void);
U_CFUNC UBool ucnv_io_cleanup(void);
U_CFUNC UBool ures_cleanup(void);
U_CFUNC UBool udata_cleanup(void);
#endif

View File

@ -159,7 +159,7 @@ isAlias(const char *alias, UErrorCode *pErrorCode) {
}
}
U_CAPI UBool U_EXPORT2
UBool
ucnv_io_cleanup()
{
if (aliasData) {

View File

@ -676,7 +676,7 @@ static UHashtable *udata_getHashTable() {
}
umtx_unlock(NULL);
if U_FAILURE(err) {
if (U_FAILURE(err)) {
return NULL; /* TODO: handle this error better. */
}
return gHashTable;
@ -691,7 +691,7 @@ static UDataMemory *udata_findCachedData(const char *path)
DataCacheElement *el;
const char *baseName;
baseName = findBasename(path); // Cache remembers only the base name, not the full path.
baseName = findBasename(path); /* Cache remembers only the base name, not the full path. */
htable = udata_getHashTable();
umtx_lock(NULL);
el = (DataCacheElement *)uhash_get(htable, baseName);
@ -816,17 +816,15 @@ static void checkCommonData(UDataMemory *udm, UErrorCode *err) {
}
U_CAPI UBool U_EXPORT2
UBool
udata_cleanup()
{
umtx_lock(NULL);
if (gHashTable) { /* Delete the cache of user data mappings. */
uhash_close(gHashTable); /* Table owns the contents, and will delete them. */
gHashTable = 0; /* Cleanup is not thread safe. */
}
udata_close(&commonICUData); /* Clean up common ICU Data */
umtx_unlock(NULL);
return TRUE; /* Everything was cleaned up */
}

View File

@ -35,6 +35,7 @@
#include "ucmp32.h"
#include "umutex.h"
#include "uhash.h"
#include "ucln_in.h"
#ifdef UCOL_DEBUG
#include <stdio.h>
@ -51,6 +52,8 @@
#define ZERO_CC_LIMIT_ 0xC0
static UCollator* UCA = NULL;
static UDataMemory* UCA_DATA_MEM = NULL;
U_CDECL_BEGIN
static UBool U_CALLCONV
@ -809,42 +812,69 @@ UCollator* ucol_initCollator(const UCATableHeader *image, UCollator *fillIn, UEr
return result;
}
void ucol_initUCA(UErrorCode *status) {
if(U_FAILURE(*status)) return;
if(UCA == NULL) {
UCollator *newUCA = (UCollator *)uprv_malloc(sizeof(UCollator));
UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status);
if(U_FAILURE(*status)) {
udata_close(result);
uprv_free(newUCA);
U_CFUNC UBool
ucol_cleanup(void)
{
if (UCA_DATA_MEM) {
udata_close(UCA_DATA_MEM);
UCA_DATA_MEM = NULL;
}
if (UCA) {
/* Since UCA was opened with ucol_initCollator, ucol_close won't work. */
ucmpe32_close(UCA->mapping);
uprv_free(UCA);
UCA = NULL;
}
return TRUE;
}
if(result != NULL) { /* It looks like sometimes we can fail to find the data file */
newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), newUCA, status);
if(U_SUCCESS(*status)){
newUCA->rb = NULL;
umtx_lock(NULL);
if(UCA == NULL) {
UCA = newUCA;
newUCA = NULL;
void ucol_initUCA(UErrorCode *status) {
if(U_FAILURE(*status))
return;
if(UCA == NULL) {
UCollator *newUCA = (UCollator *)uprv_malloc(sizeof(UCollator));
if (newUCA == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
return;
}
umtx_unlock(NULL);
if(newUCA != NULL) {
udata_close(result);
UDataMemory *result = udata_openChoice(NULL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status);
if(U_FAILURE(*status)) {
if (result) {
udata_close(result);
}
uprv_free(newUCA);
}
}else{
udata_close(result);
uprv_free(newUCA);
UCA= NULL;
}
if(result != NULL) { /* It looks like sometimes we can fail to find the data file */
newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), newUCA, status);
if(U_SUCCESS(*status)){
newUCA->rb = NULL;
umtx_lock(NULL);
if(UCA == NULL) {
UCA = newUCA;
UCA_DATA_MEM = result;
result = NULL;
newUCA = NULL;
}
umtx_unlock(NULL);
if(newUCA != NULL) {
udata_close(result);
uprv_free(newUCA);
}
else {
i18n_registerCleanup();
}
}else{
udata_close(result);
uprv_free(newUCA);
UCA= NULL;
}
}
}
}
}
/* collIterNormalize Incremental Normalization happens here. */

View File

@ -18,8 +18,10 @@
*/
#include "ucol_bld.h"
#include "ucln_in.h"
static const InverseTableHeader* invUCA = NULL;
static UDataMemory* invUCA_DATA_MEM = NULL;
U_CDECL_BEGIN
static UBool U_CALLCONV
@ -1024,35 +1026,53 @@ UCATableHeader *ucol_assembleTailoringTable(UColTokenParser *src, UErrorCode *st
return myData;
}
const InverseTableHeader *ucol_initInverseUCA(UErrorCode *status) {
if(U_FAILURE(*status)) return NULL;
if(invUCA == NULL) {
InverseTableHeader *newInvUCA = NULL;
UDataMemory *result = udata_openChoice(NULL, INVC_DATA_TYPE, INVC_DATA_NAME, isAcceptableInvUCA, NULL, status);
if(U_FAILURE(*status)) {
udata_close(result);
uprv_free(newInvUCA);
}
if(result != NULL) { /* It looks like sometimes we can fail to find the data file */
newInvUCA = (InverseTableHeader *)udata_getMemory(result);
umtx_lock(NULL);
if(invUCA == NULL) {
invUCA = newInvUCA;
newInvUCA = NULL;
}
umtx_unlock(NULL);
if(newInvUCA != NULL) {
udata_close(result);
uprv_free(newInvUCA);
}
}
}
return invUCA;
UBool
ucol_bld_cleanup(void)
{
udata_close(invUCA_DATA_MEM);
invUCA_DATA_MEM = NULL;
invUCA = NULL;
return TRUE;
}
const InverseTableHeader *
ucol_initInverseUCA(UErrorCode *status)
{
if(U_FAILURE(*status)) return NULL;
if(invUCA == NULL) {
InverseTableHeader *newInvUCA = NULL;
UDataMemory *result = udata_openChoice(NULL, INVC_DATA_TYPE, INVC_DATA_NAME, isAcceptableInvUCA, NULL, status);
if(U_FAILURE(*status)) {
if (result) {
udata_close(result);
}
uprv_free(newInvUCA);
}
if(result != NULL) { /* It looks like sometimes we can fail to find the data file */
newInvUCA = (InverseTableHeader *)udata_getMemory(result);
umtx_lock(NULL);
if(invUCA == NULL) {
invUCA = newInvUCA;
invUCA_DATA_MEM = result;
result = NULL;
newInvUCA = NULL;
}
umtx_unlock(NULL);
if(newInvUCA != NULL) {
udata_close(result);
uprv_free(newInvUCA);
}
else {
i18n_registerCleanup();
}
}
}
return invUCA;
}