clause should not do write locking
expand_index should not care whether read_locks are held. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@996 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
6031b7f049
commit
d3f49b75df
33
C/absmi.c
33
C/absmi.c
@ -1105,9 +1105,6 @@ Yap_absmi(int inp)
|
||||
saveregs();
|
||||
{
|
||||
yamop *ipc;
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
PredEntry *ap = PP;
|
||||
#endif
|
||||
|
||||
/* update ASP before calling IPred */
|
||||
ASP = YREG+E_CB;
|
||||
@ -1115,19 +1112,20 @@ Yap_absmi(int inp)
|
||||
ASP = (CELL *) B;
|
||||
}
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
READ_UNLOCK(ap->PRWLock);
|
||||
PP = NULL;
|
||||
LOCK(pe->PELock);
|
||||
if (*PREG_ADDR != PREG) {
|
||||
PREG = *PREG_ADDR;
|
||||
UNLOCK(pe->PELock);
|
||||
JMPNext();
|
||||
}
|
||||
#endif
|
||||
ipc = Yap_CleanUpIndex(PREG->u.Ill.I);
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
/* restart index */
|
||||
setregs();
|
||||
PREG = ipc;
|
||||
if (PREG == NULL) FAIL();
|
||||
CACHED_A1() = ARG1;
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
PP = ap;
|
||||
READ_LOCK(ap->PRWLock);
|
||||
#endif
|
||||
JMPNext();
|
||||
}
|
||||
ENDBOp();
|
||||
@ -6361,28 +6359,17 @@ Yap_absmi(int inp)
|
||||
}
|
||||
saveregs();
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
if (PP != pe) {
|
||||
READ_LOCK(pe->PRWLock);
|
||||
}
|
||||
LOCK(pe->PELock);
|
||||
if (*PREG_ADDR != (yamop *)&(pe->cs.p_code.ExpandCode)) {
|
||||
pt0 = *PREG_ADDR;
|
||||
if (*PREG_ADDR != PREG)) {
|
||||
PREG = *PREG_ADDR;
|
||||
UNLOCK(pe->PELock);
|
||||
if (PP != pe) {
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
}
|
||||
JMPNext();
|
||||
}
|
||||
#endif
|
||||
pt0 = Yap_ExpandIndex(pe);
|
||||
/* restart index */
|
||||
setregs();
|
||||
UNLOCK(pe->PELock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
if (PP != pe) {
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
}
|
||||
#endif
|
||||
setregs();
|
||||
PREG = pt0;
|
||||
JMPNext();
|
||||
}
|
||||
|
59
C/cdmgr.c
59
C/cdmgr.c
@ -3051,10 +3051,7 @@ fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, ya
|
||||
|
||||
cl = Yap_FollowIndexingCode(pe, i_code, th, tb, tr, NEXTOP(PredLogUpdClause->CodeOfPred,ld), cp_ptr);
|
||||
if (cl == NULL) {
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = NULL;
|
||||
#endif
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
return FALSE;
|
||||
}
|
||||
rtn = MkDBRefTerm((DBRef)cl);
|
||||
@ -3069,10 +3066,7 @@ fetch_next_lu_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr, ya
|
||||
TRAIL_CLREF(cl); /* So that fail will erase it */
|
||||
}
|
||||
#endif
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = NULL;
|
||||
#endif
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
if (cl->ClFlags & FactMask) {
|
||||
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
|
||||
!Yap_unify(tr, rtn))
|
||||
@ -3128,10 +3122,7 @@ p_log_update_clause(void)
|
||||
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
||||
if (pe == NULL || EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = pe;
|
||||
#endif
|
||||
READ_LOCK(pe->PRWLock);
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
IPred(pe);
|
||||
}
|
||||
@ -3144,10 +3135,7 @@ p_continue_log_update_clause(void)
|
||||
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
||||
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
||||
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = pe;
|
||||
#endif
|
||||
READ_LOCK(pe->PRWLock);
|
||||
return fetch_next_lu_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
|
||||
}
|
||||
|
||||
@ -3157,10 +3145,7 @@ fetch_next_lu_clause0(PredEntry *pe, yamop *i_code, Term th, Term tb, yamop *cp_
|
||||
LogUpdClause *cl;
|
||||
|
||||
cl = Yap_FollowIndexingCode(pe, i_code, th, tb, TermNil, NEXTOP(PredLogUpdClause0->CodeOfPred,ld), cp_ptr);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = NULL;
|
||||
#endif
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
if (cl == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -3217,10 +3202,7 @@ p_log_update_clause0(void)
|
||||
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
||||
if (pe == NULL || EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = pe;
|
||||
#endif
|
||||
READ_LOCK(pe->PRWLock);
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
IPred(pe);
|
||||
}
|
||||
@ -3233,10 +3215,7 @@ p_continue_log_update_clause0(void)
|
||||
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
||||
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
||||
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = pe;
|
||||
#endif
|
||||
READ_LOCK(pe->PRWLock);
|
||||
return fetch_next_lu_clause0(pe, ipc, Deref(ARG3), ARG4, B->cp_ap, FALSE);
|
||||
}
|
||||
|
||||
@ -3247,7 +3226,6 @@ fetch_next_static_clause(PredEntry *pe, yamop *i_code, Term th, Term tb, Term tr
|
||||
Term rtn;
|
||||
|
||||
cl = (StaticClause *)Yap_FollowIndexingCode(pe, i_code, th, tb, tr, NEXTOP(PredStaticClause->CodeOfPred,ld), cp_ptr);
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
if (cl == NULL)
|
||||
return FALSE;
|
||||
rtn = MkDBRefTerm((DBRef)cl);
|
||||
@ -3305,7 +3283,6 @@ p_static_clause(void)
|
||||
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
||||
if (pe == NULL || EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
IPred(pe);
|
||||
}
|
||||
@ -3327,14 +3304,21 @@ p_nth_clause(void)
|
||||
pe = get_pred(t1, Deref(ARG2), "clause/3");
|
||||
if (pe == NULL || EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
WPP = pe;
|
||||
#endif
|
||||
if (!(pe->PredFlags & (SourcePredFlag|LogUpdatePredFlag))) {
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
IPred(pe);
|
||||
}
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
}
|
||||
READ_LOCK(pe->PRWLock);
|
||||
if (!(pe->PredFlags & (SourcePredFlag|LogUpdatePredFlag))) {
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
return FALSE;
|
||||
}
|
||||
if (pe->PredFlags & SourcePredFlag) {
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
}
|
||||
/* in case we have to index or to expand code */
|
||||
if (pe->ModuleOfPred != IDB_MODULE) {
|
||||
UInt i;
|
||||
@ -3345,10 +3329,10 @@ p_nth_clause(void)
|
||||
} else {
|
||||
XREGS[2] = MkVarTerm();
|
||||
}
|
||||
if(pe->OpcodeOfPred == INDEX_OPCODE) {
|
||||
IPred(pe);
|
||||
}
|
||||
cl = Yap_NthClause(pe, ncls);
|
||||
if (pe->PredFlags & LogUpdatePredFlag) {
|
||||
READ_UNLOCK(pe->PRWLock);
|
||||
}
|
||||
if (cl == NULL)
|
||||
return FALSE;
|
||||
if (cl->ClFlags & LogUpdatePredFlag) {
|
||||
@ -3373,7 +3357,6 @@ p_continue_static_clause(void)
|
||||
PredEntry *pe = (PredEntry *)IntegerOfTerm(Deref(ARG1));
|
||||
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
|
||||
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
return fetch_next_static_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
|
||||
}
|
||||
|
||||
|
44
C/index.c
44
C/index.c
@ -6382,6 +6382,14 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
|
||||
ipc = NEXTOP(ipc,l);
|
||||
break;
|
||||
case _stale_lu_index:
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
LOCK(ap->PELock);
|
||||
if (*jbl != ipc) {
|
||||
ipc = *jbl;
|
||||
UNLOCK(ap->PELock);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
while (TRUE) {
|
||||
yamop *nipc = clean_up_index(ipc->u.Ill.I, jlbl, ap);
|
||||
if (nipc == NULL) {
|
||||
@ -6391,6 +6399,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
|
||||
H[2] = tr;
|
||||
H += 3;
|
||||
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
|
||||
UNLOCK(ap->PELock);
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return NULL;
|
||||
}
|
||||
@ -6399,6 +6408,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
|
||||
tb = H[1];
|
||||
tr = H[2];
|
||||
} else {
|
||||
UNLOCK(ap->PELock);
|
||||
ipc = nipc;
|
||||
break;
|
||||
}
|
||||
@ -6574,7 +6584,16 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
|
||||
}
|
||||
break;
|
||||
case _expand_index:
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
LOCK(ap->PELock);
|
||||
if (*jbl != ipc) {
|
||||
ipc = *jbl;
|
||||
UNLOCK(ap->PELock);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ipc = ExpandIndex(ap);
|
||||
UNLOCK(pe->PELock);
|
||||
break;
|
||||
case _op_fail:
|
||||
/*
|
||||
@ -6629,12 +6648,6 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
|
||||
abolish_incomplete_subgoals(B);
|
||||
#endif /* TABLING */
|
||||
}
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
if (PP == ap) {
|
||||
PP = NULL;
|
||||
READ_UNLOCK(ap->PRWLock);
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -6736,15 +6749,25 @@ Yap_NthClause(PredEntry *ap, Int ncls)
|
||||
case _trust_logical_pred:
|
||||
ipc = NEXTOP(ipc,l);
|
||||
case _stale_lu_index:
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
LOCK(ap->PELock);
|
||||
if (*jbl != ipc) {
|
||||
ipc = *jbl;
|
||||
UNLOCK(ap->PELock);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
while (TRUE) {
|
||||
yamop *nipc = clean_up_index(ipc->u.Ill.I, jlbl, ap);
|
||||
if (nipc == NULL) {
|
||||
/* not enough space */
|
||||
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
|
||||
UNLOCK(ap->PELock);
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
UNLOCK(ap->PELock);
|
||||
ipc = nipc;
|
||||
break;
|
||||
}
|
||||
@ -6789,7 +6812,16 @@ Yap_NthClause(PredEntry *ap, Int ncls)
|
||||
ipc = ipc->u.clll.l3;
|
||||
break;
|
||||
case _expand_index:
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
LOCK(ap->PELock);
|
||||
if (*jbl != (yamop *)&(ap->cs.p_code.ExpandCode)) {
|
||||
ipc = *jbl;
|
||||
UNLOCK(pe->PELock);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ipc = ExpandIndex(ap);
|
||||
UNLOCK(ap->PELock);
|
||||
break;
|
||||
case _op_fail:
|
||||
ipc = alt;
|
||||
|
Reference in New Issue
Block a user