summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authorwelch <welch>1999-10-30 00:27:22 (GMT)
committerwelch <welch>1999-10-30 00:27:22 (GMT)
commit7dc09492f052344474475f9d24403ce20d1022c2 (patch)
tree08944006c817cac120da14ce5cc9bfc7c41b2644 /generic/tclInt.h
parentb24019fd0f6c95e5f950963a0165b8d056eae67f (diff)
downloadtcl-7dc09492f052344474475f9d24403ce20d1022c2.zip
tcl-7dc09492f052344474475f9d24403ce20d1022c2.tar.gz
tcl-7dc09492f052344474475f9d24403ce20d1022c2.tar.bz2
Cleanup of the TclNewObj family of macros, and elimination of the
special Tcl_Obj memory allocator for the TCL_THREADS case, because this only adds lock contention.
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h91
1 files changed, 44 insertions, 47 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index b11e88b..6cf719b 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.35 1999/08/02 17:45:37 redman Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.36 1999/10/30 00:27:26 welch Exp $
*/
#ifndef _TCLINT
@@ -2025,14 +2025,33 @@ 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() \
- tclObjsAlloced++
+ Tcl_MutexLock(&tclCompStatsMutex); \
+ tclObjsAlloced++;
+ Tcl_MutexUnLock(&tclCompStatsMutex)
# define TclIncrObjsFreed() \
- tclObjsFreed++
+ Tcl_MutexLock(&tclCompStatsMutex); \
+ tclObjsFreed++; \
+ Tcl_MutexUnLock(&tclCompStatsMutex)
#else
# define TclIncrObjsAllocated()
# define TclIncrObjsFreed()
@@ -2040,47 +2059,40 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp,
#ifdef TCL_MEM_DEBUG
# define TclNewObj(objPtr) \
- (objPtr) = (Tcl_Obj *) \
- Tcl_DbCkalloc(sizeof(Tcl_Obj), __FILE__, __LINE__); \
+ TclDbNewObj(objPtr, __FILE__, __LINE__)
+
+# 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 TclDbNewObj(objPtr, file, line) \
- (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
+#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)); \
(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 /* not TCL_MEM_DEBUG */
+#else
-#ifdef TCL_THREADS
-extern Tcl_Mutex tclObjMutex;
-#endif
+/*
+ * Unthreaded case uses a special allocator.
+ */
# define TclNewObj(objPtr) \
- Tcl_MutexLock(&tclObjMutex); \
if (tclFreeObjList == NULL) { \
TclAllocateFreeObjects(); \
} \
@@ -2091,25 +2103,10 @@ extern Tcl_Mutex tclObjMutex;
(objPtr)->bytes = tclEmptyStringRep; \
(objPtr)->length = 0; \
(objPtr)->typePtr = NULL; \
- TclIncrObjsAllocated(); \
- Tcl_MutexUnlock(&tclObjMutex)
+ TclIncrObjsAllocated()
+
+#endif /* TCL_THREADS */
-# 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 */
/*