diff options
author | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:21:26 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-01-10 22:21:26 (GMT) |
commit | dc9796c6e858828861b1339b4734bab19cccca4c (patch) | |
tree | 81cb2bbde61282f93461ce283eb461c4afef2e70 /generic/tclClockFmt.c | |
parent | 18be594c8481eee9b98d140af50df7ccb3a3a79e (diff) | |
download | tcl-dc9796c6e858828861b1339b4734bab19cccca4c.zip tcl-dc9796c6e858828861b1339b4734bab19cccca4c.tar.gz tcl-dc9796c6e858828861b1339b4734bab19cccca4c.tar.bz2 |
several initialize and finalize facilities
Diffstat (limited to 'generic/tclClockFmt.c')
-rw-r--r-- | generic/tclClockFmt.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c index 48b9b69..ad04e4b 100644 --- a/generic/tclClockFmt.c +++ b/generic/tclClockFmt.c @@ -31,6 +31,8 @@ TCL_DECLARE_MUTEX(ClockFmtMutex); /* Serializes access to common format list. */ static void ClockFmtScnStorageDelete(ClockFmtScnStorage *fss); +static void ClockFrmScnFinalize(ClientData clientData); + /* * Clock scan and format facilities. */ @@ -148,7 +150,7 @@ ClockFmtScnStorage_GC_Out(ClockFmtScnStorage *entry) */ static Tcl_HashTable FmtScnHashTable; -static int initFmtScnHashTable = 0; +static int initialized = 0; inline Tcl_HashEntry * HashEntry4FmtScn(ClockFmtScnStorage *fss) { @@ -246,16 +248,18 @@ FindOrCreateFmtScnStorage( Tcl_MutexLock(&ClockFmtMutex); /* if not yet initialized */ - if (!initFmtScnHashTable) { + if (!initialized) { /* initialize type */ memcpy(&ClockFmtScnStorageHashKeyType, &tclStringHashKeyType, sizeof(tclStringHashKeyType)); ClockFmtScnStorageHashKeyType.allocEntryProc = ClockFmtScnStorageAllocProc; ClockFmtScnStorageHashKeyType.freeEntryProc = ClockFmtScnStorageFreeProc; - initFmtScnHashTable = 1; /* initialize hash table */ Tcl_InitCustomHashTable(&FmtScnHashTable, TCL_CUSTOM_TYPE_KEYS, &ClockFmtScnStorageHashKeyType); + + initialized = 1; + Tcl_CreateExitHandler(ClockFrmScnFinalize, NULL); } /* get or create entry (and alocate storage) */ @@ -845,18 +849,30 @@ done: } +MODULE_SCOPE void +ClockFrmScnClearCaches(void) +{ + Tcl_MutexLock(&ClockFmtMutex); + /* clear caches ... */ + Tcl_MutexUnlock(&ClockFmtMutex); +} + static void -Tcl_GetClockFrmScnFinalize() +ClockFrmScnFinalize( + ClientData clientData) /* Not used. */ { + Tcl_MutexLock(&ClockFmtMutex); #if CLOCK_FMT_SCN_STORAGE_GC_SIZE > 0 /* clear GC */ ClockFmtScnStorage_GC.stackPtr = NULL; ClockFmtScnStorage_GC.stackBound = NULL; ClockFmtScnStorage_GC.count = 0; #endif - if (initFmtScnHashTable) { + if (initialized) { Tcl_DeleteHashTable(&FmtScnHashTable); + initialized = 0; } + Tcl_MutexUnlock(&ClockFmtMutex); Tcl_MutexFinalize(&ClockFmtMutex); } /* |