mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
make sure that changes in the database are always flushed
This commit is contained in:
@@ -120,13 +120,9 @@ struct PGF_INTERNAL_DECL PgfPGFRoot {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wattributes"
|
||||
|
||||
struct PgfPGF : public PgfPGFRoot {
|
||||
DB db;
|
||||
|
||||
PGF_INTERNAL_DECL PgfPGF(const char* fpath) : db(fpath) {};
|
||||
struct PgfPGF : DB {
|
||||
PGF_INTERNAL_DECL PgfPGF(const char* fpath) : DB(fpath) {};
|
||||
PGF_INTERNAL_DECL ~PgfPGF() {};
|
||||
|
||||
PGF_INTERNAL_DECL void set_root();
|
||||
};
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
@@ -309,6 +309,16 @@ DB::~DB() {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void DB::sync()
|
||||
{
|
||||
size_t size =
|
||||
current_db->ms->top + size + sizeof(size_t);
|
||||
|
||||
int res = msync((void *) current_db->ms, size, MS_SYNC | MS_INVALIDATE);
|
||||
if (res != 0)
|
||||
throw std::system_error(errno, std::generic_category());
|
||||
}
|
||||
|
||||
moffset DB::get_root_internal() {
|
||||
return ms->root_offset;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ public:
|
||||
current_db->set_root_internal(root.offset);
|
||||
}
|
||||
|
||||
static void sync();
|
||||
|
||||
private:
|
||||
void init_state(size_t size);
|
||||
|
||||
|
||||
@@ -33,9 +33,11 @@ PgfPGF *pgf_read(const char* fpath, PgfExn* err)
|
||||
}
|
||||
|
||||
PgfReader rdr(&in);
|
||||
rdr.read_pgf(pgf);
|
||||
ref<PgfPGFRoot> pgf_root = rdr.read_pgf();
|
||||
|
||||
pgf->set_root();
|
||||
pgf->set_root(pgf_root);
|
||||
|
||||
DB::sync();
|
||||
}
|
||||
|
||||
return pgf;
|
||||
@@ -53,13 +55,6 @@ PgfPGF *pgf_read(const char* fpath, PgfExn* err)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PgfPGF::set_root() {
|
||||
ref<PgfPGFRoot> root = DB::malloc<PgfPGFRoot>();
|
||||
root->major_version = major_version;
|
||||
root->minor_version = minor_version;
|
||||
DB::set_root(root);
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_free(PgfPGF *pgf)
|
||||
{
|
||||
@@ -69,5 +64,5 @@ void pgf_free(PgfPGF *pgf)
|
||||
PGF_API
|
||||
PgfText *pgf_abstract_name(PgfPGF* pgf)
|
||||
{
|
||||
return textdup(&(*pgf->abstract.name));
|
||||
return textdup(&(*pgf->get_root<PgfPGFRoot>()->abstract.name));
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ ref<PgfAbsCat> PgfReader::read_abscat()
|
||||
return abscat;
|
||||
}
|
||||
|
||||
void PgfReader::read_abstract(PgfAbstr* abstract)
|
||||
void PgfReader::read_abstract(ref<PgfAbstr> abstract)
|
||||
{
|
||||
abstract->name = read_name();
|
||||
abstract->aflags = read_namespace<PgfFlag>(&PgfReader::read_flag);
|
||||
@@ -415,12 +415,16 @@ void PgfReader::read_abstract(PgfAbstr* abstract)
|
||||
abstract->cats = read_namespace<PgfAbsCat>(&PgfReader::read_abscat);
|
||||
}
|
||||
|
||||
void PgfReader::read_pgf(PgfPGFRoot *pgf)
|
||||
ref<PgfPGFRoot> PgfReader::read_pgf()
|
||||
{
|
||||
ref<PgfPGFRoot> pgf = DB::malloc<PgfPGFRoot>();
|
||||
|
||||
pgf->major_version = read_u16be();
|
||||
pgf->minor_version = read_u16be();
|
||||
|
||||
pgf->gflags = read_namespace<PgfFlag>(&PgfReader::read_flag);
|
||||
|
||||
read_abstract(&pgf->abstract);
|
||||
read_abstract(ref<PgfAbstr>::from_ptr(&pgf->abstract));
|
||||
|
||||
return pgf;
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ public:
|
||||
|
||||
ref<PgfAbsFun> read_absfun();
|
||||
ref<PgfAbsCat> read_abscat();
|
||||
void read_abstract(PgfAbstr* abstract);
|
||||
void read_abstract(ref<PgfAbstr> abstract);
|
||||
|
||||
void read_pgf(PgfPGFRoot* pgf);
|
||||
ref<PgfPGFRoot> read_pgf();
|
||||
|
||||
private:
|
||||
std::istream *in;
|
||||
|
||||
Reference in New Issue
Block a user