| ︙ | | |
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
|
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
|
-
|
int forceRelative);
MODULE_SCOPE int MakeTildeRelativePath(Tcl_Interp *interp, const char *user,
const char *subPath, Tcl_DString *dsPtr);
MODULE_SCOPE Tcl_Obj * TclGetHomeDirObj(Tcl_Interp *interp, const char *user);
MODULE_SCOPE Tcl_Obj * TclResolveTildePath(Tcl_Interp *interp,
Tcl_Obj *pathObj);
MODULE_SCOPE Tcl_Obj * TclResolveTildePathList(Tcl_Obj *pathsObj);
MODULE_SCOPE int TclJoinThread(Tcl_ThreadId id, int *result);
MODULE_SCOPE void TclLimitRemoveAllHandlers(Tcl_Interp *interp);
MODULE_SCOPE Tcl_Obj * TclLindexList(Tcl_Interp *interp,
Tcl_Obj *listPtr, Tcl_Obj *argPtr);
MODULE_SCOPE Tcl_Obj * TclLindexFlat(Tcl_Interp *interp, Tcl_Obj *listPtr,
Tcl_Size indexCount, Tcl_Obj *const indexArray[]);
/* TIP #280 */
MODULE_SCOPE void TclListLines(Tcl_Obj *listObj, Tcl_Size line, int n,
|
| ︙ | | |
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
|
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
|
-
-
|
Tcl_DString *linkPtr);
MODULE_SCOPE void TclpSetVariables(Tcl_Interp *interp);
MODULE_SCOPE void * TclThreadStorageKeyGet(Tcl_ThreadDataKey *keyPtr);
MODULE_SCOPE void TclThreadStorageKeySet(Tcl_ThreadDataKey *keyPtr,
void *data);
MODULE_SCOPE TCL_NORETURN void TclpThreadExit(int status);
MODULE_SCOPE void TclRememberCondition(Tcl_Condition *mutex);
MODULE_SCOPE void TclRememberJoinableThread(Tcl_ThreadId id);
MODULE_SCOPE void TclRememberMutex(Tcl_Mutex *mutex);
MODULE_SCOPE void TclRemoveScriptLimitCallbacks(Tcl_Interp *interp);
MODULE_SCOPE int TclReToGlob(Tcl_Interp *interp, const char *reStr,
Tcl_Size reStrLen, Tcl_DString *dsPtr, int *flagsPtr,
int *quantifiersFoundPtr);
MODULE_SCOPE Tcl_Size TclScanElement(const char *string, Tcl_Size length,
char *flagPtr);
MODULE_SCOPE void TclSetBgErrorHandler(Tcl_Interp *interp,
Tcl_Obj *cmdPrefix);
MODULE_SCOPE void TclSetBignumInternalRep(Tcl_Obj *objPtr,
void *bignumValue);
MODULE_SCOPE int TclSetBooleanFromAny(Tcl_Interp *interp,
Tcl_Obj *objPtr);
MODULE_SCOPE void TclSetCmdNameObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
Command *cmdPtr);
MODULE_SCOPE void TclSetDuplicateObj(Tcl_Obj *dupPtr, Tcl_Obj *objPtr);
MODULE_SCOPE void TclSetProcessGlobalValue(ProcessGlobalValue *pgvPtr,
Tcl_Obj *newValue, Tcl_Encoding encoding);
MODULE_SCOPE void TclSignalExitThread(Tcl_ThreadId id, int result);
MODULE_SCOPE void TclSpellFix(Tcl_Interp *interp,
Tcl_Obj *const *objv, Tcl_Size objc, Tcl_Size subIdx,
Tcl_Obj *bad, Tcl_Obj *fix);
MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr,
Tcl_Size numBytes);
typedef int (*memCmpFn_t)(const void*, const void*, size_t);
MODULE_SCOPE int TclStringCmp(Tcl_Obj *value1Ptr, Tcl_Obj *value2Ptr,
|
| ︙ | | |
| ︙ | | |
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
-
|
F96D45C408F272BC004A47F5 /* tclStubInit.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2508F272A7004A47F5 /* tclStubInit.c */; };
F96D45C508F272BC004A47F5 /* tclStubLib.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2608F272A7004A47F5 /* tclStubLib.c */; };
F96D45C608F272BC004A47F5 /* tclTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2708F272A7004A47F5 /* tclTest.c */; };
F96D45C708F272BC004A47F5 /* tclTestObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2808F272A7004A47F5 /* tclTestObj.c */; };
F96D45C808F272BC004A47F5 /* tclTestProcBodyObj.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2908F272A7004A47F5 /* tclTestProcBodyObj.c */; };
F96D45C908F272BC004A47F5 /* tclThread.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2A08F272A7004A47F5 /* tclThread.c */; };
F96D45CA08F272BC004A47F5 /* tclThreadAlloc.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */; };
F96D45CB08F272BC004A47F5 /* tclThreadJoin.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */; };
F96D45CC08F272BC004A47F5 /* tclThreadStorage.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */; };
F96D45CD08F272BC004A47F5 /* tclThreadTest.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2E08F272A7004A47F5 /* tclThreadTest.c */; };
F96D45CE08F272BC004A47F5 /* tclTimer.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F2F08F272A7004A47F5 /* tclTimer.c */; };
F96D45D008F272BC004A47F5 /* tclTomMathInterface.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */; };
F96D45D108F272BC004A47F5 /* tclTrace.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3208F272A7004A47F5 /* tclTrace.c */; };
F96D45D308F272BC004A47F5 /* tclUtf.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3408F272A7004A47F5 /* tclUtf.c */; };
F96D45D408F272BC004A47F5 /* tclUtil.c in Sources */ = {isa = PBXBuildFile; fileRef = F96D3F3508F272A7004A47F5 /* tclUtil.c */; };
|
| ︙ | | |
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
-
|
F96D3F2508F272A7004A47F5 /* tclStubInit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStubInit.c; sourceTree = "<group>"; };
F96D3F2608F272A7004A47F5 /* tclStubLib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclStubLib.c; sourceTree = "<group>"; };
F96D3F2708F272A7004A47F5 /* tclTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTest.c; sourceTree = "<group>"; };
F96D3F2808F272A7004A47F5 /* tclTestObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTestObj.c; sourceTree = "<group>"; };
F96D3F2908F272A7004A47F5 /* tclTestProcBodyObj.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTestProcBodyObj.c; sourceTree = "<group>"; };
F96D3F2A08F272A7004A47F5 /* tclThread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThread.c; sourceTree = "<group>"; };
F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadAlloc.c; sourceTree = "<group>"; };
F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadJoin.c; sourceTree = "<group>"; };
F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadStorage.c; sourceTree = "<group>"; };
F96D3F2E08F272A7004A47F5 /* tclThreadTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclThreadTest.c; sourceTree = "<group>"; };
F96D3F2F08F272A7004A47F5 /* tclTimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTimer.c; sourceTree = "<group>"; };
F96D3F3008F272A7004A47F5 /* tclTomMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tclTomMath.h; sourceTree = "<group>"; };
F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTomMathInterface.c; sourceTree = "<group>"; };
F96D3F3208F272A7004A47F5 /* tclTrace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclTrace.c; sourceTree = "<group>"; };
F96D3F3308F272A7004A47F5 /* tclUniData.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclUniData.c; sourceTree = "<group>"; };
|
| ︙ | | |
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
|
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
|
-
|
F96D3F2508F272A7004A47F5 /* tclStubInit.c */,
F96D3F2608F272A7004A47F5 /* tclStubLib.c */,
F96D3F2708F272A7004A47F5 /* tclTest.c */,
F96D3F2808F272A7004A47F5 /* tclTestObj.c */,
F96D3F2908F272A7004A47F5 /* tclTestProcBodyObj.c */,
F96D3F2A08F272A7004A47F5 /* tclThread.c */,
F96D3F2B08F272A7004A47F5 /* tclThreadAlloc.c */,
F96D3F2C08F272A7004A47F5 /* tclThreadJoin.c */,
F96D3F2D08F272A7004A47F5 /* tclThreadStorage.c */,
F96D3F2E08F272A7004A47F5 /* tclThreadTest.c */,
F96D3F2F08F272A7004A47F5 /* tclTimer.c */,
F9903CAF094FAADA004613E9 /* tclTomMath.decls */,
F96D3F3008F272A7004A47F5 /* tclTomMath.h */,
F9903CB0094FAADA004613E9 /* tclTomMathDecls.h */,
F96D3F3108F272A7004A47F5 /* tclTomMathInterface.c */,
|
| ︙ | | |
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
|
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
|
-
|
F96D45C408F272BC004A47F5 /* tclStubInit.c in Sources */,
F96D45C508F272BC004A47F5 /* tclStubLib.c in Sources */,
F96D45C608F272BC004A47F5 /* tclTest.c in Sources */,
F96D45C708F272BC004A47F5 /* tclTestObj.c in Sources */,
F96D45C808F272BC004A47F5 /* tclTestProcBodyObj.c in Sources */,
F96D45C908F272BC004A47F5 /* tclThread.c in Sources */,
F96D45CA08F272BC004A47F5 /* tclThreadAlloc.c in Sources */,
F96D45CB08F272BC004A47F5 /* tclThreadJoin.c in Sources */,
F96D45CC08F272BC004A47F5 /* tclThreadStorage.c in Sources */,
F96D45CD08F272BC004A47F5 /* tclThreadTest.c in Sources */,
F96D45CE08F272BC004A47F5 /* tclTimer.c in Sources */,
F96D45D008F272BC004A47F5 /* tclTomMathInterface.c in Sources */,
F96D45D108F272BC004A47F5 /* tclTrace.c in Sources */,
F96D45D308F272BC004A47F5 /* tclUtf.c in Sources */,
F96D45D408F272BC004A47F5 /* tclUtil.c in Sources */,
|
| ︙ | | |
| ︙ | | |
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#ifndef _MCW_EM
# define _MCW_EM 0x0008001F /* Error masks */
# define _MCW_RC 0x00000300 /* Rounding */
# define _MCW_PC 0x00030000 /* Precision */
_CRTIMP unsigned int __cdecl _controlfp (unsigned int unNew, unsigned int unMask);
#endif
static struct tclWinGlobals {
INIT_ONCE init_once; /* must be first member,
because of static initialziation */
/*
* This is the global lock used to serialize access to other serialization
* data structures.
*/
/*
* This is the global lock used to serialize access to other serialization
* data structures.
*/
static CRITICAL_SECTION globalLock;
CRITICAL_SECTION globalLock;
static int initialized = 0;
/*
* This is the global lock used to serialize initialization and finalization
* of Tcl as a whole.
*/
/*
* This is the global lock used to serialize initialization and finalization
* of Tcl as a whole.
*/
static CRITICAL_SECTION initLock;
CRITICAL_SECTION initLock;
/* holds the TLS key for the Tcl Thread_ID */
DWORD tls_thread_id;
/*
* allocLock is used by Tcl's version of malloc for synchronization. For
* obvious reasons, cannot use any dyamically allocated storage.
*/
/*
* allocLock is used by Tcl's version of malloc for synchronization. For
* obvious reasons, cannot use any dyamically allocated storage.
*/
#if TCL_THREADS
static struct Tcl_Mutex_ {
CRITICAL_SECTION crit;
} allocLock;
static Tcl_Mutex allocLockPtr = &allocLock;
struct Tcl_Mutex_ {
CRITICAL_SECTION crit;
} allocLock;
Tcl_Mutex allocLockPtr;
static int allocOnce = 0;
#endif /* TCL_THREADS */
/*
* The joinLock serializes Create- and ExitThread. This is necessary to
* prevent a race where a new joinable thread exits before the creating thread
* had the time to create the necessary data structures in the emulation
* layer.
*/
} TclWinGlobals = {
static CRITICAL_SECTION joinLock;
INIT_ONCE_STATIC_INIT
/*
* Condition variables are implemented with a combination of a per-thread
* Windows Event and a per-condition waiting queue. The idea is that each
* thread has its own Event that it waits on when it is doing a ConditionWait;
* it uses the same event for all condition variables because it only waits on
* one at a time. Each condition variable has a queue of waiting threads, and
* a mutex used to serialize access to this queue.
*
* Special thanks to David Nichols and Jim Davidson for advice on the
* Condition Variable implementation.
*/
};
/*
* The per-thread event and queue pointers.
*/
#if TCL_THREADS
typedef struct ThreadSpecificData {
HANDLE condEvent; /* Per-thread condition event */
struct ThreadSpecificData *nextPtr; /* Queue pointers */
struct ThreadSpecificData *prevPtr;
int flags; /* See flags below */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
#endif /* TCL_THREADS */
#if TCL_THREADS
/*
* State bits for the thread.
* WIN_THREAD_UNINIT Uninitialized. Must be zero because of the way
* ThreadSpecificData is created.
* WIN_THREAD_RUNNING Running, not waiting.
* WIN_THREAD_BLOCKED Waiting, or trying to wait.
*/
#define WIN_THREAD_UNINIT 0x0
#define WIN_THREAD_RUNNING 0x1
#define WIN_THREAD_BLOCKED 0x2
/*
* The per condition queue pointers and the Mutex used to serialize access to
* the queue.
*/
typedef struct {
typedef struct Tcl_Condition_ {
CRITICAL_SECTION condLock; /* Lock to serialize queuing on the
* condition. */
CONDITION_VARIABLE cv;
struct ThreadSpecificData *firstPtr; /* Queue pointers */
struct ThreadSpecificData *lastPtr;
} WinCondition;
/*
* Additions by AOL for specialized thread memory allocator.
*/
#endif /* TCL_THREADS */
#ifdef USE_THREAD_ALLOC
static DWORD tlsKey;
typedef struct {
Tcl_Mutex tlock;
CRITICAL_SECTION wlock;
} allocMutex;
#endif /* USE_THREAD_ALLOC */
/*
* The per thread data passed from TclpThreadCreate
* to TclWinThreadStart.
*/
typedef struct {
LPTHREAD_START_ROUTINE lpStartAddress; /* Original startup routine */
LPVOID lpParameter; /* Original startup data */
unsigned int fpControl; /* Floating point control word from the
* main thread */
HANDLE tHandle; /* used to wait on thread completion */
# if defined(_MSC_VER) || defined(__MSVCRT__)
unsigned
# else
DWORD
# endif
thread_id; /* initialized but unused,
possibly useful for debugging */
} WinThread;
/* assuming alignment constraints result in lsb being constant 0 */
# define TCL_WIN_THREAD_JOIN_FLAG ((size_t) 1 << 0)
# define TCL_WIN_THREAD_ID(PTR, JOINABLE)\
((Tcl_ThreadId) ((sizeof ((PTR) - (WinThread *) 0),\
(size_t) (PTR)) | ((JOINABLE)? TCL_WIN_THREAD_JOIN_FLAG: 0)))
# define TCL_WIN_THREAD_PTR(ID)\
((WinThread *) ((sizeof ((ID) == (Tcl_ThreadId) 0),\
(size_t) (ID) & ~TCL_WIN_THREAD_JOIN_FLAG)))
# define TCL_WIN_THREAD_JOINABLE(ID)\
(((sizeof ((ID) == (Tcl_ThreadId) 0),\
(size_t) (ID) & TCL_WIN_THREAD_JOIN_FLAG)))
/*
*----------------------------------------------------------------------
*
* TclWinFailure --
*
* Call this when an unexpected WIN32 error occurs
*
* Does not return
*
*----------------------------------------------------------------------
*/
void TCL_NORETURN WINAPI
TclWinFailure (
char const *const routine)
{
Tcl_Panic ("%s failed, last error = %#x\n", routine, GetLastError ());
}
/*
*----------------------------------------------------------------------
*
* TclWinThreadStart --
*
* This procedure is the entry point for all new threads created
|
| ︙ | | |
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
-
-
+
+
-
+
+
-
-
+
+
-
-
-
+
+
|
*/
static DWORD WINAPI
TclWinThreadStart(
LPVOID lpParameter) /* The WinThread structure pointer passed
* from TclpThreadCreate */
{
WinThread *winThreadPtr = (WinThread *) lpParameter;
LPTHREAD_START_ROUTINE lpOrigStartAddress;
WinThread *const winThreadPtr = (WinThread *) lpParameter;
static DWORD result;
LPVOID lpOrigParameter;
if (!winThreadPtr) {
return TCL_ERROR;
}
_controlfp(winThreadPtr->fpControl, _MCW_EM | _MCW_RC | 0x03000000 /* _MCW_DN */
#if !defined(_WIN64)
| _MCW_PC
#endif
);
if (!TlsSetValue (TclWinGlobals.tls_thread_id, winThreadPtr))
TclWinFailure ("TlsSetValue");
lpOrigStartAddress = winThreadPtr->lpStartAddress;
lpOrigParameter = winThreadPtr->lpParameter;
result = winThreadPtr->lpStartAddress (winThreadPtr->lpParameter);
if (!winThreadPtr->tHandle)
Tcl_Free(winThreadPtr);
return lpOrigStartAddress(lpOrigParameter);
TclpSysFree (winThreadPtr);
return result;
}
/*
*----------------------------------------------------------------------
*
* TclpThreadCreate --
*
|
| ︙ | | |
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
-
+
+
+
-
-
-
-
-
-
-
+
-
+
+
-
+
-
+
+
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
|
size_t stackSize, /* Size of stack for the new thread. */
int flags) /* Flags controlling behaviour of the new
* thread. */
{
WinThread *winThreadPtr; /* Per-thread startup info */
HANDLE tHandle;
winThreadPtr = (WinThread *)Tcl_Alloc(sizeof(WinThread));
winThreadPtr = (WinThread *) TclpSysAlloc (sizeof *winThreadPtr);
if (!winThreadPtr)
TclWinFailure ("memory allocation");
winThreadPtr->lpStartAddress = (LPTHREAD_START_ROUTINE) proc;
winThreadPtr->lpParameter = clientData;
winThreadPtr->fpControl = _controlfp(0, 0);
EnterCriticalSection(&joinLock);
*idPtr = 0; /* must initialize as Tcl_Thread is a pointer and
* on WIN64 sizeof void* != sizeof unsigned
*/
#if defined(_MSC_VER) || defined(__MSVCRT__)
tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize,
(Tcl_ThreadCreateProc*) TclWinThreadStart, winThreadPtr,
0, (unsigned *)idPtr);
0 /* flags */, &winThreadPtr->thread_id);
#else
tHandle = CreateThread(NULL, (DWORD) stackSize,
TclWinThreadStart, winThreadPtr, 0, (LPDWORD)idPtr);
TclWinThreadStart, winThreadPtr, 0 /* flags */,
&winThreadPtr->thread_id);
#endif
if (tHandle == NULL) {
if (!tHandle) {
LeaveCriticalSection(&joinLock);
TclpSysFree (winThreadPtr);
# if 1
TclWinFailure ("CreateThread");
# else
return TCL_ERROR;
# endif
} else {
if (flags & TCL_THREAD_JOINABLE) {
if (!(flags & TCL_THREAD_JOINABLE)) {
TclRememberJoinableThread(*idPtr);
}
/*
* The only purpose of this is to decrement the reference count so the
* OS resources will be reacquired when the thread closes.
*/
/*
* The only purpose of this is to decrement the reference count
* so the OS resources will be reacquired when the thread closes.
*/
if (!CloseHandle (tHandle))
TclWinFailure ("ClosseHandle");
/* note: the WIN32 OpenHandle() can be used to open a HANDLE
from the given threadID. However, if the thread
terminates with a HANDLE count of zero, the kernel may clean up
the thread, in particular its return status, immediately.
Hence, joining the thread requires keeping a HANDLE open
until the thread has been successfully joined. */
CloseHandle(tHandle);
LeaveCriticalSection(&joinLock);
tHandle = 0;
}
winThreadPtr->tHandle = tHandle;
*idPtr = TCL_WIN_THREAD_ID (winThreadPtr, 0 != tHandle);
return TCL_OK;
}
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | | |
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
|
int
Tcl_JoinThread(
Tcl_ThreadId threadId, /* Id of the thread to wait upon */
int *result) /* Reference to the storage the result of the
* thread we wait upon will be written into. */
{
if (!TCL_WIN_THREAD_JOINABLE (threadId))
return TCL_ERROR;
WinThread *winThreadPtr = TCL_WIN_THREAD_PTR (threadId);
HANDLE const tHandle = winThreadPtr->tHandle;
switch (WaitForSingleObject (tHandle, INFINITE)) {
DWORD exit_code;
default:
return TCL_ERROR;
case WAIT_FAILED:
TclWinFailure ("WaitForSingleObject");
case WAIT_OBJECT_0:
if (!GetExitCodeThread (tHandle, &exit_code))
TclWinFailure ("GetExitCodeThread");
*result = exit_code;
if (!CloseHandle (tHandle))
TclWinFailure ("CloseHandle");
TclpSysFree (winThreadPtr);
return TclJoinThread(threadId, result);
return TCL_OK;
}
}
/*
*----------------------------------------------------------------------
*
* TclpThreadExit --
*
|
| ︙ | | |
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
-
-
-
-
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
void
TclpThreadExit(
int status)
{
EnterCriticalSection(&joinLock);
TclSignalExitThread(Tcl_GetCurrentThread(), status);
LeaveCriticalSection(&joinLock);
WinThread *winThreadPtr;
if (winThreadPtr = (WinThread *) TlsGetValue (
TclWinGlobals.tls_thread_id)) {
if (!winThreadPtr->tHandle)
TclpSysFree (winThreadPtr);
}
#if defined(_MSC_VER) || defined(__MSVCRT__)
_endthreadex((unsigned) status);
#else
ExitThread((DWORD) status);
#endif
}
|
| ︙ | | |
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
*
*----------------------------------------------------------------------
*/
Tcl_ThreadId
Tcl_GetCurrentThread(void)
{
WinThread *winThreadPtr;
if (!(winThreadPtr = (WinThread *) TlsGetValue (
TclWinGlobals.tls_thread_id))) {
if (ERROR_SUCCESS != GetLastError ())
TclWinFailure ("TlsGetValue in Tcl_GetCurrentThread");
/* this is an initial thread */
/* can't use TclAlloc, as the USE_THREAD_ALLOC per-thread allocator
return (Tcl_ThreadId)INT2PTR(GetCurrentThreadId());
}
calls Tcl_GetCurrentThread() */
if (!(winThreadPtr = (WinThread *) TclpSysAlloc (sizeof *winThreadPtr)))
TclWinFailure ("memory allocation");
winThreadPtr->tHandle = 0;
winThreadPtr->thread_id = GetCurrentThreadId ();
if (!TlsSetValue (TclWinGlobals.tls_thread_id, winThreadPtr))
TclWinFailure ("TlsSetValue");
}
return TCL_WIN_THREAD_ID (winThreadPtr, 0 != winThreadPtr->tHandle);
}
/*
*----------------------------------------------------------------------
*
* TclWinInitOnce
*
* Perform module initialization exactly once
* storage keys.
*
* Results:
* None.
*
*
*----------------------------------------------------------------------
*/
static BOOL
TclWinInitOnce (
INIT_ONCE *init_once,
void *parameter,
void *context)
{
struct tclWinGlobals *const twg = parameter;
InitializeCriticalSection(&twg->initLock);
InitializeCriticalSection(&twg->globalLock);
twg->tls_thread_id = TlsAlloc ();
#if TCL_THREADS
InitializeCriticalSection(&twg->allocLock.crit);
twg->allocLockPtr = &twg->allocLock;
#endif /* TCL_THREADS */
return TRUE;
}
# define TCL_WIN_INITIALIZE_ONCE()\
InitOnceExecuteOnce (&TclWinGlobals.init_once,\
TclWinInitOnce,\
&TclWinGlobals,\
0)
/*
*----------------------------------------------------------------------
*
* TclpInitLock
*
* This procedure is used to grab a lock that serializes initialization
|
| ︙ | | |
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
|
*
*----------------------------------------------------------------------
*/
void
TclpInitLock(void)
{
if (!initialized) {
if (!TCL_WIN_INITIALIZE_ONCE ())
/*
* There is a fundamental race here that is solved by creating the
* first Tcl interpreter in a single threaded environment. Once the
* interpreter has been created, it is safe to create more threads
* that create interpreters in parallel.
*/
TclWinFailure ("InitOnceExecuteOnce");
initialized = 1;
InitializeCriticalSection(&joinLock);
InitializeCriticalSection(&initLock);
InitializeCriticalSection(&globalLock);
}
EnterCriticalSection(&initLock);
EnterCriticalSection(&TclWinGlobals.initLock);
}
/*
*----------------------------------------------------------------------
*
* TclpInitUnlock
*
|
| ︙ | | |
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
-
+
|
*
*----------------------------------------------------------------------
*/
void
TclpInitUnlock(void)
{
LeaveCriticalSection(&initLock);
LeaveCriticalSection(&TclWinGlobals.initLock);
}
/*
*----------------------------------------------------------------------
*
* TclpGlobalLock
*
|
| ︙ | | |
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
|
*
*----------------------------------------------------------------------
*/
void
TclpGlobalLock(void)
{
if (!initialized) {
if (!TCL_WIN_INITIALIZE_ONCE ())
/*
* There is a fundamental race here that is solved by creating the
* first Tcl interpreter in a single threaded environment. Once the
* interpreter has been created, it is safe to create more threads
* that create interpreters in parallel.
*/
TclWinFailure ("InitOnceExecuteOnce");
initialized = 1;
InitializeCriticalSection(&joinLock);
InitializeCriticalSection(&initLock);
InitializeCriticalSection(&globalLock);
}
EnterCriticalSection(&globalLock);
EnterCriticalSection(&TclWinGlobals.globalLock);
}
/*
*----------------------------------------------------------------------
*
* TclpGlobalUnlock
*
|
| ︙ | | |
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
-
+
|
*
*----------------------------------------------------------------------
*/
void
TclpGlobalUnlock(void)
{
LeaveCriticalSection(&globalLock);
LeaveCriticalSection(&TclWinGlobals.globalLock);
}
/*
*----------------------------------------------------------------------
*
* Tcl_GetAllocMutex
*
|
| ︙ | | |
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
-
+
-
-
+
-
-
+
|
*----------------------------------------------------------------------
*/
Tcl_Mutex *
Tcl_GetAllocMutex(void)
{
#if TCL_THREADS
if (!allocOnce) {
if (!TCL_WIN_INITIALIZE_ONCE ())
InitializeCriticalSection(&allocLock.crit);
allocOnce = 1;
TclWinFailure ("InitOnceExecuteOnce");
}
return &allocLockPtr;
return &TclWinGlobals.allocLockPtr;
#else
return NULL;
#endif
}
/*
*----------------------------------------------------------------------
|
| ︙ | | |
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
|
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
+
-
+
+
+
-
+
-
-
-
+
-
-
-
+
-
+
+
+
+
-
-
-
|
*
*----------------------------------------------------------------------
*/
void
TclFinalizeLock(void)
{
struct tclWinGlobals *const twg = &TclWinGlobals;
TclpGlobalLock();
DeleteCriticalSection(&joinLock);
if (!TlsFree (twg->tls_thread_id))
TclWinFailure ("TlsFree");
/*
* Destroy the critical section that we are holding!
*/
DeleteCriticalSection(&globalLock);
DeleteCriticalSection(&twg->globalLock);
initialized = 0;
#if TCL_THREADS
if (allocOnce) {
DeleteCriticalSection(&allocLock.crit);
DeleteCriticalSection(&twg->allocLock.crit);
allocOnce = 0;
}
#endif
LeaveCriticalSection(&initLock);
LeaveCriticalSection(&twg->initLock);
/*
* Destroy the critical section that we were holding.
*/
DeleteCriticalSection(&initLock);
DeleteCriticalSection(&twg->initLock);
InitOnceInitialize (&twg->init_once); /* assuming we want to
re-initialize at some point -- dubious */
}
#if TCL_THREADS
/* locally used prototype */
static void FinalizeConditionEvent(void *data);
/*
*----------------------------------------------------------------------
*
* Tcl_MutexLock --
*
* This procedure is invoked to lock a mutex. This is a self initializing
|
| ︙ | | |
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
-
+
+
-
-
-
+
+
+
-
-
+
|
*----------------------------------------------------------------------
*/
void
Tcl_MutexLock(
Tcl_Mutex *mutexPtr) /* The lock */
{
CRITICAL_SECTION *csPtr;
struct Tcl_Mutex_ *mp;
if (*mutexPtr == NULL) {
TclpGlobalLock();
/*
* Double inside global lock check to avoid a race.
* BROKEN: does work in relaxed memory models
*/
if (*mutexPtr == NULL) {
csPtr = (CRITICAL_SECTION *)Tcl_Alloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(csPtr);
*mutexPtr = (Tcl_Mutex)csPtr;
mp = Tcl_Alloc (sizeof *mp);
InitializeCriticalSection (&mp->crit);
*mutexPtr = mp;
TclRememberMutex(mutexPtr);
}
TclpGlobalUnlock();
}
csPtr = *((CRITICAL_SECTION **)mutexPtr);
EnterCriticalSection(csPtr);
EnterCriticalSection (&(*mutexPtr)->crit);
}
/*
*----------------------------------------------------------------------
*
* Tcl_MutexUnlock --
*
|
| ︙ | | |
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
-
-
-
+
|
*----------------------------------------------------------------------
*/
void
Tcl_MutexUnlock(
Tcl_Mutex *mutexPtr) /* The lock */
{
CRITICAL_SECTION *csPtr = *((CRITICAL_SECTION **)mutexPtr);
LeaveCriticalSection(csPtr);
LeaveCriticalSection (&(*mutexPtr)->crit);
}
/*
*----------------------------------------------------------------------
*
* TclpFinalizeMutex --
*
|
| ︙ | | |
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
|
-
-
+
-
-
-
+
+
|
*----------------------------------------------------------------------
*/
void
TclpFinalizeMutex(
Tcl_Mutex *mutexPtr)
{
CRITICAL_SECTION *csPtr = *(CRITICAL_SECTION **)mutexPtr;
if (*mutexPtr) {
if (csPtr != NULL) {
DeleteCriticalSection(csPtr);
Tcl_Free(csPtr);
DeleteCriticalSection(&(*mutexPtr)->crit);
Tcl_Free(*mutexPtr);
*mutexPtr = NULL;
}
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | | |
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
|
-
-
+
+
-
-
-
-
+
+
-
+
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
|
/*
*----------------------------------------------------------------------
*
* Tcl_ConditionNotify --
*
* This procedure is invoked to signal a condition variable.
*
* The mutex must be held during this call to avoid races, but this
* interface does not enforce that.
* The mutex does not need to be held during this call to avoid races
* and should not be, to minimize the number of context switches
*
* Results:
* None.
*
* Side effects:
* May unblock another thread.
*
*----------------------------------------------------------------------
*/
void
Tcl_ConditionNotify(
Tcl_Condition *condPtr)
{
WinCondition *winCondPtr;
ThreadSpecificData *tsdPtr;
if (*condPtr != NULL) {
/* double checked locking, i.e., BROKEN */
if (*condPtr == NULL) {
winCondPtr = *((WinCondition **)condPtr);
TclpGlobalLock();
if (winCondPtr == NULL) {
if (*condPtr == NULL) {
return;
}
WinCondition *winCondPtr;
/*
* Loop through all the threads waiting on the condition and notify
* them (i.e., broadcast semantics). The queue manipulation is guarded
* by the per-condition coordinating mutex.
*/
EnterCriticalSection(&winCondPtr->condLock);
winCondPtr = (WinCondition *)Tcl_Alloc(sizeof *winCondPtr);
InitializeConditionVariable (&winCondPtr->cv);
while (winCondPtr->firstPtr != NULL) {
tsdPtr = winCondPtr->firstPtr;
*condPtr = winCondPtr;
winCondPtr->firstPtr = tsdPtr->nextPtr;
if (winCondPtr->lastPtr == tsdPtr) {
winCondPtr->lastPtr = NULL;
}
}
tsdPtr->flags = WIN_THREAD_RUNNING;
tsdPtr->nextPtr = NULL;
tsdPtr->prevPtr = NULL; /* Not strictly necessary, see A: */
SetEvent(tsdPtr->condEvent);
}
LeaveCriticalSection(&winCondPtr->condLock);
} else {
/*
* No-one has used the condition variable, so there are no waiters.
*/
}
}
TclpGlobalUnlock();
/*
*----------------------------------------------------------------------
*
* FinalizeConditionEvent --
*
* This procedure is invoked to clean up the per-thread event used to
* implement condition waiting. This is only safe to call at the end of
* time.
*
* Results:
* None.
*
* Side effects:
* The per-thread event is closed.
*
*----------------------------------------------------------------------
*/
}
static void
FinalizeConditionEvent(
void *data)
{
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) data;
WakeAllConditionVariable (&(*condPtr)->cv);
tsdPtr->flags = WIN_THREAD_UNINIT;
CloseHandle(tsdPtr->condEvent);
}
/*
*----------------------------------------------------------------------
*
* TclpFinalizeCondition --
*
|
| ︙ | | |
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
|
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
|
-
+
-
+
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
void
TclpFinalizeCondition(
Tcl_Condition *condPtr)
{
WinCondition *winCondPtr = *(WinCondition **)condPtr;
WinCondition *winCondPtr = *condPtr;
/*
* Note - this is called long after the thread-local storage is reclaimed.
* The per-thread condition waiting event is reclaimed earlier in a
* per-thread exit handler, which is called before thread local storage is
* reclaimed.
*/
if (winCondPtr != NULL) {
DeleteCriticalSection(&winCondPtr->condLock);
Tcl_Free(winCondPtr);
*condPtr = NULL;
}
}
/*
* Additions by AOL for specialized thread memory allocator.
*/
#ifdef USE_THREAD_ALLOC
static DWORD tlsKey;
typedef struct {
Tcl_Mutex tlock;
CRITICAL_SECTION wlock;
} allocMutex;
Tcl_Mutex *
TclpNewAllocMutex(void)
{
allocMutex *lockPtr;
lockPtr = (allocMutex *)malloc(sizeof(allocMutex));
|
| ︙ | | |