From f609e8b93bcd96372e5fdc39440253ae56097107 Mon Sep 17 00:00:00 2001 From: vsc Date: Sun, 22 Feb 2004 00:35:07 +0000 Subject: [PATCH] check read locking on PRWLock git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1002 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 4 ++-- C/cdmgr.c | 47 +++++++++++++++++++++++------------------------ C/compiler.c | 1 + C/errors.c | 4 +++- C/exec.c | 9 +++++---- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index dd94978d6..34892283e 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -1443,11 +1443,11 @@ Yap_absmi(int inp) CUT_wait_leftmost(); #endif /* YAPOR */ /* need to make the DB stable until I get the new clause */ - READ_LOCK(((PredEntry *)(PREG->u.ld.p))->PRWLock); + READ_LOCK(PREG->u.ld.p->PRWLock); CACHE_Y(B); PREG = PREG->u.ld.d; LOCK(DynamicLock(PREG)); - READ_UNLOCK(((PredEntry *)(PREG->u.ld.p))->PRWLock); + READ_UNLOCK(PREG->u.ld.p->PRWLock); restore_yaam_regs(PREG); restore_args(PREG->u.ld.s); #ifdef FROZEN_STACKS diff --git a/C/cdmgr.c b/C/cdmgr.c index 082b194b2..65127970d 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -2035,11 +2035,13 @@ p_pred_exists(void) if (EndOfPAEntr(pe)) return FALSE; READ_LOCK(pe->PRWLock); - if (pe->PredFlags & HiddenPredFlag) - return(FALSE); + if (pe->PredFlags & HiddenPredFlag){ + READ_UNLOCK(pe->PRWLock); + return FALSE; + } out = (pe->OpcodeOfPred != UNDEF_OPCODE); READ_UNLOCK(pe->PRWLock); - return(out); + return out; } static Int @@ -2376,8 +2378,8 @@ search_for_static_predicate_in_use(PredEntry *p, int check_everything) } } } + READ_UNLOCK(pe->PRWLock); } - READ_UNLOCK(pe->PRWLock); env_ptr = b_ptr->cp_env; b_ptr = b_ptr->cp_b; } @@ -3142,6 +3144,12 @@ 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) + if (PP == pe) { + PP = NULL; + READ_UNLOCK(pe->PRWLock); + } +#endif #if defined(YAPOR) || defined(THREADS) WPP = NULL; #endif @@ -3210,18 +3218,10 @@ p_log_update_clause(void) WRITE_UNLOCK(pe->PRWLock); } #if defined(YAPOR) || defined(THREADS) - if (PP != pe) { - READ_LOCK(pe->PRWLock); - PP = pe; - } + READ_LOCK(pe->PRWLock); + PP = pe; #endif ret = fetch_next_lu_clause(pe, pe->cs.p_code.TrueCodeOfPred, t1, ARG3, ARG4, P, TRUE); -#if defined(YAPOR) || defined(THREADS) - if (PP == pe) { - PP = NULL; - READ_UNLOCK(pe->PRWLock); - } -#endif return ret; } @@ -3240,6 +3240,12 @@ 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) + if (PP == pe) { + PP = NULL; + READ_UNLOCK(pe->PRWLock); + } +#endif if (cl == NULL) { return FALSE; } @@ -3304,18 +3310,10 @@ p_log_update_clause0(void) IPred(pe); } #if defined(YAPOR) || defined(THREADS) - if (PP != pe) { - READ_LOCK(pe->PRWLock); - PP = pe; - } + READ_LOCK(pe->PRWLock); + PP = pe; #endif ret = fetch_next_lu_clause0(pe, pe->cs.p_code.TrueCodeOfPred, t1, ARG3, P, TRUE); -#if defined(YAPOR) || defined(THREADS) - if (PP == pe) { - PP = NULL; - READ_UNLOCK(pe->PRWLock); - } -#endif return ret; } @@ -3479,6 +3477,7 @@ add_code_in_pred(PredEntry *pp) { cl = ClauseCodeToStaticClause(clcode); code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp); + READ_UNLOCK(pp->PRWLock); return; } clcode = pp->cs.p_code.TrueCodeOfPred; diff --git a/C/compiler.c b/C/compiler.c index 9b259cf3f..4ba1ed74d 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -571,6 +571,7 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct READ_UNLOCK(cglobs->cint.CurrentPred->PRWLock); FAIL("can not compile data base reference",TYPE_ERROR_CALLABLE,t); } else { + READ_UNLOCK(cglobs->cint.CurrentPred->PRWLock); Yap_emit((cglobs->onhead ? get_atom_op : put_atom_op), (CELL) t, argno, &cglobs->cint); } } else { diff --git a/C/errors.c b/C/errors.c index 7f5bcc5e0..222af0e27 100644 --- a/C/errors.c +++ b/C/errors.c @@ -109,6 +109,7 @@ DumpActiveGoals (void) Functor f; Term mod = TermProlog; + READ_UNLOCK(pe->PRWLock); f = pe->FunctorOfPred; if (pe->KindOfPE && hidden (NameOfFunctor (f))) goto next; @@ -125,9 +126,10 @@ DumpActiveGoals (void) Yap_plwrite (MkIntTerm (ArityOfFunctor (f)), Yap_DebugPutc, 0); } Yap_DebugPutc (Yap_c_error_stream,'\n'); + } else { + READ_UNLOCK(pe->PRWLock); } next: - READ_UNLOCK(pe->PRWLock); ep = (CELL *) ep[E_E]; } first = 1; diff --git a/C/exec.c b/C/exec.c index 1ac5481be..cf40d569a 100644 --- a/C/exec.c +++ b/C/exec.c @@ -51,8 +51,10 @@ CallPredicate(PredEntry *pen, choiceptr cut_pt) { #ifdef DEPTH_LIMIT if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is prolog */ if (pen->ModuleOfPred) { - if (DEPTH == MkIntTerm(0)) + if (DEPTH == MkIntTerm(0)) { + READ_UNLOCK(pen->PRWLock); return FALSE; + } else DEPTH = RESET_DEPTH(); } } else if (pen->ModuleOfPred) @@ -1349,15 +1351,14 @@ Yap_RunTopGoal(Term t) ppe = RepPredProp(pe); if (pe != NIL) { READ_LOCK(ppe->PRWLock); - } - if (pe == NIL) { + } else if (pe == NIL) { /* we must always start the emulator with Prolog code */ return(FALSE); } + CodeAdr = ppe->CodeOfPred; if (pe != NIL) { READ_UNLOCK(ppe->PRWLock); } - CodeAdr = ppe->CodeOfPred; if (Yap_TrailTop - HeapTop < 2048) { Yap_PrologMode = BootMode; Yap_Error(SYSTEM_ERROR,TermNil,