This commit is contained in:
Akash Mozumdar 2018-08-24 11:32:10 -04:00
parent 65bb4b35cf
commit db6b09a50e
3 changed files with 4 additions and 5 deletions

View File

@ -4,7 +4,7 @@ set(vnrhost_src
textthread.cc textthread.cc
) )
add_library(vnrhost SHARED ${vnrhost_src}) add_library(vnrhost ${vnrhost_src})
set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS) set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS)

View File

@ -9,7 +9,7 @@
TextThread::TextThread(ThreadParam tp, DWORD status) : TextThread::TextThread(ThreadParam tp, DWORD status) :
deletionEvent(CreateEventW(nullptr, FALSE, FALSE, NULL)), deletionEvent(CreateEventW(nullptr, FALSE, FALSE, NULL)),
flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100), Flush()); }), flushThread([&]() { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); }),
timestamp(GetTickCount()), timestamp(GetTickCount()),
Output(nullptr), Output(nullptr),
tp(tp), tp(tp),
@ -18,7 +18,6 @@ TextThread::TextThread(ThreadParam tp, DWORD status) :
TextThread::~TextThread() TextThread::~TextThread()
{ {
status = -1UL;
SetEvent(deletionEvent); SetEvent(deletionEvent);
flushThread.join(); flushThread.join();
CloseHandle(deletionEvent); CloseHandle(deletionEvent);
@ -33,7 +32,6 @@ std::wstring TextThread::GetStore()
bool TextThread::Flush() bool TextThread::Flush()
{ {
TT_LOCK; 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 if (timestamp - GetTickCount() < 250 || buffer.size() == 0) return true; // TODO: let user change delay before sentence is flushed
std::wstring sentence; std::wstring sentence;
if (status & USING_UNICODE) if (status & USING_UNICODE)

View File

@ -28,11 +28,12 @@ private:
std::vector<char> buffer; std::vector<char> buffer;
std::wstring storage; std::wstring storage;
std::recursive_mutex ttMutex; std::recursive_mutex ttMutex;
HANDLE deletionEvent; HANDLE deletionEvent;
std::thread flushThread; std::thread flushThread;
DWORD timestamp; DWORD timestamp;
ThreadOutputCallback Output; ThreadOutputCallback Output;
ThreadParam tp; ThreadParam tp;
DWORD status; DWORD status;