summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorgriffin <briang42@easystreet.net>2022-08-25 20:39:33 (GMT)
committergriffin <briang42@easystreet.net>2022-08-25 20:39:33 (GMT)
commitaddfa7b662b1382b33181c3c2f1dc945e42da4e1 (patch)
treeff6e7a2658454c85084fef52b9554a75a6ea8e42 /win
parent85da0b0875d23f8af54cef159f7878f8bc3d30f3 (diff)
parent8d919c0d03dbc5bdd562607697b0aed8be34c600 (diff)
downloadtcl-addfa7b662b1382b33181c3c2f1dc945e42da4e1.zip
tcl-addfa7b662b1382b33181c3c2f1dc945e42da4e1.tar.gz
tcl-addfa7b662b1382b33181c3c2f1dc945e42da4e1.tar.bz2
sync up with core-8-branch
Diffstat (limited to 'win')
-rw-r--r--win/tclWinConsole.c90
-rw-r--r--win/tclooConfig.sh2
2 files changed, 56 insertions, 36 deletions
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c
index 23652de..753a572 100644
--- a/win/tclWinConsole.c
+++ b/win/tclWinConsole.c
@@ -19,8 +19,8 @@
#include <ctype.h>
/*
- * A general note on the design: The console channel driver differs from most
- * other drivers in the following respects:
+ * A general note on the design: The console channel driver differs from
+ * most other drivers in the following respects:
*
* - There can be at most 3 console handles at any time since Windows does
* support allocation of more than one console (with three handles
@@ -35,9 +35,10 @@
* std* channels are shared amongst threads which means there can be
* multiple Tcl channels corresponding to a single console handle.
*
- * - Even with multiple threads, more than one file event handler is unlikely.
- * It does not make sense for multiple threads to register handlers for
- * stdin because the input would be randomly fragmented amongst the threads.
+ * - Even with multiple threads, more than one file event handler is
+ * unlikely. It does not make sense for multiple threads to register
+ * handlers for stdin because the input would be randomly fragmented amongst
+ * the threads.
*
* Various design factors are driven by the above, e.g. use of lists instead
* of hash tables (at most 3 console handles) and use of global instead of
@@ -55,9 +56,9 @@
* because an interpreter may (for example) turn off echo for passwords and
* the read ahead would come in the way of that.
*
- * If multiple threads are reading from stdin, the input is sprayed in random
- * fashion. This is not good application design and hence no plan to address
- * this (not clear what should be done even in theory)
+ * If multiple threads are reading from stdin, the input is sprayed in
+ * random fashion. This is not good application design and hence no plan to
+ * address this (not clear what should be done even in theory)
*
* For output, we do not restrict all output to the console writer threads.
* See ConsoleOutputProc for the conditions.
@@ -152,7 +153,7 @@ typedef struct ConsoleHandleInfo {
* only from the thread owning channel EXCEPT when a console traverses it
* looking for a channel that is watching for events on the console. Even
* in that case, no locking is required because that access is only under
- * the consoleLock lock which prevents the channel from being removed from
+ * the gConsoleLock lock which prevents the channel from being removed from
* the gWatchingChannelList which in turn means it will not be deallocated
* from under the console thread. Access to individual fields does not need
* to be controlled because
@@ -861,21 +862,33 @@ ConsoleCheckProc(
handleInfoPtr = FindConsoleInfo(chanInfoPtr);
/* Pointer is safe to access as we are holding gConsoleLock */
- if (handleInfoPtr != NULL) {
- AcquireSRWLockShared(&handleInfoPtr->lock);
- /* Rememebr channel is read or write, never both */
- if (chanInfoPtr->watchMask & TCL_READABLE) {
- if (RingBufferLength(&handleInfoPtr->buffer) > 0
- || handleInfoPtr->lastError != ERROR_SUCCESS) {
- needEvent = 1; /* Input data available or error/EOF */
- }
- } else if (chanInfoPtr->watchMask & TCL_WRITABLE) {
- if (RingBufferHasFreeSpace(&handleInfoPtr->buffer)) {
- needEvent = 1; /* Output space available */
- }
+ if (handleInfoPtr == NULL) {
+ /* Stale event */
+ continue;
+ }
+
+ needEvent = 0;
+ AcquireSRWLockShared(&handleInfoPtr->lock);
+ /* Rememeber channel is read or write, never both */
+ if (chanInfoPtr->watchMask & TCL_READABLE) {
+ if (RingBufferLength(&handleInfoPtr->buffer) > 0
+ || handleInfoPtr->lastError != ERROR_SUCCESS) {
+ needEvent = 1; /* Input data available or error/EOF */
+ }
+ /*
+ * TCL_READABLE watch means someone is looking out for data being
+ * available, let reader thread know. Note channel need not be
+ * ASYNC! (Bug [baa51423c2])
+ */
+ handleInfoPtr->flags |= CONSOLE_DATA_AWAITED;
+ WakeConditionVariable(&handleInfoPtr->consoleThreadCV);
+ }
+ else if (chanInfoPtr->watchMask & TCL_WRITABLE) {
+ if (RingBufferHasFreeSpace(&handleInfoPtr->buffer)) {
+ needEvent = 1; /* Output space available */
}
- ReleaseSRWLockShared(&handleInfoPtr->lock);
}
+ ReleaseSRWLockShared(&handleInfoPtr->lock);
if (needEvent) {
ConsoleEvent *evPtr = (ConsoleEvent *)ckalloc(sizeof(ConsoleEvent));
@@ -1103,12 +1116,6 @@ ConsoleInputProc(
* buffered data, we will pass it up.
*/
if (numRead != 0) {
- /* If console thread was blocked, awaken it */
- if (chanInfoPtr->flags & CONSOLE_ASYNC) {
- /* Async channels always want read ahead */
- handleInfoPtr->flags |= CONSOLE_DATA_AWAITED;
- WakeConditionVariable(&handleInfoPtr->consoleThreadCV);
- }
break;
}
/*
@@ -1199,7 +1206,9 @@ ConsoleInputProc(
/* Lock is reacquired, loop back to try again */
}
- if (chanInfoPtr->flags & CONSOLE_ASYNC) {
+ /* We read data. Ask for more if either async or watching for reads */
+ if ((chanInfoPtr->flags & CONSOLE_ASYNC)
+ || (chanInfoPtr->watchMask & TCL_READABLE)) {
handleInfoPtr->flags |= CONSOLE_DATA_AWAITED;
WakeConditionVariable(&handleInfoPtr->consoleThreadCV);
}
@@ -1333,7 +1342,7 @@ ConsoleOutputProc(
}
}
- /* Lock is reacquired. Continue loop */
+ /* Lock must have been reacquired before continuing loop */
}
WakeConditionVariable(&handleInfoPtr->consoleThreadCV);
ReleaseSRWLockExclusive(&handleInfoPtr->lock);
@@ -1499,8 +1508,10 @@ ConsoleWatchProc(
ConsoleHandleInfo *handleInfoPtr;
handleInfoPtr = FindConsoleInfo(chanInfoPtr);
if (handleInfoPtr) {
+ AcquireSRWLockExclusive(&handleInfoPtr->lock);
handleInfoPtr->flags |= CONSOLE_DATA_AWAITED;
WakeConditionVariable(&handleInfoPtr->consoleThreadCV);
+ ReleaseSRWLockExclusive(&handleInfoPtr->lock);
}
ReleaseSRWLockExclusive(&gConsoleLock);
}
@@ -1508,6 +1519,7 @@ ConsoleWatchProc(
} else if (oldMask) {
/* Remove from list of watched channels */
+ AcquireSRWLockExclusive(&gConsoleLock);
for (nextPtrPtr = &gWatchingChannelList, ptr = *nextPtrPtr;
ptr != NULL;
nextPtrPtr = &ptr->nextWatchingChannelPtr, ptr = *nextPtrPtr) {
@@ -1516,6 +1528,7 @@ ConsoleWatchProc(
break;
}
}
+ ReleaseSRWLockExclusive(&gConsoleLock);
}
}
@@ -1571,7 +1584,7 @@ ConsoleGetHandleProc(
static int
ConsoleDataAvailable (HANDLE consoleHandle)
{
- INPUT_RECORD input[5];
+ INPUT_RECORD input[10];
DWORD count;
DWORD i;
@@ -1583,11 +1596,17 @@ ConsoleGetHandleProc(
== FALSE) {
return -1;
}
+ /*
+ * Even if windows size and mouse events are disabled, can still have
+ * events other than keyboard, like focus events. Look for at least one
+ * keydown event because a trailing LF keyup is always present from the
+ * last input. However, if our buffer is full, assume there is a key
+ * down somewhere in the unread buffer. I suppose we could expand the
+ * buffer but not worth...
+ */
+ if (count == (sizeof(input)/sizeof(input[0])))
+ return 1;
for (i = 0; i < count; ++i) {
- /*
- * Event must be a keydown because a trailing LF keyup event is always
- * present for line based input.
- */
if (input[i].EventType == KEY_EVENT
&& input[i].Event.KeyEvent.bKeyDown) {
return 1;
@@ -1984,6 +2003,7 @@ AllocateConsoleHandleInfo(
handleInfoPtr = (ConsoleHandleInfo *)ckalloc(sizeof(*handleInfoPtr));
+ memset(handleInfoPtr, 0, sizeof(*handleInfoPtr));
handleInfoPtr->console = consoleHandle;
InitializeSRWLock(&handleInfoPtr->lock);
InitializeConditionVariable(&handleInfoPtr->consoleThreadCV);
diff --git a/win/tclooConfig.sh b/win/tclooConfig.sh
index 4c2068c..a400b5b 100644
--- a/win/tclooConfig.sh
+++ b/win/tclooConfig.sh
@@ -16,4 +16,4 @@ TCLOO_STUB_LIB_SPEC=""
TCLOO_INCLUDE_SPEC=""
TCLOO_PRIVATE_INCLUDE_SPEC=""
TCLOO_CFLAGS=""
-TCLOO_VERSION=1.2.0
+TCLOO_VERSION=1.3