From eec29d7c27413c7a6610c2500f3ae919e5a98128 Mon Sep 17 00:00:00 2001 From: vsc Date: Wed, 11 Feb 2004 13:59:53 +0000 Subject: [PATCH] fix thread_signal git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@978 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 19 ------------------- C/init.c | 28 ++++++++++++++-------------- C/stdpreds.c | 6 ------ C/threads.c | 7 +++++++ H/Heap.h | 3 ++- pl/threads.yap | 2 +- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index d63c38641..a4ec65a98 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -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(); diff --git a/C/init.c b/C/init.c index 826f5584c..6a4709df4 100644 --- a/C/init.c +++ b/C/init.c @@ -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 = diff --git a/C/stdpreds.c b/C/stdpreds.c index 8bdc48369..bc772d636 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -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))); } diff --git a/C/threads.c b/C/threads.c index 90b1c8fca..56ae1f13e 100644 --- a/C/threads.c +++ b/C/threads.c @@ -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; } diff --git a/H/Heap.h b/H/Heap.h index 55d3b2136..481fef1f3 100644 --- a/H/Heap.h +++ b/H/Heap.h @@ -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 diff --git a/pl/threads.yap b/pl/threads.yap index fdf912b10..a41c270ca 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -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).