summaryrefslogtreecommitdiffstats
path: root/win/tclWinThrd.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-04-01 11:56:42 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-04-01 11:56:42 (GMT)
commitffcf42745c6b45037104720cdd15d5d7003fdb63 (patch)
tree079430858ed10ec1e08f8a39ece583e7ecff8c7d /win/tclWinThrd.c
parent40fd1928b84829f552e0764922b482dce9a17f0a (diff)
parent421817ca2cce688b0d7b9be9b54da8d1cbaf8013 (diff)
downloadtcl-ffcf42745c6b45037104720cdd15d5d7003fdb63.zip
tcl-ffcf42745c6b45037104720cdd15d5d7003fdb63.tar.gz
tcl-ffcf42745c6b45037104720cdd15d5d7003fdb63.tar.bz2
Two micro-optimizations in Win and UNIX notifier. See: [http://code.activestate.com/lists/tcl-core/15645/]
Diffstat (limited to 'win/tclWinThrd.c')
-rw-r--r--win/tclWinThrd.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index e44363b..4eb3573 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -119,7 +119,6 @@ typedef struct WinCondition {
*/
#ifdef USE_THREAD_ALLOC
-static int once;
static DWORD tlsKey;
typedef struct allocMutex {
@@ -968,24 +967,24 @@ TclpFreeAllocMutex(
free(lockPtr);
}
+void
+TclpInitAllocCache(void)
+{
+ /*
+ * We need to make sure that TclpFreeAllocCache is called on each
+ * thread that calls this, but only on threads that call this.
+ */
+
+ tlsKey = TlsAlloc();
+ if (tlsKey == TLS_OUT_OF_INDEXES) {
+ Tcl_Panic("could not allocate thread local storage");
+ }
+}
+
void *
TclpGetAllocCache(void)
{
void *result;
-
- if (!once) {
- /*
- * We need to make sure that TclpFreeAllocCache is called on each
- * thread that calls this, but only on threads that call this.
- */
-
- tlsKey = TlsAlloc();
- once = 1;
- if (tlsKey == TLS_OUT_OF_INDEXES) {
- Tcl_Panic("could not allocate thread local storage");
- }
- }
-
result = TlsGetValue(tlsKey);
if ((result == NULL) && (GetLastError() != NO_ERROR)) {
Tcl_Panic("TlsGetValue failed from TclpGetAllocCache");
@@ -1021,7 +1020,7 @@ TclpFreeAllocCache(
if (!success) {
Tcl_Panic("TlsSetValue failed from TclpFreeAllocCache");
}
- } else if (once) {
+ } else {
/*
* Called by us in TclFinalizeThreadAlloc() during the library
* finalization initiated from Tcl_Finalize()
@@ -1031,9 +1030,7 @@ TclpFreeAllocCache(
if (!success) {
Tcl_Panic("TlsFree failed from TclpFreeAllocCache");
}
- once = 0; /* reset for next time. */
}
-
}
#endif /* USE_THREAD_ALLOC */