619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
#ifdef TCL_THREADS
/*
* Additions by AOL for specialized thread memory allocator.
*/
#ifdef USE_THREAD_ALLOC
static volatile int initialized = 0;
static pthread_key_t key;
typedef struct {
Tcl_Mutex tlock;
pthread_mutex_t plock;
} allocMutex;
|
<
|
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
#ifdef TCL_THREADS
/*
* Additions by AOL for specialized thread memory allocator.
*/
#ifdef USE_THREAD_ALLOC
static pthread_key_t key;
typedef struct {
Tcl_Mutex tlock;
pthread_mutex_t plock;
} allocMutex;
|
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
allocMutex* lockPtr = (allocMutex*) mutex;
if (!lockPtr) {
return;
}
pthread_mutex_destroy(&lockPtr->plock);
free(lockPtr);
}
void
TclpFreeAllocCache(
void *ptr)
{
if (ptr != NULL) {
/*
* Called by the pthread lib when a thread exits
*/
TclFreeAllocCache(ptr);
pthread_setspecific(key, NULL);
} else if (initialized) {
/*
* Called by us in TclFinalizeThreadAlloc() during the library
* finalization initiated from Tcl_Finalize()
*/
pthread_key_delete(key);
initialized = 0;
}
}
void *
TclpGetAllocCache(void)
{
if (!initialized) {
pthread_mutex_lock(allocLockPtr);
if (!initialized) {
pthread_key_create(&key, TclpFreeAllocCache);
initialized = 1;
}
pthread_mutex_unlock(allocLockPtr);
}
return pthread_getspecific(key);
}
void
TclpSetAllocCache(
void *arg)
{
|
>
>
>
>
>
>
>
>
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
|
allocMutex* lockPtr = (allocMutex*) mutex;
if (!lockPtr) {
return;
}
pthread_mutex_destroy(&lockPtr->plock);
free(lockPtr);
}
void
TclpInitAllocCache(void)
{
pthread_mutex_lock(allocLockPtr);
pthread_key_create(&key, TclpFreeAllocCache);
pthread_mutex_unlock(allocLockPtr);
}
void
TclpFreeAllocCache(
void *ptr)
{
if (ptr != NULL) {
/*
* Called by the pthread lib when a thread exits
*/
TclFreeAllocCache(ptr);
pthread_setspecific(key, NULL);
} else {
pthread_key_delete(key);
}
}
void *
TclpGetAllocCache(void)
{
return pthread_getspecific(key);
}
void
TclpSetAllocCache(
void *arg)
{
|