diff options
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r-- | generic/tclInt.h | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h index 6cf719b..0be91e1 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.36 1999/10/30 00:27:26 welch Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.37 1999/11/10 02:51:56 hobbs Exp $ */ #ifndef _TCLINT @@ -2025,33 +2025,14 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp, * * EXTERN void TclNewObj _ANSI_ARGS_((Tcl_Obj *objPtr)); * EXTERN void TclDecrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr)); - * - * There are three variations on these routines for: - * TCL_MEM_DEBUG - * TCL_THREADS - * the normal case *---------------------------------------------------------------- */ -/* - * TclDecrRefCount is the same for all cases. The three cases - * are handled inside TclFreeObj. - */ - -#define TclDecrRefCount(objPtr) \ - if (--(objPtr)->refCount <= 0) { \ - TclFreeObj(objPtr); \ - } - #ifdef TCL_COMPILE_STATS # define TclIncrObjsAllocated() \ - Tcl_MutexLock(&tclCompStatsMutex); \ - tclObjsAlloced++; - Tcl_MutexUnLock(&tclCompStatsMutex) + tclObjsAlloced++ # define TclIncrObjsFreed() \ - Tcl_MutexLock(&tclCompStatsMutex); \ - tclObjsFreed++; \ - Tcl_MutexUnLock(&tclCompStatsMutex) + tclObjsFreed++ #else # define TclIncrObjsAllocated() # define TclIncrObjsFreed() @@ -2059,40 +2040,47 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp, #ifdef TCL_MEM_DEBUG # define TclNewObj(objPtr) \ - TclDbNewObj(objPtr, __FILE__, __LINE__) - -# define TclDbNewObj(objPtr, file, line) \ - (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \ + (objPtr) = (Tcl_Obj *) \ + Tcl_DbCkalloc(sizeof(Tcl_Obj), __FILE__, __LINE__); \ (objPtr)->refCount = 0; \ (objPtr)->bytes = tclEmptyStringRep; \ (objPtr)->length = 0; \ (objPtr)->typePtr = NULL; \ TclIncrObjsAllocated() -#else /* not TCL_MEM_DEBUG */ - -#ifdef TCL_THREADS - -/* - * The TclAllocateFreeObjects is a source of lock contention, - * so we just don't use it and rely on a good threaded memory allocator. - */ - -# define TclNewObj(objPtr) \ - (objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj)); \ +# define TclDbNewObj(objPtr, file, line) \ + (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \ (objPtr)->refCount = 0; \ (objPtr)->bytes = tclEmptyStringRep; \ (objPtr)->length = 0; \ (objPtr)->typePtr = NULL; \ TclIncrObjsAllocated() + +# define TclDecrRefCount(objPtr) \ + if (--(objPtr)->refCount <= 0) { \ + if ((objPtr)->refCount < -1) \ + panic("Reference count for %lx was negative: %s line %d", \ + (objPtr), __FILE__, __LINE__); \ + if (((objPtr)->bytes != NULL) \ + && ((objPtr)->bytes != tclEmptyStringRep)) { \ + ckfree((char *) (objPtr)->bytes); \ + } \ + if (((objPtr)->typePtr != NULL) \ + && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \ + (objPtr)->typePtr->freeIntRepProc(objPtr); \ + } \ + ckfree((char *) (objPtr)); \ + TclIncrObjsFreed(); \ + } -#else +#else /* not TCL_MEM_DEBUG */ -/* - * Unthreaded case uses a special allocator. - */ +#ifdef TCL_THREADS +extern Tcl_Mutex tclObjMutex; +#endif # define TclNewObj(objPtr) \ + Tcl_MutexLock(&tclObjMutex); \ if (tclFreeObjList == NULL) { \ TclAllocateFreeObjects(); \ } \ @@ -2103,10 +2091,25 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp, (objPtr)->bytes = tclEmptyStringRep; \ (objPtr)->length = 0; \ (objPtr)->typePtr = NULL; \ - TclIncrObjsAllocated() - -#endif /* TCL_THREADS */ + TclIncrObjsAllocated(); \ + Tcl_MutexUnlock(&tclObjMutex) +# define TclDecrRefCount(objPtr) \ + if (--(objPtr)->refCount <= 0) { \ + if (((objPtr)->bytes != NULL) \ + && ((objPtr)->bytes != tclEmptyStringRep)) { \ + ckfree((char *) (objPtr)->bytes); \ + } \ + if (((objPtr)->typePtr != NULL) \ + && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \ + (objPtr)->typePtr->freeIntRepProc(objPtr); \ + } \ + Tcl_MutexLock(&tclObjMutex); \ + (objPtr)->internalRep.otherValuePtr = (VOID *) tclFreeObjList; \ + tclFreeObjList = (objPtr); \ + TclIncrObjsFreed(); \ + Tcl_MutexUnlock(&tclObjMutex); \ + } #endif /* TCL_MEM_DEBUG */ /* |