mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
refactor
This commit is contained in:
parent
65bb4b35cf
commit
db6b09a50e
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user