1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/*
* tclWinThread.c --
*
* This file implements the Windows-specific thread operations.
*
* Copyright (c) 1998 by Sun Microsystems, Inc.
* Copyright (c) 1999 by Scriptics Corporation
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclWinThrd.c,v 1.18 2001/09/07 18:57:20 mdejong Exp $
*/
#include "tclWinInt.h"
#include <fcntl.h>
#include <io.h>
#include <sys/stat.h>
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/*
* tclWinThread.c --
*
* This file implements the Windows-specific thread operations.
*
* Copyright (c) 1998 by Sun Microsystems, Inc.
* Copyright (c) 1999 by Scriptics Corporation
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclWinThrd.c,v 1.19 2002/04/23 17:03:35 hobbs Exp $
*/
#include "tclWinInt.h"
#include <fcntl.h>
#include <io.h>
#include <sys/stat.h>
|
| ︙ | | | ︙ | |
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
*----------------------------------------------------------------------
*/
Tcl_Mutex *
Tcl_GetAllocMutex()
{
#ifdef TCL_THREADS
InitializeCriticalSection(&allocLock);
return &allocLockPtr;
#else
return NULL;
#endif
}
|
>
>
>
|
>
>
|
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
*----------------------------------------------------------------------
*/
Tcl_Mutex *
Tcl_GetAllocMutex()
{
#ifdef TCL_THREADS
static int once = 0;
if (!once) {
InitializeCriticalSection(&allocLock);
once = 1;
}
return &allocLockPtr;
#else
return NULL;
#endif
}
|
| ︙ | | | ︙ | |
624
625
626
627
628
629
630
631
632
633
634
635
636
637
|
void
TclpFinalizeThreadData(keyPtr)
Tcl_ThreadDataKey *keyPtr;
{
VOID *result;
DWORD *indexPtr;
if (*keyPtr != NULL) {
indexPtr = *(DWORD **)keyPtr;
result = (VOID *)TlsGetValue(*indexPtr);
if (result != NULL) {
ckfree((char *)result);
TlsSetValue(*indexPtr, (void *)NULL);
|
>
>
>
>
>
>
>
>
|
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
void
TclpFinalizeThreadData(keyPtr)
Tcl_ThreadDataKey *keyPtr;
{
VOID *result;
DWORD *indexPtr;
#ifdef USE_THREAD_ALLOC
static int once = 0;
if (!once) {
once = 1;
TclWinFreeAllocCache();
}
#endif
if (*keyPtr != NULL) {
indexPtr = *(DWORD **)keyPtr;
result = (VOID *)TlsGetValue(*indexPtr);
if (result != NULL) {
ckfree((char *)result);
TlsSetValue(*indexPtr, (void *)NULL);
|
| ︙ | | | ︙ | |
966
967
968
969
970
971
972
973
|
if (winCondPtr != NULL) {
DeleteCriticalSection(&winCondPtr->condLock);
ckfree((char *)winCondPtr);
*condPtr = NULL;
}
}
#endif /* TCL_THREADS */
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
if (winCondPtr != NULL) {
DeleteCriticalSection(&winCondPtr->condLock);
ckfree((char *)winCondPtr);
*condPtr = NULL;
}
}
/*
* Additions by AOL for specialized thread memory allocator.
*/
#ifdef USE_THREAD_ALLOC
static DWORD key;
Tcl_Mutex *
TclpNewAllocMutex(void)
{
struct lock {
Tcl_Mutex tlock;
CRITICAL_SECTION wlock;
} *lockPtr;
lockPtr = malloc(sizeof(struct lock));
if (lockPtr == NULL) {
panic("could not allocate lock");
}
lockPtr->tlock = (Tcl_Mutex) &lockPtr->wlock;
InitializeCriticalSection(&lockPtr->wlock);
return &lockPtr->tlock;
}
void *
TclpGetAllocCache(void)
{
static int once = 0;
if (!once) {
/*
* We need to make sure that TclWinFreeAllocCache is called
* on each thread that calls this, but only on threads that
* call this.
*/
key = TlsAlloc();
once = 1;
if (key == TLS_OUT_OF_INDEXES) {
panic("could not allocate thread local storage");
}
}
return TlsGetValue(key);
}
void
TclpSetAllocCache(void *ptr)
{
TlsSetValue(key, ptr);
}
void
TclWinFreeAllocCache(void)
{
void *ptr;
ptr = TlsGetValue(key);
TlsSetValue(key, NULL);
TclFreeAllocCache(ptr);
}
#endif /* USE_THREAD_ALLOC */
#endif /* TCL_THREADS */
|