fix thread_signal

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@978 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-02-11 13:59:53 +00:00
parent c9247ce308
commit eec29d7c27
6 changed files with 24 additions and 41 deletions

View File

@ -6307,7 +6307,6 @@ Yap_absmi(int inp)
{
PredEntry *ap = PredFromDefCode(PREG);
WRITE_LOCK(ap->PRWLock);
WPP = ap;
#if defined(YAPOR) || defined(THREADS)
/*
we do not lock access to the predicate,
@ -6316,7 +6315,6 @@ Yap_absmi(int inp)
if (ap->OpcodeOfPred != INDEX_OPCODE) {
/* someone was here before we were */
PREG = ap->CodeOfPred;
WPP = NULL;
WRITE_UNLOCK(ap->PRWLock);
JMPNext();
}
@ -6442,23 +6440,6 @@ Yap_absmi(int inp)
H += 2;
}
if (UndefCode == NULL) {
Atom at;
at = Yap_FullLookupAtom("$undefp");
{
Prop p = Yap_GetPredPropByFunc(Yap_MkFunctor(at, 1),0);
if (p == NIL) {
FAIL();
} else {
PredEntry *undefpe;
undefpe = RepPredProp (p);
READ_LOCK(undefpe->PRWLock);
UndefCode = undefpe;
READ_UNLOCK(undefpe->PRWLock);
}
}
}
PREG = UndefCode->CodeOfPred;
CACHE_A1();
JMPNext();

View File

@ -808,6 +808,20 @@ InitCodes(void)
return;
}
heap_regs->consultcapacity = InitialConsultCapacity;
{
Atom at;
PredEntry *pred;
at = Yap_FullLookupAtom("$creep");
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),PROLOG_MODULE));
heap_regs->creep_code = pred;
at = Yap_FullLookupAtom("$undefp");
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),PROLOG_MODULE));
heap_regs->undef_code = pred;
at = Yap_FullLookupAtom("$spy");
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
heap_regs->spy_code = pred;
}
heap_regs->system_profiling = FALSE;
heap_regs->system_call_counting = FALSE;
heap_regs->system_pred_goal_expansion_on = FALSE;
@ -988,20 +1002,6 @@ InitCodes(void)
heap_regs->dead_clauses = NULL;
Yap_ReleaseAtom(AtomOfTerm(heap_regs->term_refound_var));
/* make sure we have undefp defined */
{
Atom undefp_at = Yap_FullLookupAtom("$undefp");
Prop p = Yap_GetPredPropByFunc(Yap_MkFunctor(undefp_at, 1),0);
if (p == NIL) {
UndefCode = NULL;
} else {
PredEntry *undefpe;
undefpe = RepPredProp (p);
UndefCode = undefpe;
/* undefp is originally undefined */
undefpe->OpcodeOfPred = UNDEF_OPCODE;
}
}
/* predicates can only be defined after this point */
heap_regs->env_for_yes_code.p =
heap_regs->env_for_yes_code.p0 =

View File

@ -384,12 +384,6 @@ p_values(void)
static Int
p_flipflop(void)
{ /* '$flipflop' */
Atom at;
PredEntry *pred;
at = Yap_FullLookupAtom("$spy");
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
SpyCode = pred;
return ((int) (FlipFlop = (1 - FlipFlop)));
}

View File

@ -85,6 +85,7 @@ thread_die(void)
free(ScratchPad.ptr);
free(ThreadHandle[worker_id].default_yaam_regs);
ThreadHandle[worker_id].in_use = FALSE;
pthread_mutex_destroy(&(ThreadHandle[worker_id].tlock));
UNLOCK(ThreadHandlesLock);
}
@ -110,6 +111,7 @@ thread_run(void *widp)
tgs[0] = Yap_FetchTermFromDB(ThreadHandle[worker_id].tgoal);
tgs[1] = ThreadHandle[worker_id].tdetach;
tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs);
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
out = Yap_RunTopGoal(tgoal);
thread_die();
return NULL;
@ -135,6 +137,8 @@ p_create_thread(void)
return FALSE;
}
ThreadHandle[new_worker_id].id = new_worker_id;
pthread_mutex_init(&ThreadHandle[new_worker_id].tlock, NULL);
pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock));
store_specs(new_worker_id, ssize, tsize, tgoal, tdetach);
if ((ThreadHandle[new_worker_id].ret = pthread_create(&(ThreadHandle[new_worker_id].handle), NULL, thread_run, (void *)(&(ThreadHandle[new_worker_id].id)))) == 0) {
return TRUE;
@ -384,10 +388,13 @@ static Int
p_thread_signal(void)
{ /* '$thread_signal'(+P) */
Int wid = IntegerOfTerm(Deref(ARG1));
/* make sure the lock is available */
pthread_mutex_lock(&(ThreadHandle[wid].tlock));
LOCK(heap_regs->wl[wid].signal_lock);
ThreadHandle[wid].current_yaam_regs->CreepFlag_ = Unsigned(LCL0);
heap_regs->wl[wid].active_signals |= YAP_ITI_SIGNAL;
UNLOCK(heap_regs->wl[wid].signal_lock);
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
return TRUE;
}

View File

@ -10,7 +10,7 @@
* File: Heap.h *
* mods: *
* comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.55 2004-02-11 13:33:19 vsc Exp $ *
* version: $Id: Heap.h,v 1.56 2004-02-11 13:59:52 vsc Exp $ *
*************************************************************************/
/* information that can be stored in Code Space */
@ -75,6 +75,7 @@ typedef struct thandle {
REGSTORE *current_yaam_regs;
struct pred_entry *local_preds;
pthread_t handle;
pthread_mutex_t tlock;
} yap_thandle;
#endif

View File

@ -398,5 +398,5 @@ thread_signal(Thread, Goal) :-
'$thread_gfetch'(G) :-
'$thread_self'(Id),
recorded('$thread_signal',[Id,G],R),
recorded('$thread_signal',[Id|G],R),
erase(R).