a few more fixes, and we're done with threads (for now) ;-).

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@980 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-02-11 16:18:16 +00:00
parent e612cb2f84
commit 08fe01ad98
5 changed files with 57 additions and 14 deletions

View File

@ -6329,7 +6329,6 @@ Yap_absmi(int inp)
setregs();
CACHED_A1() = ARG1;
PREG = ap->CodeOfPred;
WPP = NULL;
WRITE_UNLOCK(ap->PRWLock);
}
JMPNext();

View File

@ -1053,7 +1053,9 @@ addclause(Term t, yamop *cp, int mode, int mod)
}
Yap_PutValue(AtomAbol, TermNil);
WRITE_LOCK(p->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = p;
#endif
pflags = p->PredFlags;
/* we are redefining a prolog module predicate */
if (p->ModuleOfPred == 0 && mod != 0) {
@ -1073,7 +1075,9 @@ addclause(Term t, yamop *cp, int mode, int mod)
not_was_reconsulted(p, t, TRUE);
/* always check if we have a valid error first */
if (Yap_ErrorMessage && Yap_Error_TYPE == PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE) {
#if defined(YAPOR) || defined(THREADS)
WPP = NULL;
#endif
WRITE_UNLOCK(p->PRWLock);
return TermNil;
}
@ -1127,7 +1131,9 @@ addclause(Term t, yamop *cp, int mode, int mod)
p->OpcodeOfPred = ((yamop *)(p->CodeOfPred))->opc;
}
}
#if defined(YAPOR) || defined(THREADS)
WPP = NULL;
#endif
WRITE_UNLOCK(p->PRWLock);
if (pflags & LogUpdatePredFlag) {
return MkDBRefTerm((DBRef)ClauseCodeToLogUpdClause(cp));
@ -1608,15 +1614,21 @@ p_purge_clauses(void)
} else
return (FALSE);
WRITE_LOCK(pred->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pred;
#endif
if (pred->PredFlags & StandardPredFlag) {
#if defined(YAPOR) || defined(THREADS)
WPP = NULL;
#endif
WRITE_UNLOCK(pred->PRWLock);
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, t, "assert/1");
return (FALSE);
}
purge_clauses(pred);
#if defined(YAPOR) || defined(THREADS)
WPP = NULL;
#endif
WRITE_UNLOCK(pred->PRWLock);
return (TRUE);
}
@ -1714,9 +1726,12 @@ p_rmspy(void)
WRITE_UNLOCK(pred->PRWLock);
return (FALSE);
}
#if THREADS
if (!(pred->PredFlags & ThreadLocalPredFlag)) {
pred->OpcodeOfPred = Yap_opcode(_thread_local);
} else if (!(pred->PredFlags & DynamicPredFlag)) {
} else
#endif
if (!(pred->PredFlags & DynamicPredFlag)) {
pred->CodeOfPred = pred->cs.p_code.TrueCodeOfPred;
pred->OpcodeOfPred = ((yamop *)(pred->CodeOfPred))->opc;
} else if (pred->OpcodeOfPred == Yap_opcode(_spy_or_trymark)) {
@ -3066,7 +3081,9 @@ 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);
return FALSE;
}
@ -3082,7 +3099,9 @@ 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);
if (cl->ClFlags & FactMask) {
if (!Yap_unify(tb, MkAtomTerm(AtomTrue)) ||
@ -3140,7 +3159,9 @@ p_log_update_clause(void)
if (pe == NULL || EndOfPAEntr(pe))
return FALSE;
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
if(pe->OpcodeOfPred == INDEX_OPCODE) {
IPred(pe);
}
@ -3154,7 +3175,9 @@ p_continue_log_update_clause(void)
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
return fetch_next_lu_clause(pe, ipc, Deref(ARG3), ARG4, ARG5, B->cp_ap, FALSE);
}
@ -3164,7 +3187,9 @@ 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);
if (cl == NULL) {
return FALSE;
@ -3223,7 +3248,9 @@ p_log_update_clause0(void)
if (pe == NULL || EndOfPAEntr(pe))
return FALSE;
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
if(pe->OpcodeOfPred == INDEX_OPCODE) {
IPred(pe);
}
@ -3237,7 +3264,9 @@ p_continue_log_update_clause0(void)
yamop *ipc = (yamop *)IntegerOfTerm(ARG2);
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
return fetch_next_lu_clause0(pe, ipc, Deref(ARG3), ARG4, B->cp_ap, FALSE);
}
@ -3329,7 +3358,9 @@ p_nth_clause(void)
if (pe == NULL || EndOfPAEntr(pe))
return FALSE;
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
if (!(pe->PredFlags & (SourcePredFlag|LogUpdatePredFlag))) {
WRITE_UNLOCK(pe->PRWLock);
return FALSE;

View File

@ -1836,9 +1836,13 @@ record_lu(PredEntry *pe, Term t, int position)
else
ipc->opc = Yap_opcode(_unify_idb_term);
WRITE_LOCK(pe->PRWLock);
#if defined(YAPOR) || defined(THREADS)
WPP = pe;
#endif
Yap_add_logupd_clause(pe, cl, (position == MkFirst ? 2 : 0));
#if defined(YAPOR) || defined(THREADS)
WPP = NULL;
#endif
WRITE_UNLOCK(pe->PRWLock);
return cl;
}
@ -3848,9 +3852,11 @@ static void
EraseLogUpdCl(LogUpdClause *clau)
{
PredEntry *ap = clau->ClPred;
#if defined(YAPOR) || defined(THREADS)
if (WPP != ap) {
WRITE_LOCK(ap->PRWLock);
}
#endif
/* no need to erase what has been erased */
if (!(clau->ClFlags & ErasedMask)) {
@ -3897,9 +3903,11 @@ EraseLogUpdCl(LogUpdClause *clau)
clau->ClRefCount--;
}
complete_lu_erase(clau);
#if defined(YAPOR) || defined(THREADS)
if (WPP != ap) {
WRITE_UNLOCK(ap->PRWLock);
}
#endif
}
static void
@ -3974,9 +3982,11 @@ PrepareToEraseLogUpdClause(LogUpdClause *clau, DBRef dbr)
if (clau->ClFlags & ErasedMask)
return;
clau->ClFlags |= ErasedMask;
#if defined(YAPOR) || defined(THREADS)
if (WPP != p) {
WRITE_LOCK(p->PRWLock);
}
#endif
if (p->cs.p_code.FirstClause != cl) {
/* we are not the first clause... */
yamop *prev_code_p = (yamop *)(dbr->Prev->Code);
@ -4026,9 +4036,11 @@ PrepareToEraseLogUpdClause(LogUpdClause *clau, DBRef dbr)
p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
}
}
#if defined(YAPOR) || defined(THREADS)
if (WPP != p) {
WRITE_UNLOCK(p->PRWLock);
}
#endif
}
static void
@ -4905,6 +4917,7 @@ Yap_ReleaseTermFromDB(DBTerm *ref)
static Int
p_install_thread_local(void)
{ /* '$is_dynamic'(+P) */
#if THREADS
PredEntry *pe;
Term t = Deref(ARG1);
Term t2 = Deref(ARG2);
@ -4941,6 +4954,7 @@ p_install_thread_local(void)
pe->OpcodeOfPred = Yap_opcode(_thread_local);
pe->CodeOfPred = (yamop *)&pe->OpcodeOfPred;
WRITE_UNLOCK(pe->PRWLock);
#endif
return TRUE;
}

