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:
parent
c9247ce308
commit
eec29d7c27
19
C/absmi.c
19
C/absmi.c
|
@ -6307,7 +6307,6 @@ Yap_absmi(int inp)
|
||||||
{
|
{
|
||||||
PredEntry *ap = PredFromDefCode(PREG);
|
PredEntry *ap = PredFromDefCode(PREG);
|
||||||
WRITE_LOCK(ap->PRWLock);
|
WRITE_LOCK(ap->PRWLock);
|
||||||
WPP = ap;
|
|
||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
/*
|
/*
|
||||||
we do not lock access to the predicate,
|
we do not lock access to the predicate,
|
||||||
|
@ -6316,7 +6315,6 @@ Yap_absmi(int inp)
|
||||||
if (ap->OpcodeOfPred != INDEX_OPCODE) {
|
if (ap->OpcodeOfPred != INDEX_OPCODE) {
|
||||||
/* someone was here before we were */
|
/* someone was here before we were */
|
||||||
PREG = ap->CodeOfPred;
|
PREG = ap->CodeOfPred;
|
||||||
WPP = NULL;
|
|
||||||
WRITE_UNLOCK(ap->PRWLock);
|
WRITE_UNLOCK(ap->PRWLock);
|
||||||
JMPNext();
|
JMPNext();
|
||||||
}
|
}
|
||||||
|
@ -6442,23 +6440,6 @@ Yap_absmi(int inp)
|
||||||
H += 2;
|
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;
|
PREG = UndefCode->CodeOfPred;
|
||||||
CACHE_A1();
|
CACHE_A1();
|
||||||
JMPNext();
|
JMPNext();
|
||||||
|
|
28
C/init.c
28
C/init.c
|
@ -808,6 +808,20 @@ InitCodes(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
heap_regs->consultcapacity = InitialConsultCapacity;
|
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_profiling = FALSE;
|
||||||
heap_regs->system_call_counting = FALSE;
|
heap_regs->system_call_counting = FALSE;
|
||||||
heap_regs->system_pred_goal_expansion_on = FALSE;
|
heap_regs->system_pred_goal_expansion_on = FALSE;
|
||||||
|
@ -988,20 +1002,6 @@ InitCodes(void)
|
||||||
heap_regs->dead_clauses = NULL;
|
heap_regs->dead_clauses = NULL;
|
||||||
Yap_ReleaseAtom(AtomOfTerm(heap_regs->term_refound_var));
|
Yap_ReleaseAtom(AtomOfTerm(heap_regs->term_refound_var));
|
||||||
/* make sure we have undefp defined */
|
/* 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 */
|
/* predicates can only be defined after this point */
|
||||||
heap_regs->env_for_yes_code.p =
|
heap_regs->env_for_yes_code.p =
|
||||||
heap_regs->env_for_yes_code.p0 =
|
heap_regs->env_for_yes_code.p0 =
|
||||||
|
|
|
@ -384,12 +384,6 @@ p_values(void)
|
||||||
static Int
|
static Int
|
||||||
p_flipflop(void)
|
p_flipflop(void)
|
||||||
{ /* '$flipflop' */
|
{ /* '$flipflop' */
|
||||||
Atom at;
|
|
||||||
PredEntry *pred;
|
|
||||||
|
|
||||||
at = Yap_FullLookupAtom("$spy");
|
|
||||||
pred = RepPredProp(PredPropByFunc(Yap_MkFunctor(at, 1),0));
|
|
||||||
SpyCode = pred;
|
|
||||||
return ((int) (FlipFlop = (1 - FlipFlop)));
|
return ((int) (FlipFlop = (1 - FlipFlop)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ thread_die(void)
|
||||||
free(ScratchPad.ptr);
|
free(ScratchPad.ptr);
|
||||||
free(ThreadHandle[worker_id].default_yaam_regs);
|
free(ThreadHandle[worker_id].default_yaam_regs);
|
||||||
ThreadHandle[worker_id].in_use = FALSE;
|
ThreadHandle[worker_id].in_use = FALSE;
|
||||||
|
pthread_mutex_destroy(&(ThreadHandle[worker_id].tlock));
|
||||||
UNLOCK(ThreadHandlesLock);
|
UNLOCK(ThreadHandlesLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ thread_run(void *widp)
|
||||||
tgs[0] = Yap_FetchTermFromDB(ThreadHandle[worker_id].tgoal);
|
tgs[0] = Yap_FetchTermFromDB(ThreadHandle[worker_id].tgoal);
|
||||||
tgs[1] = ThreadHandle[worker_id].tdetach;
|
tgs[1] = ThreadHandle[worker_id].tdetach;
|
||||||
tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs);
|
tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs);
|
||||||
|
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||||
out = Yap_RunTopGoal(tgoal);
|
out = Yap_RunTopGoal(tgoal);
|
||||||
thread_die();
|
thread_die();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -135,6 +137,8 @@ p_create_thread(void)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
ThreadHandle[new_worker_id].id = new_worker_id;
|
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);
|
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) {
|
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;
|
return TRUE;
|
||||||
|
@ -384,10 +388,13 @@ static Int
|
||||||
p_thread_signal(void)
|
p_thread_signal(void)
|
||||||
{ /* '$thread_signal'(+P) */
|
{ /* '$thread_signal'(+P) */
|
||||||
Int wid = IntegerOfTerm(Deref(ARG1));
|
Int wid = IntegerOfTerm(Deref(ARG1));
|
||||||
|
/* make sure the lock is available */
|
||||||
|
pthread_mutex_lock(&(ThreadHandle[wid].tlock));
|
||||||
LOCK(heap_regs->wl[wid].signal_lock);
|
LOCK(heap_regs->wl[wid].signal_lock);
|
||||||
ThreadHandle[wid].current_yaam_regs->CreepFlag_ = Unsigned(LCL0);
|
ThreadHandle[wid].current_yaam_regs->CreepFlag_ = Unsigned(LCL0);
|
||||||
heap_regs->wl[wid].active_signals |= YAP_ITI_SIGNAL;
|
heap_regs->wl[wid].active_signals |= YAP_ITI_SIGNAL;
|
||||||
UNLOCK(heap_regs->wl[wid].signal_lock);
|
UNLOCK(heap_regs->wl[wid].signal_lock);
|
||||||
|
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
H/Heap.h
3
H/Heap.h
|
@ -10,7 +10,7 @@
|
||||||
* File: Heap.h *
|
* File: Heap.h *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: Heap Init Structure *
|
* 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 */
|
/* information that can be stored in Code Space */
|
||||||
|
@ -75,6 +75,7 @@ typedef struct thandle {
|
||||||
REGSTORE *current_yaam_regs;
|
REGSTORE *current_yaam_regs;
|
||||||
struct pred_entry *local_preds;
|
struct pred_entry *local_preds;
|
||||||
pthread_t handle;
|
pthread_t handle;
|
||||||
|
pthread_mutex_t tlock;
|
||||||
} yap_thandle;
|
} yap_thandle;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -398,5 +398,5 @@ thread_signal(Thread, Goal) :-
|
||||||
|
|
||||||
'$thread_gfetch'(G) :-
|
'$thread_gfetch'(G) :-
|
||||||
'$thread_self'(Id),
|
'$thread_self'(Id),
|
||||||
recorded('$thread_signal',[Id,G],R),
|
recorded('$thread_signal',[Id|G],R),
|
||||||
erase(R).
|
erase(R).
|
||||||
|
|
Reference in New Issue