mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-27 07:44:02 +08:00
sync
This commit is contained in:
parent
8ccecb045a
commit
d35fb7a601
@ -164,7 +164,19 @@ C_LUNA_API void Luna_embedcallback(DWORD pid, LPCWSTR text, LPCWSTR trans)
|
|||||||
|
|
||||||
C_LUNA_API void Luna_SyncThread(ThreadParam tp, bool sync)
|
C_LUNA_API void Luna_SyncThread(ThreadParam tp, bool sync)
|
||||||
{
|
{
|
||||||
auto sm = Host::GetCommonSharedMem(tp.processId);
|
// 必须放到线程里去异步做,不然GetThread死锁
|
||||||
if (!sm)
|
std::thread([=]()
|
||||||
return;
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto &&t=Host::GetThread(tp);
|
||||||
|
if (sync)
|
||||||
|
TextThread::syncThreads->insert(&t);
|
||||||
|
else
|
||||||
|
TextThread::syncThreads->erase(&t);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
} })
|
||||||
|
.detach();
|
||||||
}
|
}
|
@ -61,6 +61,13 @@ namespace
|
|||||||
threadsToRemove.push_back(&thread);
|
threadsToRemove.push_back(&thread);
|
||||||
for (auto thread : threadsToRemove)
|
for (auto thread : threadsToRemove)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TextThread::syncThreads->erase(thread);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
OnDestroy(*thread);
|
OnDestroy(*thread);
|
||||||
textThreadsByParams->erase(thread->tp);
|
textThreadsByParams->erase(thread->tp);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void TextThread::Push(BYTE *data, int length)
|
|||||||
else
|
else
|
||||||
Host::AddConsoleOutput(INVALID_CODEPAGE);
|
Host::AddConsoleOutput(INVALID_CODEPAGE);
|
||||||
|
|
||||||
lastPushTime = GetTickCount64();
|
UpdateFlushTime();
|
||||||
|
|
||||||
if (filterRepetition)
|
if (filterRepetition)
|
||||||
{
|
{
|
||||||
@ -89,12 +89,26 @@ void TextThread::Push(BYTE *data, int length)
|
|||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void TextThread::UpdateFlushTime(bool recursive)
|
||||||
|
{
|
||||||
|
lastPushTime = GetTickCount64();
|
||||||
|
if (!recursive)
|
||||||
|
return;
|
||||||
|
auto&& ths = syncThreads.Acquire().contents;
|
||||||
|
if (ths.find(this) == ths.end())
|
||||||
|
return;
|
||||||
|
for (auto t : ths)
|
||||||
|
{
|
||||||
|
if (t == this)
|
||||||
|
continue;
|
||||||
|
t->UpdateFlushTime(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
void TextThread::Push(const wchar_t *data)
|
void TextThread::Push(const wchar_t *data)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(bufferMutex);
|
std::scoped_lock lock(bufferMutex);
|
||||||
// not sure if this should filter repetition
|
// not sure if this should filter repetition
|
||||||
lastPushTime = GetTickCount64();
|
UpdateFlushTime();
|
||||||
buffer += data;
|
buffer += data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ public:
|
|||||||
inline static int flushDelay = 100;
|
inline static int flushDelay = 100;
|
||||||
inline static int maxBufferSize = 3000;
|
inline static int maxBufferSize = 3000;
|
||||||
inline static int maxHistorySize = 10'000'000;
|
inline static int maxHistorySize = 10'000'000;
|
||||||
|
inline static Synchronized<std::set<TextThread *>> syncThreads;
|
||||||
|
|
||||||
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});
|
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});
|
||||||
|
|
||||||
@ -41,4 +42,5 @@ private:
|
|||||||
void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); }
|
void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); }
|
||||||
};
|
};
|
||||||
AutoHandle<TimerDeleter> timer = NULL;
|
AutoHandle<TimerDeleter> timer = NULL;
|
||||||
|
void UpdateFlushTime(bool recursive = true);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user