View File

@ -6556,12 +6556,12 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr, yam
case _unlock_lu:
ipc = NEXTOP(ipc,e);
break;
case _thread_local:
#if THREADS
case _thread_local:
ap = Yap_GetThreadPred(ap);
ipc = ap->CodeOfPred;
#endif
break;
#endif
case _index_pred:
case _spy_pred:
Yap_IPred(ap);

View File

@ -18,14 +18,6 @@
static char SccsId[] = "%W% %G%";
#endif
#if THREADS
/*
* This file includes the definition of threads in Yap. Threads
* are supposed to be compatible with the SWI-Prolog thread package.
*
*/
#include "Yap.h"
#include "Yatom.h"
#include "Heap.h"
@ -36,6 +28,14 @@ static char SccsId[] = "%W% %G%";
#include <string.h>
#endif
#if THREADS
/*
* This file includes the definition of threads in Yap. Threads
* are supposed to be compatible with the SWI-Prolog thread package.
*
*/
static int
allocate_new_tid(void)
{
@ -402,7 +402,6 @@ void Yap_InitThreadPreds(void)
#else
static Int
p_no_threads(void)
{ /* '$thread_signal'(+P) */
@ -411,7 +410,7 @@ p_no_threads(void)
void Yap_InitThreadPreds(void)
{
Yap_InitCPred("$no_threads", 0, p_create_thread, 0);
Yap_InitCPred("$no_threads", 0, p_no_threads, 0);
}