diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index 068cccd4a..9c7f3ca7a 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -348,18 +348,6 @@ PgfDB::~PgfDB() { ::free((void*) filepath); } -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); -} - PGF_INTERNAL ref PgfDB::get_revision(PgfText *name) { @@ -1021,14 +1009,16 @@ void PgfDB::unlink_transient_revision(ref pgf) current_db->ms->transient_revisions = pgf->next; } -DB_scope::DB_scope(PgfDB *db, DB_scope_mode tp) +DB_scope::DB_scope(PgfDB *db, DB_scope_mode m) { int res = - (tp == READER_SCOPE) ? pthread_rwlock_rdlock(&db->rwlock) - : pthread_rwlock_wrlock(&db->rwlock); + (m == READER_SCOPE) ? pthread_rwlock_rdlock(&db->rwlock) + : pthread_rwlock_wrlock(&db->rwlock); if (res != 0) throw pgf_systemerror(res); + mode = m; + save_db = current_db; current_db = db; current_base = (unsigned char*) current_db->ms; @@ -1039,17 +1029,29 @@ DB_scope::DB_scope(PgfDB *db, DB_scope_mode tp) DB_scope::~DB_scope() { - int res = pthread_rwlock_unlock(¤t_db->rwlock); - #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); if (res != 0) throw pgf_systemerror(res); -#pragma GCC diagnostic pop current_db = save_db; current_base = current_db ? (unsigned char*) current_db->ms : NULL; last_db_scope = next_scope; + +#pragma GCC diagnostic pop } diff --git a/src/runtime/c/pgf/db.h b/src/runtime/c/pgf/db.h index 0331ad4b3..50c0fcaa5 100644 --- a/src/runtime/c/pgf/db.h +++ b/src/runtime/c/pgf/db.h @@ -85,8 +85,6 @@ public: static PGF_INTERNAL_DECL void link_transient_revision(ref pgf); static PGF_INTERNAL_DECL void unlink_transient_revision(ref pgf); - PGF_INTERNAL_DECL static void sync(); - private: PGF_INTERNAL_DECL void init_state(size_t size); @@ -100,10 +98,11 @@ enum DB_scope_mode {READER_SCOPE, WRITER_SCOPE}; class PGF_INTERNAL_DECL DB_scope { public: - DB_scope(PgfDB *db, DB_scope_mode type); + DB_scope(PgfDB *db, DB_scope_mode m); ~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 8676a73fc..30908c369 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -87,8 +87,6 @@ PgfDB *pgf_boot_ngf(const char* pgf_path, const char* ngf_path, PgfDB::set_revision(pgf); *revision = pgf.as_object(); - - PgfDB::sync(); } return db;