mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
implemented pgf_free_revision
This commit is contained in:
@@ -312,14 +312,23 @@ PgfDB::PgfDB(const char* filepath, int flags, int mode) {
|
|||||||
if (ms == MAP_FAILED)
|
if (ms == MAP_FAILED)
|
||||||
throw pgf_systemerror(errno, filepath);
|
throw pgf_systemerror(errno, filepath);
|
||||||
|
|
||||||
if (is_new) {
|
|
||||||
init_state(file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
int res = pthread_rwlock_init(&rwlock, NULL);
|
int res = pthread_rwlock_init(&rwlock, NULL);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
throw pgf_systemerror(errno);
|
throw pgf_systemerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_new) {
|
||||||
|
init_state(file_size);
|
||||||
|
} else {
|
||||||
|
// We must make sure that left-over transient revisions are
|
||||||
|
// released. This may happen if a client process was killed
|
||||||
|
// or if the garbadge collector has not managed to run
|
||||||
|
// pgf_release_revision() before the process ended.
|
||||||
|
|
||||||
|
while (ms->transient_revisions != 0) {
|
||||||
|
pgf_free_revision(this, ms->transient_revisions.as_object());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
@@ -994,14 +1003,18 @@ void PgfDB::link_transient_revision(ref<PgfPGF> pgf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_INTERNAL
|
PGF_INTERNAL
|
||||||
void PgfDB::unlink_transient_revision(ref<PgfPGF> pgf)
|
bool PgfDB::unlink_transient_revision(ref<PgfPGF> pgf)
|
||||||
{
|
{
|
||||||
if (pgf->next != 0)
|
if (pgf->next != 0)
|
||||||
pgf->next->prev = pgf->prev;
|
pgf->next->prev = pgf->prev;
|
||||||
if (pgf->prev != 0)
|
if (pgf->prev != 0)
|
||||||
pgf->prev->next = pgf->next;
|
pgf->prev->next = pgf->next;
|
||||||
else
|
else if (current_db->ms->transient_revisions == pgf)
|
||||||
current_db->ms->transient_revisions = pgf->next;
|
current_db->ms->transient_revisions = pgf->next;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DB_scope::DB_scope(PgfDB *db, DB_scope_mode tp)
|
DB_scope::DB_scope(PgfDB *db, DB_scope_mode tp)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public:
|
|||||||
static PGF_INTERNAL_DECL void set_revision(ref<PgfPGF> pgf);
|
static PGF_INTERNAL_DECL void set_revision(ref<PgfPGF> pgf);
|
||||||
static PGF_INTERNAL_DECL ref<PgfPGF> revision2pgf(PgfRevision revision);
|
static PGF_INTERNAL_DECL ref<PgfPGF> revision2pgf(PgfRevision revision);
|
||||||
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 bool unlink_transient_revision(ref<PgfPGF> pgf);
|
||||||
|
|
||||||
PGF_INTERNAL_DECL static void sync();
|
PGF_INTERNAL_DECL static void sync();
|
||||||
|
|
||||||
|
|||||||
@@ -156,8 +156,23 @@ void pgf_free(PgfDB *db)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_free_revision(PgfDB *pgf, PgfRevision revision)
|
void pgf_free_revision(PgfDB *db, PgfRevision revision)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
DB_scope scope(db, READER_SCOPE);
|
||||||
|
ref<PgfPGF> pgf = PgfDB::revision2pgf(revision);
|
||||||
|
|
||||||
|
if (PgfDB::unlink_transient_revision(pgf)) {
|
||||||
|
namespace_release(pgf->gflags);
|
||||||
|
PgfDB::free(pgf->abstract.name);
|
||||||
|
namespace_release(pgf->abstract.aflags);
|
||||||
|
namespace_release(pgf->abstract.funs);
|
||||||
|
namespace_release(pgf->abstract.cats);
|
||||||
|
PgfDB::free(pgf);
|
||||||
|
}
|
||||||
|
} catch (std::runtime_error& e) {
|
||||||
|
// silently ignore and hope for the best
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
|
|||||||
Reference in New Issue
Block a user