we cannot trust that just having on reference will protect a clause. Several references may go in a single operation!

This commit is contained in:
Costa Vitor 2012-07-18 14:32:53 -05:00
parent d78a55ca83
commit c8ef4dbdb4
2 changed files with 25 additions and 7 deletions

View File

@ -1131,8 +1131,9 @@ Yap_absmi(int inp)
/* next, recover space for the indexing code if it was erased */
if (cl->ClFlags & (ErasedMask|DirtyMask)) {
if (PREG != FAILCODE) {
/* make sure we don't erase the clause we are jumping too */
if (lcl->ClRefCount == 1 && !(lcl->ClFlags & InUseMask)) {
/* make sure we don't erase the clause we are jumping to,
notice that we can erase a number of refs in one go. */
if (!(lcl->ClFlags & InUseMask)) {
lcl->ClFlags |= InUseMask;
TRAIL_CLREF(lcl);
}
@ -1439,7 +1440,7 @@ Yap_absmi(int inp)
if (cl->ClFlags & (ErasedMask|DirtyMask)) {
if (PREG != FAILCODE) {
/* make sure we don't erase the clause we are jumping too */
if (lcl->ClRefCount == 1 && !(lcl->ClFlags & InUseMask)) {
if (!(lcl->ClFlags & InUseMask)) {
lcl->ClFlags |= InUseMask;
TRAIL_CLREF(lcl);
}
@ -8066,7 +8067,7 @@ Yap_absmi(int inp)
if (cl->ClFlags & (ErasedMask|DirtyMask)) {
if (PREG != FAILCODE) {
/* make sure we don't erase the clause we are jumping too */
if (lcl->ClRefCount == 1 && !(lcl->ClFlags & InUseMask)) {
if (!(lcl->ClFlags & InUseMask)) {
lcl->ClFlags |= InUseMask;
TRAIL_CLREF(lcl);
B->cp_tr = TR;

View File

@ -6306,13 +6306,27 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
/* actually get rid of the code */
if (cl->ClRefCount == 0 && cl->ClFlags & (ErasedMask|DirtyMask)) {
/* I am the last one using this clause, hence I don't need a lock
to dispose of it
to dispose of it. But on the other hand I need to make sure
the clause is still there when I am back.
*/
LogUpdClause *lcl = ipc->u.OtILl.d;
if (newpc) {
/* I am the last one using this clause, hence I don't need a lock
to dispose of it
*/
/* make sure the clause isn't destroyed */
/* always add an extra reference */
INC_CLREF_COUNT(lcl);
TRAIL_CLREF(lcl);
}
if (cl->ClFlags & ErasedMask) {
Yap_ErLogUpdIndex(cl);
} else {
Yap_CleanUpIndex(cl);
}
if (newpc) {
DEC_CLREF_COUNT(lcl);
}
}
#else
if (TrailTerm(B->cp_tr-1) == CLREF_TO_TRENTRY(cl) &&
@ -6324,8 +6338,11 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
/* next, recover space for the indexing code if it was erased */
if (cl->ClFlags & (ErasedMask|DirtyMask)) {
LogUpdClause *lcl = ipc->u.OtILl.d;
/* make sure we don't erase the clause we are jumping to */
if (lcl->ClRefCount == 1 && !(lcl->ClFlags & (DirtyMask|InUseMask))) {
/* make sure we don't erase the clause we are jumping to, notice that
ErLogUpdIndex may remove several references in one go.
Notice we only need to do this if we´ re jumping to the clause.
*/
if (newpc && !(lcl->ClFlags & (DirtyMask|InUseMask))) {
lcl->ClFlags |= InUseMask;
TRAIL_CLREF(lcl);
}