From 18506025c31de45f0f1d57947f3875a460d4a06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Sun, 19 Oct 2014 01:48:38 +0100 Subject: [PATCH] use PP with care: - clean after interrupt; - use it only for indexing code. --- C/absmi.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- C/amasm.c | 27 +++++++-------------------- H/absmi.h | 2 ++ 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index a901084e2..0b2019cac 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -949,6 +949,7 @@ interrupt_execute( USES_REGS1 ) if ((v = check_alarm_fail_int( true PASS_REGS )) >= 0) { return v; } + if (PP) UNLOCKPE(1,PP); PP = P->y_u.pp.p0; if ((PP->ExtraPredFlags & (NoTracePredFlag|HiddenPredFlag)) && Yap_only_has_signal(YAP_CREEP_SIGNAL)) { return 2; @@ -975,6 +976,7 @@ interrupt_call( USES_REGS1 ) if ((v = check_alarm_fail_int( true PASS_REGS )) >= 0) { return v; } + if (PP) UNLOCKPE(1,PP); PP = P->y_u.Osbpp.p0; if (Yap_only_has_signal(YAP_CREEP_SIGNAL) && (PP->ExtraPredFlags & (NoTracePredFlag|HiddenPredFlag)) ) { @@ -1002,6 +1004,7 @@ interrupt_pexecute( PredEntry *pen USES_REGS ) if ((v = check_alarm_fail_int( 2 PASS_REGS )) >= 0) { return v; } + if (PP) UNLOCKPE(1,PP); PP = NULL; if (Yap_only_has_signal(YAP_CREEP_SIGNAL)) { return 2; /* keep on creeping */ @@ -1046,6 +1049,7 @@ interrupt_deallocate( USES_REGS1 ) } else { CELL cut_b = LCL0-(CELL *)(S[E_CB]); + if (PP) UNLOCKPE(1,PP); PP = PREVOP(P,p)->y_u.p.p; ASP = YENV+E_CB; /* cut_e */ @@ -1174,6 +1178,7 @@ interrupt_commit_x( USES_REGS1 ) if (Yap_only_has_signals(YAP_CDOVF_SIGNAL , YAP_CREEP_SIGNAL )) { return 2; } + if (PP) UNLOCKPE(1,PP); PP = P->y_u.xps.p0; /* find something to fool S */ if (P->opc == Yap_opcode(_fcall)) { @@ -1205,6 +1210,7 @@ interrupt_either( USES_REGS1 ) if (Yap_only_has_signal(YAP_CREEP_SIGNAL)) { return 2; } + if (PP) UNLOCKPE(1,PP); PP = P->y_u.Osblp.p0; /* find something to fool S */ SET_ASP(YENV, P->y_u.Osbpp.s); @@ -1229,6 +1235,7 @@ interrupt_dexecute( USES_REGS1 ) if (trace_interrupts) fprintf(stderr,"[%d] %lu--%lu %s/%d (YENV=%p ENV=%p ASP=%p)\n", worker_id, LOCAL_FirstActiveSignal, LOCAL_LastActiveSignal, \ __FUNCTION__, __LINE__,YENV,ENV,ASP); #endif + if (PP) UNLOCKPE(1,PP); PP = P->y_u.pp.p0; pe = P->y_u.pp.p; if ((PP->ExtraPredFlags & (NoTracePredFlag|HiddenPredFlag)) && Yap_only_has_signal(YAP_CREEP_SIGNAL)) { @@ -2042,6 +2049,13 @@ Yap_absmi(int inp) UInt timestamp; CACHE_Y(B); +#if defined(YAPOR) || defined(THREADS) + if (PP != PREG->y_u.OtaLl.d->ClPred) { + if (PP) UNLOCKPE(15,PP); + PP = PREG->y_u.OtaLl.d->ClPred; + PELOCK(15,PP); + } +#endif timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]); if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) { /* jump to next instruction */ @@ -2077,6 +2091,13 @@ Yap_absmi(int inp) LogUpdClause *lcl = PREG->y_u.OtILl.d; UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]); +#if defined(YAPOR) || defined(THREADS) + if (PP != ap) { + if (PP) UNLOCKPE(16,PP); + PP = ap; + PELOCK(16,PP); + } +#endif if (!VALID_TIMESTAMP(timestamp, lcl)) { /* jump to next alternative */ PREG = FAILCODE; @@ -2089,8 +2110,6 @@ Yap_absmi(int inp) /* HEY, leave indexing block alone!! */ /* check if we are the ones using this code */ #if MULTIPLE_STACKS - PELOCK(1, ap); - PP = ap; DEC_CLREF_COUNT(cl); /* clear the entry from the trail */ B->cp_tr--; @@ -2322,6 +2341,13 @@ Yap_absmi(int inp) UInt timestamp; CACHE_Y(B); +#if defined(YAPOR) || defined(THREADS) + if (PP != PREG->y_u.OtaLl.d->ClPred) { + if (PP) UNLOCKPE(15,PP); + PP = PREG->y_u.OtaLl.d->ClPred; + PELOCK(15,PP); + } +#endif timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[PREG->y_u.OtaLl.s]); if (!VALID_TIMESTAMP(timestamp, PREG->y_u.OtaLl.d)) { /* jump to next instruction */ @@ -2371,6 +2397,13 @@ Yap_absmi(int inp) LogUpdClause *lcl = PREG->y_u.OtILl.d; UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]); +#if defined(YAPOR) || defined(THREADS) + if (PP != ap) { + if (PP) UNLOCKPE(16,PP); + PP = ap; + PELOCK(16,PP); + } +#endif if (!VALID_TIMESTAMP(timestamp, lcl)) { /* jump to next alternative */ PREG = FAILCODE; @@ -2511,8 +2544,10 @@ Yap_absmi(int inp) /* lock logical updates predicate. */ Op(unlock_lu, e); #if defined(YAPOR) || defined(THREADS) - UNLOCKPE(1,PP); - PP = NULL; + if (PP) { + UNLOCKPE(1,PP); + PP = NULL; + } #endif PREG = NEXTOP(PREG, e); GONext(); @@ -8620,7 +8655,8 @@ Yap_absmi(int inp) CACHE_Y(B); #if defined(YAPOR) || defined(THREADS) - if (!PP) { + if (PP != PREG->y_u.OtaLl.d->ClPred) { + if (PP) UNLOCKPE(15,PP); PP = PREG->y_u.OtaLl.d->ClPred; PELOCK(15,PP); } @@ -8660,9 +8696,10 @@ Yap_absmi(int inp) /* fprintf(stderr,"- %p/%p %d %d %p\n",PREG,ap,timestamp,ap->TimeStampOfPred,PREG->y_u.OtILl.d->ClCode);*/ #if defined(YAPOR) || defined(THREADS) - if (!PP) { - PELOCK(16,ap); + if (PP != ap) { + if (PP) UNLOCKPE(16,PP); PP = ap; + PELOCK(16,PP); } #endif if (!VALID_TIMESTAMP(timestamp, lcl)) { diff --git a/C/amasm.c b/C/amasm.c index a897490d9..91ee19760 100755 --- a/C/amasm.c +++ b/C/amasm.c @@ -3054,6 +3054,13 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp code_p = a_try(_try_me, 0, LOCAL_IPredArity, code_p, pass_no, cip); #endif /* YAPOR */ } +#if THREADS||YAPOR + if (log_update) { + // separate from indexing code, + //clauses are protected by time-stamps + code_p = a_e(_unlock_lu, code_p, pass_no); + } +#endif } else { /* index code */ if (log_update) { @@ -3365,13 +3372,6 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp (*clause_has_blobsp || *clause_has_dbtermp) && !clinfo.alloc_found) code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip); -#if defined(THREADS) || defined(YAPOR) - else - if (cip->CurrentPred->PredFlags & LogUpdatePredFlag && - !(cip->CurrentPred->PredFlags & ThreadLocalPredFlag) && - !clinfo.alloc_found) - code_p = a_e(_unlock_lu, code_p, pass_no); -#endif code_p = a_cut(&clinfo, code_p, pass_no, cip); break; case allocate_op: @@ -3465,25 +3465,12 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp (*clause_has_blobsp || *clause_has_dbtermp) && !clinfo.alloc_found) code_p = a_cle(_alloc_for_logical_pred, code_p, pass_no, cip); -#if defined(THREADS) || defined(YAPOR) - else - if (cip->CurrentPred->PredFlags & LogUpdatePredFlag && - !(cip->CurrentPred->PredFlags & ThreadLocalPredFlag) && - !clinfo.alloc_found) - code_p = a_e(_unlock_lu, code_p, pass_no); -#endif code_p = a_pl(_procceed, cip->CurrentPred, code_p, pass_no); break; case call_op: code_p = a_p(_call, &clinfo, code_p, pass_no, cip); break; case execute_op: -#if defined(THREADS) || defined(YAPOR) - if (cip->CurrentPred->PredFlags & LogUpdatePredFlag && - !(cip->CurrentPred->PredFlags & ThreadLocalPredFlag) && - !clinfo.alloc_found) - code_p = a_e(_unlock_lu, code_p, pass_no); -#endif code_p = a_p(_execute, &clinfo, code_p, pass_no, cip); break; case safe_call_op: diff --git a/H/absmi.h b/H/absmi.h index 0f64282f5..9300a2485 100755 --- a/H/absmi.h +++ b/H/absmi.h @@ -1616,6 +1616,7 @@ prune(choiceptr cp USES_REGS) setregs(); \ SREG = Yap_REGS.S_; \ if (!d0) FAIL(); \ + PP = NULL;\ if (d0 == 2) goto C; \ JMPNext(); \ ENDD(d0); @@ -1625,6 +1626,7 @@ prune(choiceptr cp USES_REGS) saveregs(); \ d0 = F ( PASS_REGS1 );\ setregs(); \ + PP = NULL;\ if (!d0) FAIL(); \ if (d0 == 2) goto C; \ JMPNext(); \