From 14b67dc76db1fe0f44642b83749785c7e90fa91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 20 Dec 2012 21:33:20 +0000 Subject: [PATCH] fix threads --- C/adtdefs.c | 18 ++++++++++++------ C/amasm.c | 5 ++++- C/dbase.c | 11 +++++++---- C/exec.c | 2 +- C/index.c | 5 ++++- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/C/adtdefs.c b/C/adtdefs.c index 30f404c9f..922001d91 100755 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -851,9 +851,12 @@ Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod) } p->FunctorOfPred = fe; WRITE_UNLOCK(fe->FRWLock); - Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred)+1, p, GPROF_NEW_PRED_FUNC); - if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) { - Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode), &(p->cs.p_code.ExpandCode)+1, p, GPROF_NEW_PRED_FUNC); + { + CACHE_REGS + Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred)+1, p, GPROF_NEW_PRED_FUNC); + if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) { + Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode), &(p->cs.p_code.ExpandCode)+1, p, GPROF_NEW_PRED_FUNC); + } } return AbsPredProp(p); } @@ -962,9 +965,12 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod) p0 = AbsPredProp(p); p->FunctorOfPred = (Functor)AbsAtom(ae); WRITE_UNLOCK(ae->ARWLock); - Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred)+1, p, GPROF_NEW_PRED_ATOM); - if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) { - Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode), &(p->cs.p_code.ExpandCode)+1, p, GPROF_NEW_PRED_ATOM); + { + CACHE_REGS + Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred)+1, p, GPROF_NEW_PRED_ATOM); + if (!(p->PredFlags & (CPredFlag|AsmPredFlag))) { + Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode), &(p->cs.p_code.ExpandCode)+1, p, GPROF_NEW_PRED_ATOM); + } } return p0; } diff --git a/C/amasm.c b/C/amasm.c index 62223ed11..7bd09e56c 100755 --- a/C/amasm.c +++ b/C/amasm.c @@ -2056,7 +2056,10 @@ a_try(op_numbers opcode, CELL lab, CELL opr, int nofalts, int hascut, yamop *cod save_machine_regs(); siglongjmp(cip->CompilerBotch,2); } - Yap_inform_profiler_of_clause(newcp, (char *)(newcp)+size, ap, GPROF_INDEX); + { + CACHE_REGS + Yap_inform_profiler_of_clause(newcp, (char *)(newcp)+size, ap, GPROF_INDEX); + } Yap_LUIndexSpace_CP += size; #ifdef DEBUG Yap_NewCps++; diff --git a/C/dbase.c b/C/dbase.c index 69cf50f9c..99438d338 100755 --- a/C/dbase.c +++ b/C/dbase.c @@ -1892,7 +1892,10 @@ record_lu(PredEntry *pe, Term t, int position) if ((cl = new_lu_db_entry(t, pe)) == NULL) { return NULL; } - Yap_inform_profiler_of_clause(cl, (char *)cl+cl->ClSize, pe, GPROF_NEW_LU_CLAUSE); + { + CACHE_REGS + Yap_inform_profiler_of_clause(cl, (char *)cl+cl->ClSize, pe, GPROF_NEW_LU_CLAUSE); + } Yap_add_logupd_clause(pe, cl, (position == MkFirst ? 2 : 0)); return cl; } @@ -4429,7 +4432,7 @@ p_increase_reference_counter( USES_REGS1 ) cl = (LogUpdClause *)DBRefOfTerm(t1); PELOCK(67,cl->ClPred); cl->ClRefCount++; - UNLOCK(cl->ClPred); + UNLOCK(cl->ClPred->PELock); return TRUE; } @@ -4452,10 +4455,10 @@ p_decrease_reference_counter( USES_REGS1 ) PELOCK(67,cl->ClPred); if (cl->ClRefCount) { cl->ClRefCount--; - UNLOCK(cl->ClPred); + UNLOCK(cl->ClPred->PELock); return TRUE; } - UNLOCK(cl->ClPred); + UNLOCK(cl->ClPred->PELock); return FALSE; } diff --git a/C/exec.c b/C/exec.c index c4c8628d0..6befeace0 100644 --- a/C/exec.c +++ b/C/exec.c @@ -1736,7 +1736,7 @@ Yap_InitYaamRegs( int myworker_id ) Yap_ResetExceptionTerm ( myworker_id ); Yap_PutValue (AtomBreak, MkIntTerm (0)); TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id); - H = H0 = ((CELL *) REMOTE_GlobalBase(myworker_id))+1; + H = H0 = ((CELL *) REMOTE_GlobalBase(myworker_id))+1; // +1: hack to ensure the gc does not try to mark mistakenly LCL0 = ASP = (CELL *) REMOTE_LocalBase(myworker_id); CurrentTrailTop = (tr_fr_ptr)(REMOTE_TrailTop(myworker_id)-MinTrailGap); /* notice that an initial choice-point and environment diff --git a/C/index.c b/C/index.c index b7b65e7f8..252d56409 100755 --- a/C/index.c +++ b/C/index.c @@ -1923,7 +1923,10 @@ suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermedi } else { Yap_IndexSpace_EXT += sz; } - Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode+sz, ap, GPROF_NEW_EXPAND_BLOCK); + { + CACHE_REGS + Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode+sz, ap, GPROF_NEW_EXPAND_BLOCK); + } /* create an expand_block */ ncode->opc = Yap_opcode(_expand_clauses); ncode->u.sssllp.p = ap;