1
0
forked from GitHub/gf-core

database synchronization only on commit

This commit is contained in:
krangelov
2021-09-17 16:43:54 +02:00
parent 44b5d0f870
commit e41feae82a
3 changed files with 21 additions and 16 deletions

View File

@@ -1022,6 +1022,18 @@ void PgfDB::unlink_transient_revision(ref<PgfPGF> pgf)
current_db->ms->transient_revisions = pgf->next;
}
PGF_INTERNAL
void PgfDB::sync()
{
malloc_state *ms = current_db->ms;
size_t size =
ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
int res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE);
if (res != 0)
throw pgf_systemerror(errno);
}
DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
{
int res =
@@ -1030,8 +1042,6 @@ DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
if (res != 0)
throw pgf_systemerror(res);
mode = m;
save_db = current_db;
current_db = db;
current_base = (unsigned char*) current_db->ms;
@@ -1044,19 +1054,7 @@ DB_scope::~DB_scope()
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wterminate"
int res;
if (mode == WRITER_SCOPE) {
malloc_state *ms = current_db->ms;
size_t size =
ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE);
if (res != 0)
throw pgf_systemerror(errno);
}
res = pthread_rwlock_unlock(&current_db->rwlock);
int res = pthread_rwlock_unlock(&current_db->rwlock);
if (res != 0)
throw pgf_systemerror(res);

View File

@@ -85,6 +85,8 @@ public:
static PGF_INTERNAL_DECL void link_transient_revision(ref<PgfPGF> pgf);
static PGF_INTERNAL_DECL void unlink_transient_revision(ref<PgfPGF> pgf);
static PGF_INTERNAL_DECL void sync();
private:
PGF_INTERNAL_DECL void init_state(size_t size);
@@ -102,7 +104,6 @@ public:
~DB_scope();
private:
DB_scope_mode mode;
PgfDB* save_db;
DB_scope* next_scope;
};

View File

@@ -93,6 +93,8 @@ PgfDB *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
PgfDB::set_revision(pgf);
*revision = pgf.as_object();
PgfDB::sync();
}
return db;
@@ -169,6 +171,8 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name,
memcpy(&pgf->name, &master, sizeof(PgfText)+master.size+1);
PgfDB::set_revision(pgf);
*revision = pgf.as_object();
PgfDB::sync();
}
return db;
@@ -618,6 +622,8 @@ void pgf_commit_revision(PgfDB *db, PgfRevision revision,
if (old_pgf != 0)
PgfDB::link_transient_revision(old_pgf);
PgfDB::sync();
} PGF_API_END
}