diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-04-01 11:56:42 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-04-01 11:56:42 (GMT) |
commit | 2efac8287052129530eb33f10f980d5d67854789 (patch) | |
tree | 079430858ed10ec1e08f8a39ece583e7ecff8c7d /win | |
parent | 77ccaefbb1482145de9b9276979318e88b9e542e (diff) | |
parent | df008ca3249de1390d881ced2ec3a0b95425d203 (diff) | |
download | tcl-2efac8287052129530eb33f10f980d5d67854789.zip tcl-2efac8287052129530eb33f10f980d5d67854789.tar.gz tcl-2efac8287052129530eb33f10f980d5d67854789.tar.bz2 |
Two micro-optimizations in Win and UNIX notifier. See: [http://code.activestate.com/lists/tcl-core/15645/]
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinNotify.c | 26 | ||||
-rw-r--r-- | win/tclWinThrd.c | 33 |
2 files changed, 33 insertions, 26 deletions
diff --git a/win/tclWinNotify.c b/win/tclWinNotify.c index ea4035b..1ad022d 100644 --- a/win/tclWinNotify.c +++ b/win/tclWinNotify.c @@ -51,7 +51,8 @@ static Tcl_ThreadDataKey dataKey; static int notifierCount = 0; static const TCHAR className[] = TEXT("TclNotifier"); -TCL_DECLARE_MUTEX(notifierMutex) +static int initialized = 0; +static CRITICAL_SECTION notifierMutex; /* * Static routines defined in this file. @@ -85,12 +86,19 @@ Tcl_InitNotifier(void) ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); WNDCLASS class; + TclpMasterLock(); + if (!initialized) { + initialized = 1; + InitializeCriticalSection(¬ifierMutex); + } + TclpMasterUnlock(); + /* * Register Notifier window class if this is the first thread to use * this module. */ - Tcl_MutexLock(¬ifierMutex); + EnterCriticalSection(¬ifierMutex); if (notifierCount == 0) { class.style = 0; class.cbClsExtra = 0; @@ -108,7 +116,7 @@ Tcl_InitNotifier(void) } } notifierCount++; - Tcl_MutexUnlock(¬ifierMutex); + LeaveCriticalSection(¬ifierMutex); tsdPtr->pending = 0; tsdPtr->timerActive = 0; @@ -183,12 +191,14 @@ Tcl_FinalizeNotifier( * notifier window class. */ - Tcl_MutexLock(¬ifierMutex); - notifierCount--; - if (notifierCount == 0) { - UnregisterClass(className, TclWinGetTclInstance()); + EnterCriticalSection(¬ifierMutex); + if (notifierCount) { + notifierCount--; + if (notifierCount == 0) { + UnregisterClass(className, TclWinGetTclInstance()); + } } - Tcl_MutexUnlock(¬ifierMutex); + LeaveCriticalSection(¬ifierMutex); } } 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 */ |