From db6b09a50e0f8fb68da04b9b31f4017f9658e768 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 24 Aug 2018 11:32:10 -0400 Subject: [PATCH] refactor --- host/CMakeLists.txt | 2 +- host/textthread.cc | 4 +--- host/textthread.h | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index b863d03..a130c35 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -4,7 +4,7 @@ set(vnrhost_src textthread.cc ) -add_library(vnrhost SHARED ${vnrhost_src}) +add_library(vnrhost ${vnrhost_src}) set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS) diff --git a/host/textthread.cc b/host/textthread.cc index 227a32a..b9d5811 100644 --- a/host/textthread.cc +++ b/host/textthread.cc @@ -9,7 +9,7 @@ TextThread::TextThread(ThreadParam tp, DWORD status) : deletionEvent(CreateEventW(nullptr, FALSE, FALSE, NULL)), - flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100), Flush()); }), + flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); }), timestamp(GetTickCount()), Output(nullptr), tp(tp), @@ -18,7 +18,6 @@ TextThread::TextThread(ThreadParam tp, DWORD status) : TextThread::~TextThread() { - status = -1UL; SetEvent(deletionEvent); flushThread.join(); CloseHandle(deletionEvent); @@ -33,7 +32,6 @@ std::wstring TextThread::GetStore() bool TextThread::Flush() { TT_LOCK; - if (status == -1UL) return false; if (timestamp - GetTickCount() < 250 || buffer.size() == 0) return true; // TODO: let user change delay before sentence is flushed std::wstring sentence; if (status & USING_UNICODE) diff --git a/host/textthread.h b/host/textthread.h index a4737e0..99e4c64 100644 --- a/host/textthread.h +++ b/host/textthread.h @@ -28,11 +28,12 @@ private: std::vector buffer; std::wstring storage; + std::recursive_mutex ttMutex; HANDLE deletionEvent; std::thread flushThread; - DWORD timestamp; + ThreadOutputCallback Output; ThreadParam tp; DWORD status;