From 0a8a140351a533e2fb895228589efd2846b9c697 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 30 Mar 2018 16:47:09 +0300 Subject: fix for asynchronous database flush to fix unsaved data --- plugins/Dbx_mdbx/src/dbintf.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'plugins/Dbx_mdbx/src/dbintf.cpp') diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 79f5f0a4f1..b94edd4845 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -95,6 +95,7 @@ int CDbxMDBX::Load(bool bSkipInit) m_header.dwVersion = DBHEADER_VERSION; data.iov_base = &m_header; data.iov_len = sizeof(m_header); mdbx_put(trnlck, m_dbGlobal, &key, &data, 0); + DBFlush(); } keyVal = 2; @@ -183,6 +184,7 @@ int CDbxMDBX::PrepareCheck() STDMETHODIMP_(void) CDbxMDBX::SetCacheSafetyMode(BOOL bIsSet) { m_safetyMode = bIsSet != 0; + DBFlush(true); } int CDbxMDBX::Map() @@ -203,3 +205,25 @@ int CDbxMDBX::Map() int exclusive = (m_bShared) ? 1 : 2; return mdbx_env_open_ex(m_env, _T2A(m_tszProfileName), mode, 0664, &exclusive); } + +///////////////////////////////////////////////////////////////////////////////////////// + +static VOID CALLBACK DoBufferFlushTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD) +{ + KillTimer(nullptr, idEvent); + + for (auto &it : g_Dbs) + if (it->m_timerId == idEvent) + it->DBFlush(true); +} + +void CDbxMDBX::DBFlush(bool bForce) +{ + if (bForce) { + mdbx_env_sync(m_env, true); + } + else if (m_safetyMode) { + ::KillTimer(nullptr, m_timerId); + ::SetTimer(nullptr, m_timerId, 50, DoBufferFlushTimerProc); + } +} -- cgit v1.2.3