Create the flush thread on first use

Some processes just return from the entry point; this only exits the
thread, not the process.  It seems that when ANSICON created its flush
thread in DllMain, that became the primary thread, so when the entry
point returned the process was still waiting for the flush thread to
exit.  Creating the flush thread the first time it is used avoids this
problem, letting the process exit.
This commit is contained in:
Jason Hood 2018-02-16 17:18:25 +10:00
parent c232c1ff37
commit 3a16e68201
4 changed files with 17 additions and 10 deletions

8
ANSI.c
View File

@ -193,6 +193,9 @@
flush and invalidate the cache on CloseHandle; flush and invalidate the cache on CloseHandle;
make IsConsoleHandle a critical section, for multithreaded processes; make IsConsoleHandle a critical section, for multithreaded processes;
use APIConsole for all console functions (needed for Windows 10). use APIConsole for all console functions (needed for Windows 10).
v1.83, 16 February, 2018:
create the flush thread on first use.
*/ */
#include "ansicon.h" #include "ansicon.h"
@ -212,7 +215,7 @@ WORD orgattr; // original attributes
DWORD orgmode; // original mode DWORD orgmode; // original mode
CONSOLE_CURSOR_INFO orgcci; // original cursor state CONSOLE_CURSOR_INFO orgcci; // original cursor state
HANDLE hHeap; // local memory heap HANDLE hHeap; // local memory heap
HANDLE hBell; HANDLE hBell, hFlush;
#define CACHE 5 #define CACHE 5
struct Cache struct Cache
@ -2528,6 +2531,8 @@ ParseAndPrintString( HANDLE hDev,
{ {
LARGE_INTEGER due; LARGE_INTEGER due;
due.QuadPart = -150000; due.QuadPart = -150000;
if (hFlush == NULL)
hFlush = CreateThread( NULL, 4096, FlushThread, NULL, 0, NULL );
SetWaitableTimer( hFlushTimer, &due, 0, NULL, NULL, FALSE ); SetWaitableTimer( hFlushTimer, &due, 0, NULL, NULL, FALSE );
} }
} }
@ -3897,7 +3902,6 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
InitializeCriticalSection( &CritSect ); InitializeCriticalSection( &CritSect );
hFlushTimer = CreateWaitableTimer( NULL, FALSE, NULL ); hFlushTimer = CreateWaitableTimer( NULL, FALSE, NULL );
CreateThread( NULL, 4096, FlushThread, NULL, 0, NULL );
} }
else if (dwReason == DLL_PROCESS_DETACH) else if (dwReason == DLL_PROCESS_DETACH)
{ {

View File

@ -91,7 +91,7 @@
use -pu to unload from the parent. use -pu to unload from the parent.
*/ */
#define PDATE L"13 February, 2018" #define PDATE L"16 February, 2018"
#include "ansicon.h" #include "ansicon.h"
#include "version.h" #include "version.h"

View File

@ -3,7 +3,7 @@
Copyright 2005-2018 Jason Hood Copyright 2005-2018 Jason Hood
Version 1.82. Freeware Version 1.83. Freeware
Description Description
@ -339,6 +339,9 @@ Version History
Legend: + added, - bug-fixed, * changed. Legend: + added, - bug-fixed, * changed.
1.83 - 16 February, 2018:
- create the flush thread on first use.
1.82 - 13 February, 2018: 1.82 - 13 February, 2018:
- add ANSICON_WRAP for programs that expect the wrap at right margin; - add ANSICON_WRAP for programs that expect the wrap at right margin;
- make IsConsoleHandle a critical section, for multithreaded processes; - make IsConsoleHandle a critical section, for multithreaded processes;
@ -610,4 +613,4 @@ Distribution
============================== ==============================
Jason Hood, 13 February, 2018. Jason Hood, 16 February, 2018.

View File

@ -2,11 +2,11 @@
version.h - Version defines. version.h - Version defines.
*/ */
#define PVERS L"1.82" // wide string #define PVERS L"1.83" // wide string
#define PVERSA "1.82" // ANSI string (windres 2.16.91 didn't like L) #define PVERSA "1.83" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"182" // wide environment string #define PVERE L"183" // wide environment string
#define PVEREA "182" // ANSI environment string #define PVEREA "183" // ANSI environment string
#define PVERB 1,8,2,0 // binary (resource) #define PVERB 1,8,3,0 // binary (resource)
#ifdef _WIN64 #ifdef _WIN64
# define BITS L"64" # define BITS L"64"