diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-01-13 14:43:07 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-01-13 14:43:07 (GMT) |
commit | 8c5fe95e9cc4b8115124f0cd9a936f68e7247db1 (patch) | |
tree | b83b1bb2c4dd8b6bf0965a5c29529fe3bf570762 /generic | |
parent | dcb024402d1a3c73cf744af89c99f82339dc215c (diff) | |
parent | f15743b10f46d799266a5df68f03a35a22885704 (diff) | |
download | tcl-8c5fe95e9cc4b8115124f0cd9a936f68e7247db1.zip tcl-8c5fe95e9cc4b8115124f0cd9a936f68e7247db1.tar.gz tcl-8c5fe95e9cc4b8115124f0cd9a936f68e7247db1.tar.bz2 |
Introduce new function TclInitThreadAlloc(), symmetric with TclFinalizeThreadAlloc()notifier
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclEvent.c | 3 | ||||
-rw-r--r-- | generic/tclInt.h | 1 | ||||
-rw-r--r-- | generic/tclThreadAlloc.c | 46 |
3 files changed, 39 insertions, 11 deletions
diff --git a/generic/tclEvent.c b/generic/tclEvent.c index b0b8188..436db7a 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -1043,6 +1043,9 @@ TclInitSubsystems(void) #if USE_TCLALLOC TclInitAlloc(); /* Process wide mutex init */ #endif +#if defined(TCL_THREADS) && defined(USE_THREAD_ALLOC) + TclInitThreadAlloc(); /* Setup thread allocator caches */ +#endif #ifdef TCL_MEM_DEBUG TclInitDbCkalloc(); /* Process wide mutex init */ #endif diff --git a/generic/tclInt.h b/generic/tclInt.h index dd0c11a..8516385 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2945,6 +2945,7 @@ MODULE_SCOPE void TclFinalizeNotifier(void); MODULE_SCOPE void TclFinalizeObjects(void); MODULE_SCOPE void TclFinalizePreserve(void); MODULE_SCOPE void TclFinalizeSynchronization(void); +MODULE_SCOPE void TclInitThreadAlloc(void); MODULE_SCOPE void TclFinalizeThreadAlloc(void); MODULE_SCOPE void TclFinalizeThreadAllocThread(void); MODULE_SCOPE void TclFinalizeThreadData(int quick); diff --git a/generic/tclThreadAlloc.c b/generic/tclThreadAlloc.c index fc281db..8077de4 100644 --- a/generic/tclThreadAlloc.c +++ b/generic/tclThreadAlloc.c @@ -196,21 +196,11 @@ GetCache(void) if (listLockPtr == NULL) { Tcl_Mutex *initLockPtr; - unsigned int i; initLockPtr = Tcl_GetAllocMutex(); Tcl_MutexLock(initLockPtr); if (listLockPtr == NULL) { - listLockPtr = TclpNewAllocMutex(); - objLockPtr = TclpNewAllocMutex(); - for (i = 0; i < NBUCKETS; ++i) { - bucketInfo[i].blockSize = MINALLOC << i; - bucketInfo[i].maxBlocks = 1 << (NBUCKETS - 1 - i); - bucketInfo[i].numMove = i < NBUCKETS - 1 ? - 1 << (NBUCKETS - 2 - i) : 1; - bucketInfo[i].lockPtr = TclpNewAllocMutex(); - } - TclpInitAllocCache(); + TclInitThreadAlloc(); } Tcl_MutexUnlock(initLockPtr); } @@ -1065,6 +1055,40 @@ GetBlocks( } return 1; } + +/* + *---------------------------------------------------------------------- + * + * TclInitThreadAlloc -- + * + * Initializes the allocator cache-maintenance structures. + * It is done early and protected during the TclInitSubsystems(). + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +void +TclInitThreadAlloc(void) +{ + unsigned int i; + + listLockPtr = TclpNewAllocMutex(); + objLockPtr = TclpNewAllocMutex(); + for (i = 0; i < NBUCKETS; ++i) { + bucketInfo[i].blockSize = MINALLOC << i; + bucketInfo[i].maxBlocks = 1 << (NBUCKETS - 1 - i); + bucketInfo[i].numMove = i < NBUCKETS - 1 ? + 1 << (NBUCKETS - 2 - i) : 1; + bucketInfo[i].lockPtr = TclpNewAllocMutex(); + } + TclpInitAllocCache(); +} /* *---------------------------------------------------------------------- |