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
)
add_library(vnrhost SHARED ${vnrhost_src})
add_library(vnrhost ${vnrhost_src})
set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS)

View File

@ -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)

View File

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