1
0
forked from GitHub/gf-core

PgfDB::sync is now moved to the desctructor for DB_scope

This commit is contained in:
krangelov
2021-09-11 18:20:28 +02:00
parent 4e443374de
commit 6cfa250b28
3 changed files with 22 additions and 23 deletions

View File

@@ -348,18 +348,6 @@ PgfDB::~PgfDB() {
::free((void*) filepath); ::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 PGF_INTERNAL
ref<PgfPGF> PgfDB::get_revision(PgfText *name) ref<PgfPGF> PgfDB::get_revision(PgfText *name)
{ {
@@ -1021,14 +1009,16 @@ void PgfDB::unlink_transient_revision(ref<PgfPGF> pgf)
current_db->ms->transient_revisions = pgf->next; 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 = int res =
(tp == READER_SCOPE) ? pthread_rwlock_rdlock(&db->rwlock) (m == READER_SCOPE) ? pthread_rwlock_rdlock(&db->rwlock)
: pthread_rwlock_wrlock(&db->rwlock); : pthread_rwlock_wrlock(&db->rwlock);
if (res != 0) if (res != 0)
throw pgf_systemerror(res); throw pgf_systemerror(res);
mode = m;
save_db = current_db; save_db = current_db;
current_db = db; current_db = db;
current_base = (unsigned char*) current_db->ms; 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() DB_scope::~DB_scope()
{ {
int res = pthread_rwlock_unlock(&current_db->rwlock);
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wterminate" #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);
if (res != 0) if (res != 0)
throw pgf_systemerror(res); throw pgf_systemerror(res);
#pragma GCC diagnostic pop
current_db = save_db; current_db = save_db;
current_base = current_db ? (unsigned char*) current_db->ms current_base = current_db ? (unsigned char*) current_db->ms
: NULL; : NULL;
last_db_scope = next_scope; last_db_scope = next_scope;
#pragma GCC diagnostic pop
} }

View File

@@ -85,8 +85,6 @@ public:
static PGF_INTERNAL_DECL void link_transient_revision(ref<PgfPGF> pgf); 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 unlink_transient_revision(ref<PgfPGF> pgf);
PGF_INTERNAL_DECL static void sync();
private: private:
PGF_INTERNAL_DECL void init_state(size_t size); 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 { class PGF_INTERNAL_DECL DB_scope {
public: public:
DB_scope(PgfDB *db, DB_scope_mode type); DB_scope(PgfDB *db, DB_scope_mode m);
~DB_scope(); ~DB_scope();
private: private:
DB_scope_mode mode;
PgfDB* save_db; PgfDB* save_db;
DB_scope* next_scope; DB_scope* next_scope;
}; };

View File

@@ -87,8 +87,6 @@ PgfDB *pgf_boot_ngf(const char* pgf_path, const char* ngf_path,
PgfDB::set_revision(pgf); PgfDB::set_revision(pgf);
*revision = pgf.as_object(); *revision = pgf.as_object();
PgfDB::sync();
} }
return db; return db;