summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasiljevic <zv@archiware.com>2007-06-30 09:58:42 (GMT)
committervasiljevic <zv@archiware.com>2007-06-30 09:58:42 (GMT)
commit39f3fb41532e9e33414f8e35c50aad670e98d0e2 (patch)
treeb66748add6d35758197245900fecc91eb50d94fb
parent18e1cd3cc3f1062987089b2d89e4950fdf892f37 (diff)
downloadtcl-39f3fb41532e9e33414f8e35c50aad670e98d0e2.zip
tcl-39f3fb41532e9e33414f8e35c50aad670e98d0e2.tar.gz
tcl-39f3fb41532e9e33414f8e35c50aad670e98d0e2.tar.bz2
Prevent RemeberSyncObj() from growing the sync
object lists by reusing already free'd slots, if possible. See discussion on Bug 1726873 for more information.
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclThread.c17
2 files changed, 20 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 1282067..dcd80cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-30 Zoran Vasiljevic <vasiljevic@users.sourceforge.net>
+
+ * generic/tclThread.c: Prevent RemeberSyncObj() from growing the sync
+ object lists by reusing already free'd slots, if possible.
+ See discussion on Bug 1726873 for more information.
+
2007-06-29 Daniel Steffen <das@users.sourceforge.net>
* generic/tclAlloc.c: on Darwin, ensure memory allocated by
diff --git a/generic/tclThread.c b/generic/tclThread.c
index b0b2300..033d197 100644
--- a/generic/tclThread.c
+++ b/generic/tclThread.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclThread.c,v 1.6.2.1 2004/05/06 01:02:59 davygrvy Exp $
+ * RCS: @(#) $Id: tclThread.c,v 1.6.2.2 2007/06/30 09:58:43 vasiljevic Exp $
*/
#include "tclInt.h"
@@ -205,7 +205,17 @@ RememberSyncObject(objPtr, recPtr)
int i, j;
/*
- * Save the pointer to the allocated object so it can be finalized.
+ * Reuse any free slot in the list.
+ */
+
+ for (i=0 ; i < recPtr->num ; ++i) {
+ if (recPtr->list[i] == NULL) {
+ recPtr->list[i] = objPtr;
+ return;
+ }
+ }
+
+ /*
* Grow the list of pointers if necessary, copying only non-NULL
* pointers to the new list.
*/
@@ -213,7 +223,7 @@ RememberSyncObject(objPtr, recPtr)
if (recPtr->num >= recPtr->max) {
recPtr->max += 8;
newList = (char **)ckalloc(recPtr->max * sizeof(char *));
- for (i=0,j=0 ; i<recPtr->num ; i++) {
+ for (i=0, j=0 ; i < recPtr->num ; i++) {
if (recPtr->list[i] != NULL) {
newList[j++] = recPtr->list[i];
}
@@ -224,6 +234,7 @@ RememberSyncObject(objPtr, recPtr)
recPtr->list = newList;
recPtr->num = j;
}
+
recPtr->list[recPtr->num] = objPtr;
recPtr->num++;
}