diff --git a/GUI/host/host.cpp b/GUI/host/host.cpp index d96d73b..856ccad 100644 --- a/GUI/host/host.cpp +++ b/GUI/host/host.cpp @@ -53,8 +53,8 @@ namespace WinMutex viewMutex; }; - ThreadSafePtr>> textThreadsByParams; - ThreadSafePtr> processRecordsByIds; + ThreadSafe>> textThreadsByParams; + ThreadSafe> processRecordsByIds; ThreadParam CONSOLE{ 0, -1ULL, -1ULL, -1ULL }, CLIPBOARD{ 0, 0, -1ULL, -1ULL }; diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index b73d41b..2e80404 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -22,7 +22,7 @@ public: void AddSentence(std::wstring sentence); void Push(const BYTE* data, int len); - const ThreadSafePtr storage; + ThreadSafe storage; const int64_t handle; const std::wstring name; const ThreadParam tp; diff --git a/include/types.h b/include/types.h index 44c62dd..0c49d63 100644 --- a/include/types.h +++ b/include/types.h @@ -5,25 +5,25 @@ template using Array = T[]; -template typename P = std::unique_ptr> -class ThreadSafePtr +template +class ThreadSafe { public: - template ThreadSafePtr(Args ...args) : ptr(new E(args...)), mtxPtr(new M) {} - auto operator->() const + template ThreadSafe(Args ...args) : contents(args...) {} + auto operator->() { struct { E* operator->() { return ptr; } std::unique_lock lock; E* ptr; - } lockedProxy{ std::unique_lock(*mtxPtr), ptr.get() }; + } lockedProxy{ std::unique_lock(mtx), &contents }; return lockedProxy; } private: - P ptr; - P mtxPtr; + E contents; + M mtx; }; struct DefHandleCloser { void operator()(void* h) { CloseHandle(h); } };