Skip to content

Commit

Permalink
Create the flush thread on first use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adoxa committed Feb 16, 2018
1 parent c232c1f commit 3a16e68
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
8 changes: 6 additions & 2 deletions ANSI.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
flush and invalidate the cache on CloseHandle;
make IsConsoleHandle a critical section, for multithreaded processes;
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"
Expand All @@ -212,7 +215,7 @@ WORD orgattr; // original attributes
DWORD orgmode; // original mode
CONSOLE_CURSOR_INFO orgcci; // original cursor state
HANDLE hHeap; // local memory heap
HANDLE hBell;
HANDLE hBell, hFlush;

#define CACHE 5
struct Cache
Expand Down Expand Up @@ -2528,6 +2531,8 @@ ParseAndPrintString( HANDLE hDev,
{
LARGE_INTEGER due;
due.QuadPart = -150000;
if (hFlush == NULL)
hFlush = CreateThread( NULL, 4096, FlushThread, NULL, 0, NULL );
SetWaitableTimer( hFlushTimer, &due, 0, NULL, NULL, FALSE );
}
}
Expand Down Expand Up @@ -3897,7 +3902,6 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )

InitializeCriticalSection( &CritSect );
hFlushTimer = CreateWaitableTimer( NULL, FALSE, NULL );
CreateThread( NULL, 4096, FlushThread, NULL, 0, NULL );
}
else if (dwReason == DLL_PROCESS_DETACH)
{
Expand Down
2 changes: 1 addition & 1 deletion ansicon.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
use -pu to unload from the parent.
*/

#define PDATE L"13 February, 2018"
#define PDATE L"16 February, 2018"

#include "ansicon.h"
#include "version.h"
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Copyright 2005-2018 Jason Hood

Version 1.82. Freeware
Version 1.83. Freeware


Description
Expand Down Expand Up @@ -339,6 +339,9 @@ Version History

Legend: + added, - bug-fixed, * changed.

1.83 - 16 February, 2018:
- create the flush thread on first use.

1.82 - 13 February, 2018:
- add ANSICON_WRAP for programs that expect the wrap at right margin;
- make IsConsoleHandle a critical section, for multithreaded processes;
Expand Down Expand Up @@ -610,4 +613,4 @@ Distribution


==============================
Jason Hood, 13 February, 2018.
Jason Hood, 16 February, 2018.
10 changes: 5 additions & 5 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
version.h - Version defines.
*/

#define PVERS L"1.82" // wide string
#define PVERSA "1.82" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"182" // wide environment string
#define PVEREA "182" // ANSI environment string
#define PVERB 1,8,2,0 // binary (resource)
#define PVERS L"1.83" // wide string
#define PVERSA "1.83" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"183" // wide environment string
#define PVEREA "183" // ANSI environment string
#define PVERB 1,8,3,0 // binary (resource)

#ifdef _WIN64
# define BITS L"64"
Expand Down

0 comments on commit 3a16e68

Please sign in to comment.