forked from Public-Mirror/Textractor
refactor
This commit is contained in:
parent
65bb4b35cf
commit
db6b09a50e
@ -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)
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user