summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-01 21:08:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-01 21:08:57 +0300
commit704258cde008db0e80b9d5459833c3c2b6a3f09d (patch)
tree7327cd038762c03b31afb46b3c000d32b02b35e0 /plugins/Dbx_mdbx/src
parent64c7a1ff5a3fd1fcfa809c48c5ea18410cf4fc0a (diff)
much more efficient way of handling DBFlush, with separate window
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp20
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h3
2 files changed, 15 insertions, 8 deletions
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index b94edd4845..00440fb425 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -31,6 +31,9 @@ CDbxMDBX::CDbxMDBX(const TCHAR *tszFileName, int iMode) :
{
m_tszProfileName = mir_wstrdup(tszFileName);
+ m_hwndTimer = CreateWindowExW(0, L"STATIC", nullptr, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, nullptr, g_hInst, nullptr);
+ ::SetWindowLongPtr(m_hwndTimer, GWLP_USERDATA, (LONG_PTR)this);
+
mdbx_env_create(&m_env);
mdbx_env_set_maxdbs(m_env, 10);
mdbx_env_set_maxreaders(m_env, 244);
@@ -42,6 +45,8 @@ CDbxMDBX::~CDbxMDBX()
g_Dbs.remove(this);
mdbx_env_close(m_env);
+ ::DestroyWindow(m_hwndTimer);
+
DestroyServiceFunction(hService);
UnhookEvent(hHook);
@@ -198,6 +203,7 @@ int CDbxMDBX::Map()
-1 /* default page size */);
if (rc != MDBX_SUCCESS)
return rc;
+
unsigned int mode = MDBX_NOSUBDIR | MDBX_MAPASYNC | MDBX_WRITEMAP | MDBX_NOSYNC;
if (m_bReadOnly)
mode |= MDBX_RDONLY;
@@ -208,13 +214,13 @@ int CDbxMDBX::Map()
/////////////////////////////////////////////////////////////////////////////////////////
-static VOID CALLBACK DoBufferFlushTimerProc(HWND, UINT, UINT_PTR idEvent, DWORD)
+static VOID CALLBACK DoBufferFlushTimerProc(HWND hwnd, UINT, UINT_PTR idEvent, DWORD)
{
- KillTimer(nullptr, idEvent);
+ KillTimer(hwnd, idEvent);
- for (auto &it : g_Dbs)
- if (it->m_timerId == idEvent)
- it->DBFlush(true);
+ CDbxMDBX *pDb = (CDbxMDBX *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ if (pDb)
+ pDb->DBFlush(true);
}
void CDbxMDBX::DBFlush(bool bForce)
@@ -223,7 +229,7 @@ void CDbxMDBX::DBFlush(bool bForce)
mdbx_env_sync(m_env, true);
}
else if (m_safetyMode) {
- ::KillTimer(nullptr, m_timerId);
- ::SetTimer(nullptr, m_timerId, 50, DoBufferFlushTimerProc);
+ ::KillTimer(m_hwndTimer, 1);
+ ::SetTimer(m_hwndTimer, 1, 50, DoBufferFlushTimerProc);
}
}
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index a1e4c992c7..9c42ea77f7 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -161,6 +161,8 @@ class CDbxMDBX : public MDatabaseCommon, public MZeroedObject
DBHeader m_header;
HANDLE hSettingChangeEvent, hContactDeletedEvent, hContactAddedEvent, hEventMarkedRead;
+ HWND m_hwndTimer; // for flushing database
+
DBCachedContact m_ccDummy; // dummy contact to serve a cache item for MCONTACT = 0
////////////////////////////////////////////////////////////////////////////
@@ -268,5 +270,4 @@ public:
public:
MICryptoEngine *m_crypto;
- UINT_PTR m_timerId; // timer to flush unsaved data
};