From a8ba3cb11220fdfc5ce6ee62a78c2754fbba2a63 Mon Sep 17 00:00:00 2001 From: Michał Cichoń Date: Tue, 25 Aug 2015 19:02:33 +0200 Subject: Replace pthread with CRT thread. --- src/console.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/console.c b/src/console.c index af105b2..b05f0a3 100644 --- a/src/console.c +++ b/src/console.c @@ -26,7 +26,7 @@ THE SOFTWARE. #include #include #include -#include +#include #include "vtparse/vtparse.h" enum { READ = 0, WRITE }; @@ -50,8 +50,7 @@ static struct BarConsoleState { WORD DefaultAttributes; WORD CurrentAttributes; - pthread_t ConsoleThread; - bool Spawned; + HANDLE ConsoleThread; bool Terminate; vtparse_t Parser; @@ -144,7 +143,7 @@ static void BarParseCallback(struct vtparse* parser, vtparse_action_t action, un } } -static void* BarConsoleThread(void* args) { +static unsigned __stdcall BarConsoleThread(void* args) { while (!g_BarConsole.Terminate) { @@ -156,10 +155,11 @@ static void* BarConsoleThread(void* args) { BarOutFlush(); } - return NULL; + return 0; } void BarConsoleInit() { + unsigned threadId = 0; CONSOLE_SCREEN_BUFFER_INFO csbi; memset(&g_BarConsole, 0, sizeof(g_BarConsole)); @@ -184,8 +184,8 @@ void BarConsoleInit() { dup2(g_BarConsole.Pipes[WRITE], fileno(stdout)); dup2(g_BarConsole.Pipes[WRITE], fileno(stderr)); - g_BarConsole.Spawned = pthread_create(&g_BarConsole.ConsoleThread, NULL, BarConsoleThread, NULL) == 0; - if (!g_BarConsole.Spawned) + g_BarConsole.ConsoleThread = (HANDLE)_beginthreadex(NULL, 0, BarConsoleThread, NULL, 0, &threadId); + if (!g_BarConsole.ConsoleThread) BarConsoleDestroy(); } @@ -193,7 +193,7 @@ void BarConsoleInit() { } void BarConsoleDestroy() { - if (g_BarConsole.Spawned) { + if (g_BarConsole.ConsoleThread) { g_BarConsole.Terminate = true; fputs(" ", stderr); fputs(" ", stdout); @@ -201,7 +201,7 @@ void BarConsoleDestroy() { fflush(stdout); fflush(stderr); - pthread_join(g_BarConsole.ConsoleThread, NULL); + WaitForSingleObject(g_BarConsole.ConsoleThread, INFINITE); } if (g_BarConsole.OriginalStdErr > 0) { -- cgit v1.2.3