performance improvement

This commit is contained in:
Akash Mozumdar 2018-08-28 15:17:45 -04:00
parent 88b2d85a75
commit 41f80622cb
3 changed files with 14 additions and 3 deletions

View File

@ -25,7 +25,7 @@ namespace
std::unordered_map<ThreadParam, TextThread*> textThreadsByParams;
std::unordered_map<DWORD, ProcessRecord> processRecordsByIds;
std::recursive_mutex hostMutex;
WinMutex hostMutex;
DWORD DUMMY[100];
ThreadParam CONSOLE{ 0, -1ULL, -1ULL, -1ULL };

View File

@ -28,7 +28,7 @@ private:
std::vector<char> 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(); });

View File

@ -68,4 +68,15 @@ struct HookRemovedNotif // From hook
unsigned __int64 address;
};
typedef std::lock_guard<std::recursive_mutex> 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<WinMutex> LOCK;