From 516cbe82f0191a9ff3b2c43e4b2330fb48fa07e3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 12 Jan 2020 19:48:42 +0300 Subject: CDbxMDBX: useless window removed and replaced with Miranda_GetSystemWindow() --- plugins/Dbx_mdbx/src/dbintf.cpp | 32 +++++++------------------------- plugins/Dbx_mdbx/src/dbintf.h | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 26 deletions(-) (limited to 'plugins') diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 088dcb5eea..db87bcca74 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -30,14 +30,10 @@ CDbxMDBX::CDbxMDBX(const TCHAR *tszFileName, int iMode) : m_safetyMode(true), m_bReadOnly((iMode & DBMODE_READONLY) != 0), m_bShared((iMode & DBMODE_SHARED) != 0), - m_maxContactId(0) + m_maxContactId(0), + m_impl(*this) { m_tszProfileName = mir_wstrdup(tszFileName); - - if (!m_bReadOnly) { - m_hwndTimer = CreateWindowExW(0, L"STATIC", nullptr, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, nullptr, g_plugin.getInst(), nullptr); - ::SetWindowLongPtr(m_hwndTimer, GWLP_USERDATA, (LONG_PTR)this); - } } CDbxMDBX::~CDbxMDBX() @@ -47,9 +43,6 @@ CDbxMDBX::~CDbxMDBX() if (!m_bReadOnly) TouchFile(); - if (m_hwndTimer != nullptr) - ::DestroyWindow(m_hwndTimer); - for (auto &it : hService) DestroyServiceFunction(it); UnhookEvent(hHook); @@ -188,7 +181,7 @@ LBL_Fail: res = FlushFileBuffers(pFile); if (res == 0) { - Netlib_Logf(0, "CDbxMDBX::Backup: FlushFileBuffers failed with error code %d (%d)", GetLastError()); + Netlib_Logf(0, "CDbxMDBX::Backup: FlushFileBuffers failed with error code %d", GetLastError()); goto LBL_Fail; } @@ -279,22 +272,11 @@ void CDbxMDBX::TouchFile() ///////////////////////////////////////////////////////////////////////////////////////// -static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT, UINT_PTR idEvent, DWORD) -{ - KillTimer(hwnd, idEvent); - - CDbxMDBX *pDb = (CDbxMDBX *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - if (pDb) - pDb->DBFlush(true); -} - void CDbxMDBX::DBFlush(bool bForce) { - if (bForce) { + if (bForce) mdbx_env_sync(m_env); - } - else if (m_safetyMode) { - ::KillTimer(m_hwndTimer, 1); - ::SetTimer(m_hwndTimer, 1, 50, DoBufferFlushTimerProc); - } + + else if (m_safetyMode) + m_impl.m_timer.Start(50); } diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 14e44ae700..acba02260d 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -140,6 +140,24 @@ class CDbxMDBX : public MDatabaseCommon, public MZeroedObject { friend class MDBXEventCursor; + struct Impl { + CDbxMDBX &pro; + + CTimer m_timer; + void OnTimer(CTimer *pTimer) + { + pTimer->Stop(); + pro.DBFlush(true); + } + + Impl(CDbxMDBX &_p) : + pro(_p), + m_timer(Miranda_GetSystemWindow(), UINT_PTR(this)) + { + m_timer.OnEvent = Callback(this, &Impl::OnTimer); + } + } m_impl; + __forceinline MDBX_txn* StartTran() const { MDBX_txn *res = 0; @@ -168,7 +186,6 @@ class CDbxMDBX : public MDatabaseCommon, public MZeroedObject MDBX_dbi m_dbGlobal; DBHeader m_header; - HWND m_hwndTimer; // for flushing database DBCachedContact m_ccDummy; // dummy contact to serve a cache item for MCONTACT = 0 -- cgit v1.2.3