1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
-
+
|
/*
* tclThreadAlloc.c --
*
* This is a very fast storage allocator for used with threads (designed
* avoid lock contention). The basic strategy is to allocate memory in
* fixed size blocks from block caches.
*
* The Initial Developer of the Original Code is America Online, Inc.
* Portions created by AOL are Copyright (C) 1999 America Online, Inc.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclThreadAlloc.c,v 1.6.2.15 2008/03/26 20:00:23 dgp Exp $
* RCS: @(#) $Id: tclThreadAlloc.c,v 1.6.2.16 2008/07/29 20:21:17 dgp Exp $
*/
#include "tclInt.h"
#if defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
/*
* If range checking is enabled, an additional byte will be allocated to store
|
| ︙ | | |
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
+
+
-
+
|
/*
* The following define the number of Tcl_Obj's to allocate/move at a time and
* the high water mark to prune a per-thread cache. On a 32 bit system,
* sizeof(Tcl_Obj) = 24 so 800 * 24 = ~16k.
*/
#define NOBJALLOC 800
/* Actual definition moved to tclInt.h */
#define NOBJHIGH 1200
#define NOBJHIGH ALLOC_NOBJHIGH
/*
* The following union stores accounting information for each block including
* two small magic numbers and a bucket number when in use or a next pointer
* when free. The original requested size (not including the Block overhead)
* is also maintained.
*/
|
| ︙ | | |
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
-
+
+
+
|
long numWaits; /* Number of waits to acquire a lock */
long numLocks; /* Number of locks acquired */
long totalAssigned; /* Total space assigned to bucket */
} Bucket;
/*
* The following structure defines a cache of buckets and objs, of which there
* will be (at most) one per thread.
* will be (at most) one per thread. Any changes need to be reflected in the
* struct AllocCache defined in tclInt.h, possibly also in the initialisation
* code in Tcl_CreateInterp().
*/
typedef struct Cache {
struct Cache *nextPtr; /* Linked list of cache entries */
Tcl_ThreadId owner; /* Which thread's cache is this? */
Tcl_Obj *firstObjPtr; /* List of free objects for thread */
int numObjects; /* Number of objects for thread */
|
| ︙ | | |
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
+
+
+
+
|
* Results:
* Pointer to uninitialized Tcl_Obj.
*
* Side effects:
* May move Tcl_Obj's from shared cached or allocate new Tcl_Obj's if
* list is empty.
*
* Note:
* If this code is updated, the changes need to be reflected in the
* macro TclAllocObjStorageEx() defined in tclInt.h
*
*----------------------------------------------------------------------
*/
Tcl_Obj *
TclThreadAllocObj(void)
{
register Cache *cachePtr = TclpGetAllocCache();
|
| ︙ | | |
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
+
+
+
+
|
*
* Results:
* None.
*
* Side effects:
* May move free Tcl_Obj's to shared list upon hitting high water mark.
*
* Note:
* If this code is updated, the changes need to be reflected in the
* macro TclAllocObjStorageEx() defined in tclInt.h
*
*----------------------------------------------------------------------
*/
void
TclThreadFreeObj(
Tcl_Obj *objPtr)
{
|
| ︙ | | |