fix deadlock when trying to create a module with the same name as a

predicate (for now, just don't lock modules). obs Paulo Moura.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1869 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2007-04-18 23:01:16 +00:00
parent ee03654060
commit dc3b7079f4
3 changed files with 25 additions and 13 deletions

View File

@ -10,8 +10,11 @@
* File: c_interface.c * * File: c_interface.c *
* comments: c_interface primitives definition * * comments: c_interface primitives definition *
* * * *
* Last rev: $Date: 2007-03-30 16:47:22 $,$Author: vsc $ * * Last rev: $Date: 2007-04-18 23:01:16 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.91 2007/03/30 16:47:22 vsc
* fix gmpless blob handling
*
* Revision 1.90 2007/03/22 11:12:20 vsc * Revision 1.90 2007/03/22 11:12:20 vsc
* make sure that YAP_Restart does not restart a failed goal. * make sure that YAP_Restart does not restart a failed goal.
* *
@ -1645,7 +1648,12 @@ YAP_CurrentModule(void)
X_API Term X_API Term
YAP_CreateModule(Atom at) YAP_CreateModule(Atom at)
{ {
return Yap_Module(MkAtomTerm(at)); Term t;
WRITE_LOCK(RepAtom(at)->ARWLock);
t = Yap_Module(MkAtomTerm(at));
WRITE_UNLOCK(RepAtom(at)->ARWLock);
return t;
} }
X_API int X_API int

View File

@ -33,17 +33,18 @@ FetchModuleEntry(Atom at)
Prop p0; Prop p0;
AtomEntry *ae = RepAtom(at); AtomEntry *ae = RepAtom(at);
WRITE_LOCK(ae->ARWLock); READ_LOCK(ae->ARWLock);
p0 = ae->PropsOfAE; p0 = ae->PropsOfAE;
while (p0) { while (p0) {
ModEntry *me = RepModProp(p0); ModEntry *me = RepModProp(p0);
if ( me->KindOfPE == ModProperty if ( me->KindOfPE == ModProperty
) { ) {
WRITE_UNLOCK(ae->ARWLock); READ_UNLOCK(ae->ARWLock);
return me; return me;
} }
p0 = me->NextOfPE; p0 = me->NextOfPE;
} }
READ_UNLOCK(ae->ARWLock);
return NULL; return NULL;
} }
@ -55,13 +56,11 @@ GetModuleEntry(Atom at)
AtomEntry *ae = RepAtom(at); AtomEntry *ae = RepAtom(at);
ModEntry *new; ModEntry *new;
WRITE_LOCK(ae->ARWLock);
p0 = ae->PropsOfAE; p0 = ae->PropsOfAE;
while (p0) { while (p0) {
ModEntry *me = RepModProp(p0); ModEntry *me = RepModProp(p0);
if ( me->KindOfPE == ModProperty if ( me->KindOfPE == ModProperty
) { ) {
WRITE_UNLOCK(ae->ARWLock);
return me; return me;
} }
p0 = me->NextOfPE; p0 = me->NextOfPE;
@ -75,7 +74,6 @@ GetModuleEntry(Atom at)
new->AtomOfME = ae; new->AtomOfME = ae;
new->NextOfPE = ae->PropsOfAE; new->NextOfPE = ae->PropsOfAE;
ae->PropsOfAE = AbsModProp(new); ae->PropsOfAE = AbsModProp(new);
WRITE_UNLOCK(ae->ARWLock);
return new; return new;
} }
@ -105,12 +103,14 @@ static ModEntry *
LookupModule(Term a) LookupModule(Term a)
{ {
Atom at; Atom at;
ModEntry *me;
/* prolog module */ /* prolog module */
if (a == 0) if (a == 0)
return GetModuleEntry(AtomOfTerm(TermProlog)); return GetModuleEntry(AtomOfTerm(TermProlog));
at = AtomOfTerm(a); at = AtomOfTerm(a);
return GetModuleEntry(at); me = GetModuleEntry(at);
return me;
} }
Term Term
@ -136,9 +136,10 @@ Yap_NewModulePred(Term mod, struct pred_entry *ap)
if (!(me = LookupModule(mod))) if (!(me = LookupModule(mod)))
return; return;
/* LOCK THIS */ WRITE_LOCK(me->ModRWLock);
ap->NextPredOfModule = me->PredForME; ap->NextPredOfModule = me->PredForME;
me->PredForME = ap; me->PredForME = ap;
WRITE_UNLOCK(me->ModRWLock);
} }
static Int static Int
@ -162,7 +163,7 @@ p_current_module(void)
CurrentModule = t; CurrentModule = t;
LookupModule(CurrentModule); LookupModule(CurrentModule);
} }
return (TRUE); return TRUE;
} }
static Int static Int

View File

@ -11,8 +11,11 @@
* File: stdpreds.c * * File: stdpreds.c *
* comments: General-purpose C implemented system predicates * * comments: General-purpose C implemented system predicates *
* * * *
* Last rev: $Date: 2007-02-26 10:41:40 $,$Author: vsc $ * * Last rev: $Date: 2007-04-18 23:01:16 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.118 2007/02/26 10:41:40 vsc
* fix prolog_flags for chr.
*
* Revision 1.117 2007/01/28 14:26:37 vsc * Revision 1.117 2007/01/28 14:26:37 vsc
* WIN32 support * WIN32 support
* *
@ -2480,9 +2483,9 @@ cont_current_predicate(void)
Term name; Term name;
while (pp != NULL) { while (pp != NULL) {
if (pp->PredFlags & HiddenPredFlag) if (pp->PredFlags & HiddenPredFlag) {
pp = pp->NextPredOfModule; pp = pp->NextPredOfModule;
else } else
break; break;
} }
if (pp == NULL) if (pp == NULL)