summaryrefslogtreecommitdiffstats
path: root/generic/tclThreadAlloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclThreadAlloc.c')
-rw-r--r--generic/tclThreadAlloc.c69
1 files changed, 47 insertions, 22 deletions
diff --git a/generic/tclThreadAlloc.c b/generic/tclThreadAlloc.c
index 2ee758e..8dfe014 100644
--- a/generic/tclThreadAlloc.c
+++ b/generic/tclThreadAlloc.c
@@ -13,7 +13,7 @@
*/
#include "tclInt.h"
-#if defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
+#if TCL_THREADS && defined(USE_THREAD_ALLOC)
/*
* If range checking is enabled, an additional byte will be allocated to store
@@ -196,20 +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();
- }
+ TclInitThreadAlloc();
}
Tcl_MutexUnlock(initLockPtr);
}
@@ -257,7 +248,7 @@ TclFreeAllocCache(
{
Cache *cachePtr = arg;
Cache **nextPtrPtr;
- register unsigned int bucket;
+ unsigned int bucket;
/*
* Flush blocks.
@@ -314,7 +305,7 @@ TclpAlloc(
{
Cache *cachePtr;
Block *blockPtr;
- register int bucket;
+ int bucket;
size_t size;
#ifndef __LP64__
@@ -546,8 +537,8 @@ TclpRealloc(
Tcl_Obj *
TclThreadAllocObj(void)
{
- register Cache *cachePtr;
- register Tcl_Obj *objPtr;
+ Cache *cachePtr;
+ Tcl_Obj *objPtr;
GETCACHE(cachePtr);
@@ -557,7 +548,7 @@ TclThreadAllocObj(void)
*/
if (cachePtr->numObjects == 0) {
- register int numMove;
+ int numMove;
Tcl_MutexLock(objLockPtr);
numMove = sharedPtr->numObjects;
@@ -718,7 +709,7 @@ MoveObjs(
Cache *toPtr,
int numMove)
{
- register Tcl_Obj *objPtr = fromPtr->firstObjPtr;
+ Tcl_Obj *objPtr = fromPtr->firstObjPtr;
Tcl_Obj *fromFirstObjPtr = objPtr;
toPtr->numObjects += numMove;
@@ -819,7 +810,7 @@ Block2Ptr(
int bucket,
unsigned int reqSize)
{
- register void *ptr;
+ void *ptr;
blockPtr->magicNum1 = blockPtr->magicNum2 = MAGIC;
blockPtr->sourceBucket = bucket;
@@ -835,7 +826,7 @@ static Block *
Ptr2Block(
char *ptr)
{
- register Block *blockPtr;
+ Block *blockPtr;
blockPtr = (((Block *) ptr) - 1);
if (blockPtr->magicNum1 != MAGIC || blockPtr->magicNum2 != MAGIC) {
@@ -969,8 +960,8 @@ GetBlocks(
Cache *cachePtr,
int bucket)
{
- register Block *blockPtr;
- register int n;
+ Block *blockPtr;
+ int n;
/*
* First, atttempt to move blocks from the shared cache. Note the
@@ -1015,7 +1006,7 @@ GetBlocks(
}
if (cachePtr->buckets[bucket].numFree == 0) {
- register size_t size;
+ size_t size;
/*
* If no blocks could be moved from shared, first look for a larger
@@ -1064,6 +1055,40 @@ GetBlocks(
}
return 1;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclInitThreadAlloc --
+ *
+ * Initializes the allocator cache-maintenance structures.
+ * It is done early and protected during the Tcl_InitSubsystems().
+ *
+ * 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();
+}
/*
*----------------------------------------------------------------------