diff options
Diffstat (limited to 'generic/tclThread.c')
| -rw-r--r-- | generic/tclThread.c | 125 |
1 files changed, 66 insertions, 59 deletions
diff --git a/generic/tclThread.c b/generic/tclThread.c index de9fac9..d3cf4ba 100644 --- a/generic/tclThread.c +++ b/generic/tclThread.c @@ -4,8 +4,7 @@ * This file implements Platform independent thread operations. Most of * the real work is done in the platform dependent files. * - * Copyright © 1998 Sun Microsystems, Inc. - * Copyright © 2008 George Peter Staplin + * Copyright (c) 1998 by Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -41,6 +40,21 @@ static void RememberSyncObject(void *objPtr, SyncObjRecord *recPtr); /* + * Several functions are #defined to nothing in tcl.h if TCL_THREADS is not + * specified. Here we undo that so the functions are defined in the stubs + * table. + */ + +#ifndef TCL_THREADS +#undef Tcl_MutexLock +#undef Tcl_MutexUnlock +#undef Tcl_MutexFinalize +#undef Tcl_ConditionNotify +#undef Tcl_ConditionWait +#undef Tcl_ConditionFinalize +#endif + +/* *---------------------------------------------------------------------- * * Tcl_GetThreadData -- @@ -64,27 +78,25 @@ Tcl_GetThreadData( int size) /* Size of storage block */ { void *result; -#if TCL_THREADS +#ifdef TCL_THREADS /* * Initialize the key for this thread. */ - - result = TclThreadStorageKeyGet(keyPtr); + result = TclpThreadDataKeyGet(keyPtr); if (result == NULL) { - result = ckalloc(size); - memset(result, 0, size); - TclThreadStorageKeySet(keyPtr, result); + result = ckalloc((size_t) size); + memset(result, 0, (size_t) size); + TclpThreadDataKeySet(keyPtr, result); } #else /* TCL_THREADS */ if (*keyPtr == NULL) { - result = ckalloc(size); - memset(result, 0, size); + result = ckalloc((size_t) size); + memset(result, 0, (size_t) size); *keyPtr = (Tcl_ThreadDataKey)result; RememberSyncObject(keyPtr, &keyRecord); - } else { - result = *keyPtr; } + result = * (void **) keyPtr; #endif /* TCL_THREADS */ return result; } @@ -108,15 +120,17 @@ Tcl_GetThreadData( void * TclThreadDataKeyGet( - Tcl_ThreadDataKey *keyPtr) /* Identifier for the data chunk. */ - + Tcl_ThreadDataKey *keyPtr) /* Identifier for the data chunk, really + * (pthread_key_t **) */ { -#if TCL_THREADS - return TclThreadStorageKeyGet(keyPtr); +#ifdef TCL_THREADS + return TclpThreadDataKeyGet(keyPtr); #else /* TCL_THREADS */ - return *keyPtr; + char *result = *(char **) keyPtr; + return result; #endif /* TCL_THREADS */ } + /* *---------------------------------------------------------------------- @@ -126,7 +140,7 @@ TclThreadDataKeyGet( * Keep a list of (mutexes/condition variable/data key) used during * finalization. * - * Assume global lock is held. + * Assume master lock is held. * * Results: * None. @@ -164,14 +178,14 @@ RememberSyncObject( if (recPtr->num >= recPtr->max) { recPtr->max += 8; - newList = (void **)ckalloc(recPtr->max * sizeof(void *)); + newList = (void **) ckalloc(recPtr->max * sizeof(char *)); for (i=0,j=0 ; i<recPtr->num ; i++) { if (recPtr->list[i] != NULL) { newList[j++] = recPtr->list[i]; } } if (recPtr->list != NULL) { - ckfree(recPtr->list); + ckfree((char *) recPtr->list); } recPtr->list = newList; recPtr->num = j; @@ -187,7 +201,7 @@ RememberSyncObject( * ForgetSyncObject * * Remove a single object from the list. - * Assume global lock is held. + * Assume master lock is held. * * Results: * None. @@ -219,7 +233,7 @@ ForgetSyncObject( * TclRememberMutex * * Keep a list of mutexes used during finalization. - * Assume global lock is held. + * Assume master lock is held. * * Results: * None. @@ -254,17 +268,16 @@ TclRememberMutex( *---------------------------------------------------------------------- */ -#undef Tcl_MutexFinalize void Tcl_MutexFinalize( Tcl_Mutex *mutexPtr) { -#if TCL_THREADS +#ifdef TCL_THREADS TclpFinalizeMutex(mutexPtr); #endif - TclpGlobalLock(); + TclpMasterLock(); ForgetSyncObject(mutexPtr, &mutexRecord); - TclpGlobalUnlock(); + TclpMasterUnlock(); } /* @@ -273,7 +286,7 @@ Tcl_MutexFinalize( * TclRememberCondition * * Keep a list of condition variables used during finalization. - * Assume global lock is held. + * Assume master lock is held. * * Results: * None. @@ -308,17 +321,16 @@ TclRememberCondition( *---------------------------------------------------------------------- */ -#undef Tcl_ConditionFinalize void Tcl_ConditionFinalize( Tcl_Condition *condPtr) { -#if TCL_THREADS +#ifdef TCL_THREADS TclpFinalizeCondition(condPtr); #endif - TclpGlobalLock(); + TclpMasterLock(); ForgetSyncObject(condPtr, &condRecord); - TclpGlobalUnlock(); + TclpMasterUnlock(); } /* @@ -340,18 +352,11 @@ Tcl_ConditionFinalize( */ void -TclFinalizeThreadData(int quick) +TclFinalizeThreadData(void) { - TclFinalizeThreadDataThread(); -#if TCL_THREADS && defined(USE_THREAD_ALLOC) - if (!quick) { - /* - * Quick exit principle makes it useless to terminate allocators - */ - TclFinalizeThreadAllocThread(); - } -#else - (void)quick; + TclpFinalizeThreadDataThread(); +#if defined(TCL_THREADS) && defined(USE_THREAD_ALLOC) + TclFinalizeThreadAllocThread(); #endif } @@ -378,11 +383,11 @@ TclFinalizeSynchronization(void) int i; void *blockPtr; Tcl_ThreadDataKey *keyPtr; -#if TCL_THREADS +#ifdef TCL_THREADS Tcl_Mutex *mutexPtr; Tcl_Condition *condPtr; - TclpGlobalLock(); + TclpMasterLock(); #endif /* @@ -393,18 +398,18 @@ TclFinalizeSynchronization(void) if (keyRecord.list != NULL) { for (i=0 ; i<keyRecord.num ; i++) { keyPtr = (Tcl_ThreadDataKey *) keyRecord.list[i]; - blockPtr = *keyPtr; + blockPtr = (void *) *keyPtr; ckfree(blockPtr); } - ckfree(keyRecord.list); + ckfree((char *) keyRecord.list); keyRecord.list = NULL; } keyRecord.max = 0; keyRecord.num = 0; - -#if TCL_THREADS + +#ifdef TCL_THREADS /* - * Call thread storage global cleanup. + * Call thread storage master cleanup. */ TclFinalizeThreadStorage(); @@ -416,7 +421,7 @@ TclFinalizeSynchronization(void) } } if (mutexRecord.list != NULL) { - ckfree(mutexRecord.list); + ckfree((char *) mutexRecord.list); mutexRecord.list = NULL; } mutexRecord.max = 0; @@ -429,13 +434,13 @@ TclFinalizeSynchronization(void) } } if (condRecord.list != NULL) { - ckfree(condRecord.list); + ckfree((char *) condRecord.list); condRecord.list = NULL; } condRecord.max = 0; condRecord.num = 0; - TclpGlobalUnlock(); + TclpMasterUnlock(); #endif /* TCL_THREADS */ } @@ -462,10 +467,12 @@ Tcl_ExitThread( int status) { Tcl_FinalizeThread(); +#ifdef TCL_THREADS TclpThreadExit(status); +#endif } -#if !TCL_THREADS +#ifndef TCL_THREADS /* *---------------------------------------------------------------------- @@ -488,30 +495,30 @@ Tcl_ExitThread( #undef Tcl_ConditionWait void Tcl_ConditionWait( - TCL_UNUSED(Tcl_Condition *), /* Really (pthread_cond_t **) */ - TCL_UNUSED(Tcl_Mutex *), /* Really (pthread_mutex_t **) */ - TCL_UNUSED(const Tcl_Time *)) /* Timeout on waiting period */ + Tcl_Condition *condPtr, /* Really (pthread_cond_t **) */ + Tcl_Mutex *mutexPtr, /* Really (pthread_mutex_t **) */ + Tcl_Time *timePtr) /* Timeout on waiting period */ { } #undef Tcl_ConditionNotify void Tcl_ConditionNotify( - TCL_UNUSED(Tcl_Condition *)) + Tcl_Condition *condPtr) { } #undef Tcl_MutexLock void Tcl_MutexLock( - TCL_UNUSED(Tcl_Mutex *)) + Tcl_Mutex *mutexPtr) { } #undef Tcl_MutexUnlock void Tcl_MutexUnlock( - TCL_UNUSED(Tcl_Mutex *)) + Tcl_Mutex *mutexPtr) { } #endif /* !TCL_THREADS */ |
