protect writes to SignalMask and to CreepFlag. Reads are still not
locked. fix XREGS for threads. fix thread_signal not even being defined. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@969 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
a5b6a22f27
commit
ca4e754af7
18
C/absmi.c
18
C/absmi.c
@ -212,7 +212,7 @@ Yap_absmi(int inp)
|
||||
|
||||
/* the registers are all set up, let's swap */
|
||||
#ifdef THREADS
|
||||
pthread_setspecific(yaamregs_key, (const void *)&absmi_regs);
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)&absmi_regs);
|
||||
ThreadHandle[worker_id].current_yaam_regs = &absmi_regs;
|
||||
#else
|
||||
Yap_regp = &absmi_regs;
|
||||
@ -2456,8 +2456,10 @@ Yap_absmi(int inp)
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
/* I need this for Windows and other systems where SIGINT
|
||||
is not proceesed by same thread as absmi */
|
||||
LOCK(SignalLock);
|
||||
if (Yap_PrologMode & (AbortMode|InterruptMode)) {
|
||||
CFREG = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
/* same instruction */
|
||||
if (Yap_PrologMode & InterruptMode) {
|
||||
Yap_PrologMode &= ~InterruptMode;
|
||||
@ -2470,6 +2472,7 @@ Yap_absmi(int inp)
|
||||
}
|
||||
JMPNext();
|
||||
}
|
||||
UNLOCK(SignalLock);
|
||||
#endif
|
||||
#if SHADOW_S
|
||||
S = SREG;
|
||||
@ -2520,23 +2523,26 @@ Yap_absmi(int inp)
|
||||
ARG1 = (Term) AbsPair(H);
|
||||
|
||||
H += 2;
|
||||
LOCK(SignalLock);
|
||||
CFREG = CalculateStackGap();
|
||||
#ifdef COROUTINING
|
||||
if (ActiveSignals & YAP_WAKEUP_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_WAKEUP_SIGNAL;
|
||||
UNLOCK(SignalLock);
|
||||
ARG2 = Yap_ListOfWokenGoals();
|
||||
SREG = (CELL *) (WakeUpCode);
|
||||
/* no more goals to wake up */
|
||||
Yap_UpdateTimedVar(WokenGoals, TermNil);
|
||||
ActiveSignals &= ~YAP_WAKEUP_SIGNAL;
|
||||
} else
|
||||
#endif
|
||||
SREG = (CELL *) CreepCode;
|
||||
CFREG = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
#ifdef LOW_LEVEL_TRACER
|
||||
if (Yap_do_low_level_trace)
|
||||
low_level_trace(enter_pred,(PredEntry *)(SREG),XREGS+1);
|
||||
#endif /* LOW_LEVEL_TRACE */
|
||||
PREG = ((PredEntry *)(SREG))->CodeOfPred;
|
||||
CFREG = CalculateStackGap();
|
||||
CACHE_A1();
|
||||
JMPNext();
|
||||
|
||||
@ -6433,7 +6439,6 @@ Yap_absmi(int inp)
|
||||
{
|
||||
Prop p = Yap_GetPredPropByFunc(Yap_MkFunctor(at, 1),0);
|
||||
if (p == NIL) {
|
||||
CFREG = CalculateStackGap();
|
||||
FAIL();
|
||||
} else {
|
||||
PredEntry *undefpe;
|
||||
@ -6445,7 +6450,6 @@ Yap_absmi(int inp)
|
||||
}
|
||||
}
|
||||
PREG = UndefCode->CodeOfPred;
|
||||
CFREG = CalculateStackGap();
|
||||
CACHE_A1();
|
||||
JMPNext();
|
||||
ENDBOp();
|
||||
@ -11680,7 +11684,9 @@ Yap_absmi(int inp)
|
||||
WRITEBACK_Y_AS_ENV();
|
||||
SREG = (CELL *) pen;
|
||||
ASP = E_YREG;
|
||||
LOCK(SignalLock);
|
||||
ActiveSignals &= ~YAP_CDOVF_SIGNAL;
|
||||
UNLOCK(SignalLock);
|
||||
if (ActiveSignals & YAP_CDOVF_SIGNAL) {
|
||||
saveregs_and_ycache();
|
||||
if (!Yap_growheap(FALSE, 0, NULL)) {
|
||||
@ -11689,7 +11695,9 @@ Yap_absmi(int inp)
|
||||
FAIL();
|
||||
}
|
||||
setregs_and_ycache();
|
||||
LOCK(SignalLock);
|
||||
CFREG = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
}
|
||||
if (ActiveSignals) {
|
||||
goto creep;
|
||||
|
@ -3314,9 +3314,7 @@ p_recorded(void)
|
||||
} else {
|
||||
DBRef ref = DBRefOfTerm(t3);
|
||||
if (ref == NULL) return FALSE;
|
||||
LOCK(ref->lock);
|
||||
if (DEAD_REF(ref)) {
|
||||
UNLOCK(ref->lock);
|
||||
return FALSE;
|
||||
}
|
||||
if (ref->Flags & LogUpdMask) {
|
||||
@ -3324,22 +3322,17 @@ p_recorded(void)
|
||||
PredEntry *ap;
|
||||
if (Yap_op_from_opcode(cl->ClCode->opc) == _unify_idb_term) {
|
||||
if (!Yap_unify(ARG2, cl->ClSource->Entry)) {
|
||||
UNLOCK(cl->ClLock);
|
||||
return FALSE;
|
||||
}
|
||||
} else if (!Yap_unify(ARG2,GetDBTerm(cl->ClSource))) {
|
||||
UNLOCK(cl->ClLock);
|
||||
return FALSE;
|
||||
}
|
||||
ap = cl->ClPred;
|
||||
UNLOCK(ref->lock);
|
||||
return Yap_unify(GetDBLUKey(ap), ARG1);
|
||||
} else if (!Yap_unify(ARG2,GetDBTermFromDBEntry(ref))
|
||||
|| !UnifyDBKey(ref,0,ARG1)) {
|
||||
UNLOCK(ref->lock);
|
||||
return FALSE;
|
||||
} else {
|
||||
UNLOCK(ref->lock);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
10
C/exec.c
10
C/exec.c
@ -301,7 +301,9 @@ EnterCreepMode(Term t, SMALLUNSGN mod) {
|
||||
}
|
||||
PredCreep = RepPredProp(PredPropByFunc(FunctorCreep,1));
|
||||
ARG1 = MkPairTerm(ModuleName[mod],ARG1);
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
P_before_spy = P;
|
||||
return (CallPredicate(PredCreep, B));
|
||||
}
|
||||
@ -1081,9 +1083,11 @@ exec_absmi(int top)
|
||||
#endif
|
||||
#endif
|
||||
yap_flags[SPY_CREEP_FLAG] = 0;
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
P = (yamop *)FAILCODE;
|
||||
Yap_PrologMode = UserMode;
|
||||
UNLOCK(SignalLock);
|
||||
P = (yamop *)FAILCODE;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@ -1541,7 +1545,7 @@ Yap_InitYaamRegs(void)
|
||||
machine registers */
|
||||
#ifdef THREADS
|
||||
int myworker_id = worker_id;
|
||||
pthread_setspecific(yaamregs_key, (const void *)ThreadHandle[myworker_id].default_yaam_regs);
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)ThreadHandle[myworker_id].default_yaam_regs);
|
||||
ThreadHandle[myworker_id].current_yaam_regs = ThreadHandle[myworker_id].default_yaam_regs;
|
||||
worker_id = myworker_id;
|
||||
#else
|
||||
@ -1573,7 +1577,9 @@ Yap_InitYaamRegs(void)
|
||||
BBREG = B_FZ = B_BASE;
|
||||
TR = TR_FZ = TR_BASE;
|
||||
#endif /* FROZEN_STACKS */
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
EX = 0L;
|
||||
/* for slots to work */
|
||||
*--ASP = MkIntTerm(0);
|
||||
|
8
C/grow.c
8
C/grow.c
@ -529,7 +529,9 @@ static_growheap(long size, int fix_code, struct intermediates *cip)
|
||||
}
|
||||
/* CreepFlag is set to force heap expansion */
|
||||
if (ActiveSignals == YAP_CDOVF_SIGNAL) {
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
}
|
||||
ASP -= 256;
|
||||
TrDiff = LDiff = GDiff = DelayDiff = size;
|
||||
@ -711,9 +713,11 @@ do_growheap(int fix_code, UInt in_size, struct intermediates *cip)
|
||||
fix_tabling_info();
|
||||
#endif /* TABLING */
|
||||
if (sz >= sizeof(CELL) * 16 * 1024L) {
|
||||
LOCK(SignalLock);
|
||||
ActiveSignals &= ~YAP_CDOVF_SIGNAL;
|
||||
if (!ActiveSignals)
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
return TRUE;
|
||||
}
|
||||
/* failed */
|
||||
@ -996,10 +1000,12 @@ static int do_growtrail(long size)
|
||||
fprintf(Yap_stderr, "[TO] took %g sec\n", (double)growth_time/1000);
|
||||
fprintf(Yap_stderr, "[TO] Total of %g sec expanding trail \n", (double)total_trail_overflow_time/1000);
|
||||
}
|
||||
LOCK(SignalLock);
|
||||
if (ActiveSignals == YAP_TROVF_SIGNAL) {
|
||||
CreepFlag = CalculateStackGap();
|
||||
}
|
||||
ActiveSignals &= ~YAP_TROVF_SIGNAL;
|
||||
UNLOCK(SignalLock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1051,10 +1057,12 @@ Yap_growatomtable(void)
|
||||
Int start_growth_time = Yap_cputime(), growth_time;
|
||||
int gc_verbose = Yap_is_gc_verbose();
|
||||
|
||||
LOCK(SignalLock);
|
||||
if (ActiveSignals == YAP_CDOVF_SIGNAL) {
|
||||
CreepFlag = CalculateStackGap();
|
||||
}
|
||||
ActiveSignals &= ~YAP_CDOVF_SIGNAL;
|
||||
UNLOCK(SignalLock);
|
||||
while ((ntb = (AtomHashEntry *)Yap_AllocCodeSpace(nsize*sizeof(AtomHashEntry))) == NULL) {
|
||||
/* leave for next time */
|
||||
if (!do_growheap(FALSE, nsize*sizeof(AtomHashEntry), NULL))
|
||||
|
4
C/init.c
4
C/init.c
@ -1137,8 +1137,8 @@ Yap_InitWorkspace(int Heap,
|
||||
|
||||
#if PUSH_REGS
|
||||
#ifdef THREADS
|
||||
pthread_key_create(&yaamregs_key, NULL);
|
||||
pthread_setspecific(yaamregs_key, (const void *)&Yap_standard_regs);
|
||||
pthread_key_create(&Yap_yaamregs_key, NULL);
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
|
||||
#else
|
||||
/* In this case we need to initialise the abstract registers */
|
||||
Yap_regp = &Yap_standard_regs;
|
||||
|
@ -31,7 +31,7 @@ REGSTORE Yap_standard_regs;
|
||||
#ifdef THREADS
|
||||
/* PushRegs always on */
|
||||
|
||||
pthread_key_t yaamregs_key;
|
||||
pthread_key_t Yap_yaamregs_key;
|
||||
|
||||
#else
|
||||
|
||||
|
@ -432,7 +432,9 @@ p_creep(void)
|
||||
static Int
|
||||
p_stop_creep(void)
|
||||
{
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
UNLOCK(SignalLock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -82,13 +82,12 @@ thread_run(void *widp)
|
||||
|
||||
/* create the YAAM descriptor */
|
||||
ThreadHandle[myworker_id].default_yaam_regs = standard_regs;
|
||||
pthread_setspecific(yaamregs_key, (void *)standard_regs);
|
||||
pthread_setspecific(Yap_yaamregs_key, (void *)standard_regs);
|
||||
worker_id = myworker_id;
|
||||
Yap_InitExStacks(ThreadHandle[myworker_id].ssize, ThreadHandle[myworker_id].tsize);
|
||||
Yap_InitYaamRegs();
|
||||
{
|
||||
ADDR ptr = Yap_PreAllocCodeSpace();
|
||||
Yap_ReleasePreAllocCodeSpace(ptr);
|
||||
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
||||
}
|
||||
tgs[0] = Yap_FetchTermFromDB(ThreadHandle[worker_id].tgoal);
|
||||
tgoal = Yap_MkApplTerm(FunctorThreadRun, 1, tgs);
|
||||
@ -369,6 +368,7 @@ p_thread_signal(void)
|
||||
ThreadHandle[wid].current_yaam_regs->CreepFlag_ = Unsigned(LCL0);
|
||||
heap_regs->wl[wid].active_signals |= YAP_ITI_SIGNAL;
|
||||
UNLOCK(heap_regs->wl[wid].signal_lock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
@ -393,6 +393,7 @@ void Yap_InitThreadPreds(void)
|
||||
Yap_InitCPred("$cond_broadcast", 1, p_cond_broadcast, SafePredFlag);
|
||||
Yap_InitCPred("$cond_wait", 2, p_cond_wait, SafePredFlag);
|
||||
Yap_InitCPred("$install_thread_local", 2, p_install_thread_local, SafePredFlag);
|
||||
Yap_InitCPred("$thread_signal", 2, p_thread_signal, SafePredFlag);
|
||||
}
|
||||
|
||||
|
||||
|
8
H/Regs.h
8
H/Regs.h
@ -10,7 +10,7 @@
|
||||
* File: Regs.h *
|
||||
* mods: *
|
||||
* comments: YAP abstract machine registers *
|
||||
* version: $Id: Regs.h,v 1.23 2004-02-05 16:57:01 vsc Exp $ *
|
||||
* version: $Id: Regs.h,v 1.24 2004-02-06 17:22:24 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ extern REGSTORE *Yap_regp;
|
||||
|
||||
#if PUSH_X
|
||||
|
||||
#define XREGS (Yap_regp->XTERMS)
|
||||
#define XREGS (Yap_REGS.XTERMS)
|
||||
|
||||
#else
|
||||
|
||||
@ -153,9 +153,9 @@ Term Yap_XREGS[MaxTemps]; /* 29 */
|
||||
|
||||
#ifdef THREADS
|
||||
|
||||
extern pthread_key_t yaamregs_key;
|
||||
extern pthread_key_t Yap_yaamregs_key;
|
||||
|
||||
#define Yap_regp ((REGSTORE *)pthread_getspecific(yaamregs_key))
|
||||
#define Yap_regp ((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -179,7 +179,7 @@ restore_absmi_regs(REGSTORE * old_regs)
|
||||
{
|
||||
memcpy(old_regs, Yap_regp, sizeof(REGSTORE));
|
||||
#ifdef THREADS
|
||||
pthread_setspecific(yaamregs_key, (void *)old_regs);
|
||||
pthread_setspecific(Yap_yaamregs_key, (void *)old_regs);
|
||||
ThreadHandle[worker_id].current_yaam_regs = old_regs;
|
||||
#else
|
||||
Yap_regp = old_regs;
|
||||
|
@ -56,6 +56,7 @@ typedef struct logic_upd_index {
|
||||
yamop ClCode[MIN_ARRAY];
|
||||
} LogUpdIndex;
|
||||
|
||||
/* The ordering of the first 3 fields should be compatible with dbrefs */
|
||||
typedef struct logic_upd_clause {
|
||||
Functor Id; /* allow pointers to this struct to id */
|
||||
/* as dbref */
|
||||
|
@ -286,19 +286,20 @@ typedef struct DB_TERM {
|
||||
Term Contents[MIN_ARRAY]; /* stored term */
|
||||
} DBTerm;
|
||||
|
||||
/* The ordering of the first 3 fields should be compatible with lu_clauses */
|
||||
typedef struct DB_STRUCT {
|
||||
Functor id; /* allow pointers to this struct to id */
|
||||
/* as dbref */
|
||||
CELL Flags; /* Term Flags */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar lock; /* a simple lock to protect this entry */
|
||||
Int ref_count; /* how many branches are using this entry */
|
||||
#endif
|
||||
CELL NOfRefsTo; /* Number of references pointing here */
|
||||
struct struct_dbentry *Parent; /* key of DBase reference */
|
||||
struct yami *Code; /* pointer to code if this is a clause */
|
||||
struct DB_STRUCT *Prev; /* Previous element in chain */
|
||||
struct DB_STRUCT *Next; /* Next element in chain */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar lock; /* a simple lock to protect this entry */
|
||||
Int ref_count; /* how many branches are using this entry */
|
||||
#endif
|
||||
struct DB_STRUCT *p, *n; /* entry's age, negative if from recorda,
|
||||
positive if it was recordz */
|
||||
CELL Mask; /* parts that should be cleared */
|
||||
|
Reference in New Issue
Block a user