From 41f80622cbcbc0f7c17d609a77d92e9e5ed1639b Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 28 Aug 2018 15:17:45 -0400 Subject: [PATCH] performance improvement --- GUI/host/host.cc | 2 +- GUI/host/textthread.h | 2 +- include/types.h | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/GUI/host/host.cc b/GUI/host/host.cc index 4f4c38b..fc89755 100644 --- a/GUI/host/host.cc +++ b/GUI/host/host.cc @@ -25,7 +25,7 @@ namespace std::unordered_map textThreadsByParams; std::unordered_map processRecordsByIds; - std::recursive_mutex hostMutex; + WinMutex hostMutex; DWORD DUMMY[100]; ThreadParam CONSOLE{ 0, -1ULL, -1ULL, -1ULL }; diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index c9974f3..0ee7ea5 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -28,7 +28,7 @@ private: std::vector buffer; std::wstring storage; - std::recursive_mutex ttMutex; + WinMutex ttMutex; HANDLE deletionEvent = CreateEventW(nullptr, FALSE, FALSE, NULL); std::thread flushThread = std::thread([&]() { while (WaitForSingleObject(deletionEvent, 100) == WAIT_TIMEOUT) Flush(); }); diff --git a/include/types.h b/include/types.h index 0755013..efd8847 100644 --- a/include/types.h +++ b/include/types.h @@ -68,4 +68,15 @@ struct HookRemovedNotif // From hook unsigned __int64 address; }; -typedef std::lock_guard LOCK; +// Artikash 8/28/2018: similar to std::recursive_mutex but uses WinAPI for better performance +class WinMutex +{ + CRITICAL_SECTION cs; +public: + WinMutex() { InitializeCriticalSection(&cs); }; + ~WinMutex() { EnterCriticalSection(&cs); LeaveCriticalSection(&cs); DeleteCriticalSection(&cs); }; + void lock() { EnterCriticalSection(&cs); }; + void unlock() { LeaveCriticalSection(&cs); }; +}; + +typedef std::lock_guard LOCK;