From e41feae82a9cca589b32c23696e4d752203642dc Mon Sep 17 00:00:00 2001 From: krangelov Date: Fri, 17 Sep 2021 16:43:54 +0200 Subject: [PATCH] database synchronization only on commit --- src/runtime/c/pgf/db.cxx | 28 +++++++++++++--------------- src/runtime/c/pgf/db.h | 3 ++- src/runtime/c/pgf/pgf.cxx | 6 ++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index d96888e00..b0bad20f7 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -1022,6 +1022,18 @@ void PgfDB::unlink_transient_revision(ref 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(¤t_db->rwlock); + int res = pthread_rwlock_unlock(¤t_db->rwlock); if (res != 0) throw pgf_systemerror(res); diff --git a/src/runtime/c/pgf/db.h b/src/runtime/c/pgf/db.h index 50c0fcaa5..bfde56ebb 100644 --- a/src/runtime/c/pgf/db.h +++ b/src/runtime/c/pgf/db.h @@ -85,6 +85,8 @@ public: static PGF_INTERNAL_DECL void link_transient_revision(ref pgf); static PGF_INTERNAL_DECL void unlink_transient_revision(ref 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; }; diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index 1c90bbf3c..14a65b566 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -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 }