Add a second in-memory database to ensure non-blocking operation at all times

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2021-02-28 11:51:41 +01:00
parent a273d24ce5
commit 0fa1def3bb
7 changed files with 159 additions and 50 deletions
+13 -2
View File
@@ -60,17 +60,28 @@ void *DB_thread(void *val)
// Save timestamp as we do not want to store immediately
// to the database
time_t lastDBsave = time(NULL) - time(NULL)%config.DBinterval;
time_t before = time(NULL);
time_t lastDBsave = before - before%config.DBinterval;
while(!killed)
{
if(FTL_DB_avail())
{
time_t now = time(NULL);
// Move queries from non-blocking newdb into the larger memdb
// Do this once per second
if(now > before)
{
mv_newdb_memdb();
before = now;
}
// Store queries in on-disk database
if(now - lastDBsave >= config.DBinterval)
{
// Update lastDBsave timer
lastDBsave = time(NULL) - time(NULL)%config.DBinterval;
lastDBsave = now - now%config.DBinterval;
// Save data to database (if enabled)
if(config.DBexport)