forked from GitHub/gf-core
database synchronization only on commit
This commit is contained in:
@@ -1022,6 +1022,18 @@ void PgfDB::unlink_transient_revision(ref<PgfPGF> pgf)
|
|||||||
current_db->ms->transient_revisions = pgf->next;
|
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)
|
DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
|
||||||
{
|
{
|
||||||
int res =
|
int res =
|
||||||
@@ -1030,8 +1042,6 @@ DB_scope::DB_scope(PgfDB *db, DB_scope_mode m)
|
|||||||
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;
|
||||||
@@ -1044,19 +1054,7 @@ DB_scope::~DB_scope()
|
|||||||
{
|
{
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wterminate"
|
#pragma GCC diagnostic ignored "-Wterminate"
|
||||||
int res;
|
int res = pthread_rwlock_unlock(¤t_db->rwlock);
|
||||||
|
|
||||||
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)
|
if (res != 0)
|
||||||
throw pgf_systemerror(res);
|
throw pgf_systemerror(res);
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ 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);
|
||||||
|
|
||||||
|
static PGF_INTERNAL_DECL void sync();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PGF_INTERNAL_DECL void init_state(size_t size);
|
PGF_INTERNAL_DECL void init_state(size_t size);
|
||||||
|
|
||||||
@@ -102,7 +104,6 @@ public:
|
|||||||
~DB_scope();
|
~DB_scope();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DB_scope_mode mode;
|
|
||||||
PgfDB* save_db;
|
PgfDB* save_db;
|
||||||
DB_scope* next_scope;
|
DB_scope* next_scope;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ 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;
|
||||||
@@ -169,6 +171,8 @@ PgfDB *pgf_new_ngf(PgfText *abstract_name,
|
|||||||
memcpy(&pgf->name, &master, sizeof(PgfText)+master.size+1);
|
memcpy(&pgf->name, &master, sizeof(PgfText)+master.size+1);
|
||||||
PgfDB::set_revision(pgf);
|
PgfDB::set_revision(pgf);
|
||||||
*revision = pgf.as_object();
|
*revision = pgf.as_object();
|
||||||
|
|
||||||
|
PgfDB::sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
@@ -618,6 +622,8 @@ void pgf_commit_revision(PgfDB *db, PgfRevision revision,
|
|||||||
|
|
||||||
if (old_pgf != 0)
|
if (old_pgf != 0)
|
||||||
PgfDB::link_transient_revision(old_pgf);
|
PgfDB::link_transient_revision(old_pgf);
|
||||||
|
|
||||||
|
PgfDB::sync();
|
||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user