thread support fixes

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1462 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2005-11-17 13:40:18 +00:00
parent 7cd5cafe1c
commit d62ec41632
6 changed files with 325 additions and 294 deletions

View File

@ -253,21 +253,21 @@ AccessNamedArray(Atom a, Int indx)
Term out; Term out;
out = MkIntegerTerm(ptr->ValueOfVE.ints[indx]); out = MkIntegerTerm(ptr->ValueOfVE.ints[indx]);
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return (out); return out;
} }
case array_of_doubles: case array_of_doubles:
{ {
Term out; Term out;
out = MkEvalFl(ptr->ValueOfVE.floats[indx]); out = MkEvalFl(ptr->ValueOfVE.floats[indx]);
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return (out); return out;
} }
case array_of_ptrs: case array_of_ptrs:
{ {
Term out; Term out;
out = MkIntegerTerm((Int)(ptr->ValueOfVE.ptrs[indx])); out = MkIntegerTerm((Int)(ptr->ValueOfVE.ptrs[indx]));
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return (out); return out;
} }
case array_of_atoms: case array_of_atoms:
{ {
@ -275,9 +275,9 @@ AccessNamedArray(Atom a, Int indx)
out = ptr->ValueOfVE.atoms[indx]; out = ptr->ValueOfVE.atoms[indx];
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
if (out == 0L) if (out == 0L)
out = TermNil; return TermNil;
else else
return(out); return out;
} }
/* just return the atom */ /* just return the atom */
case array_of_chars: case array_of_chars:
@ -285,14 +285,14 @@ AccessNamedArray(Atom a, Int indx)
Term out; Term out;
out = MkIntegerTerm((Int)(ptr->ValueOfVE.chars[indx])); out = MkIntegerTerm((Int)(ptr->ValueOfVE.chars[indx]));
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return (out); return out;
} }
case array_of_uchars: case array_of_uchars:
{ {
Term out; Term out;
out = MkIntegerTerm((Int)(ptr->ValueOfVE.uchars[indx])); out = MkIntegerTerm((Int)(ptr->ValueOfVE.uchars[indx]));
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return (out); return out;
} }
case array_of_dbrefs: case array_of_dbrefs:
{ {
@ -347,7 +347,7 @@ AccessNamedArray(Atom a, Int indx)
} }
default: default:
READ_UNLOCK(ptr->ArRWLock); READ_UNLOCK(ptr->ArRWLock);
return(TermNil); return TermNil;
} }
} }
} }
@ -545,20 +545,21 @@ CreateStaticArray(AtomEntry *ae, Int dim, static_array_types type, CODEADDR star
p->KindOfPE = ArrayProperty; p->KindOfPE = ArrayProperty;
p->NextOfPE = ae->PropsOfAE; p->NextOfPE = ae->PropsOfAE;
INIT_RWLOCK(p->ArRWLock); INIT_RWLOCK(p->ArRWLock);
WRITE_LOCK(p->ArRWLock);
} }
WRITE_LOCK(p->ArRWLock);
p->ArrayEArity = -dim; p->ArrayEArity = -dim;
p->ArrayType = type; p->ArrayType = type;
ae->PropsOfAE = AbsArrayProp((ArrayEntry *)p); ae->PropsOfAE = AbsArrayProp((ArrayEntry *)p);
p->NextAE = StaticArrays; p->NextAE = StaticArrays;
StaticArrays = p; StaticArrays = p;
WRITE_UNLOCK(ae->ARWLock);
if (start_addr == NULL) { if (start_addr == NULL) {
int i; int i;
AllocateStaticArraySpace(p, type, dim); AllocateStaticArraySpace(p, type, dim);
if (p->ValueOfVE.ints == NULL) if (p->ValueOfVE.ints == NULL) {
WRITE_UNLOCK(p->ArRWLock);
return p; return p;
}
switch(type) { switch(type) {
case array_of_ints: case array_of_ints:
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
@ -612,15 +613,17 @@ ResizeStaticArray(StaticArrayEntry *pp, Int dim)
Int old_dim = - pp->ArrayEArity; Int old_dim = - pp->ArrayEArity;
Int mindim = (dim < old_dim ? dim : old_dim), i; Int mindim = (dim < old_dim ? dim : old_dim), i;
WRITE_LOCK(pp->ArRWLock);
/* change official size */ /* change official size */
if (pp->ArrayEArity >= 0) if (pp->ArrayEArity >= 0){
return; return;
}
WRITE_LOCK(pp->ArRWLock);
pp->ArrayEArity = -dim; pp->ArrayEArity = -dim;
#if HAVE_MMAP #if HAVE_MMAP
if (pp->ValueOfVE.chars < (char *)Yap_HeapBase || if (pp->ValueOfVE.chars < (char *)Yap_HeapBase ||
pp->ValueOfVE.chars > (char *)HeapTop) { pp->ValueOfVE.chars > (char *)HeapTop) {
ResizeMmappedArray(pp, dim, (void *)(pp->ValueOfVE.chars)); ResizeMmappedArray(pp, dim, (void *)(pp->ValueOfVE.chars));
WRITE_UNLOCK(pp->ArRWLock);
return; return;
} }
#endif #endif
@ -868,23 +871,32 @@ p_create_static_array(void)
app = (ArrayEntry *) pp; app = (ArrayEntry *) pp;
if (EndOfPAEntr(pp) || pp->ValueOfVE.ints == NULL) { if (EndOfPAEntr(pp) || pp->ValueOfVE.ints == NULL) {
pp = CreateStaticArray(ae, size, props, NULL, pp); pp = CreateStaticArray(ae, size, props, NULL, pp);
if (pp == NULL || pp->ValueOfVE.ints == NULL) if (pp == NULL || pp->ValueOfVE.ints == NULL) {
return(FALSE); WRITE_UNLOCK(ae->ARWLock);
return (TRUE); return FALSE;
}
WRITE_UNLOCK(ae->ARWLock);
return TRUE;
} else if (ArrayIsDynamic(app)) { } else if (ArrayIsDynamic(app)) {
if (IsVarTerm(app->ValueOfVE) && IsUnboundVar(&app->ValueOfVE)) { if (IsVarTerm(app->ValueOfVE) && IsUnboundVar(&app->ValueOfVE)) {
pp = CreateStaticArray(ae, size, props, NULL, pp); pp = CreateStaticArray(ae, size, props, NULL, pp);
if (pp == NULL) WRITE_UNLOCK(ae->ARWLock);
return(FALSE); if (pp == NULL) {
return (TRUE); return FALSE;
}
return TRUE;
} else { } else {
WRITE_UNLOCK(ae->ARWLock);
Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"cannot create static array over dynamic array"); Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"cannot create static array over dynamic array");
return FALSE; return FALSE;
} }
} else { } else {
if (pp->ArrayEArity == -size && if (pp->ArrayEArity == -size &&
pp->ArrayType == props) pp->ArrayType == props) {
WRITE_UNLOCK(ae->ARWLock);
return TRUE; return TRUE;
}
WRITE_UNLOCK(ae->ARWLock);
Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"cannot create static array over static array"); Yap_Error(PERMISSION_ERROR_CREATE_ARRAY,t,"cannot create static array over static array");
return FALSE; return FALSE;
} }
@ -1249,12 +1261,15 @@ p_create_mmapped_array(void)
pp = RepStaticArrayProp(ae->PropsOfAE); pp = RepStaticArrayProp(ae->PropsOfAE);
while (!EndOfPAEntr(pp) && pp->KindOfPE != ArrayProperty) while (!EndOfPAEntr(pp) && pp->KindOfPE != ArrayProperty)
pp = RepStaticArrayProp(pp->NextOfPE); pp = RepStaticArrayProp(pp->NextOfPE);
if (!EndOfPAEntr(pp)) {
WRITE_LOCK(pp->ArRWLock);
}
if (EndOfPAEntr(pp) || pp->ValueOfVE.ints == NULL) { if (EndOfPAEntr(pp) || pp->ValueOfVE.ints == NULL) {
mmap_array_block *ptr; mmap_array_block *ptr;
if (EndOfPAEntr(pp)) {
WRITE_UNLOCK(ae->ARWLock);
return FALSE;
} else {
WRITE_LOCK(pp->ArRWLock);
}
CreateStaticArray(ae, size, props, array_addr, pp); CreateStaticArray(ae, size, props, array_addr, pp);
ptr = (mmap_array_block *)Yap_AllocAtomSpace(sizeof(mmap_array_block)); ptr = (mmap_array_block *)Yap_AllocAtomSpace(sizeof(mmap_array_block));
ptr->name = AbsAtom(ae); ptr->name = AbsAtom(ae);
@ -1264,16 +1279,17 @@ p_create_mmapped_array(void)
ptr->fd = fd; ptr->fd = fd;
ptr->next = mmap_arrays; ptr->next = mmap_arrays;
mmap_arrays = ptr; mmap_arrays = ptr;
return(TRUE);
} else {
WRITE_UNLOCK(pp->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
WRITE_UNLOCK(ae->ARWLock);
return TRUE;
} else {
WRITE_UNLOCK(ae->ARWLock); WRITE_UNLOCK(ae->ARWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_TYPE,t,"create_mmapped_array", ae->StrOfAE); Yap_Error(DOMAIN_ERROR_ARRAY_TYPE,t,"create_mmapped_array", ae->StrOfAE);
return(FALSE); return(FALSE);
} }
} else { } else {
Yap_Error(TYPE_ERROR_ATOM,t,"create_mmapped_array"); Yap_Error(TYPE_ERROR_ATOM,t,"create_mmapped_array");
return (FALSE); return FALSE;
} }
#else #else
Yap_Error(SYSTEM_ERROR,ARG1,"create_mmapped_array (mmap)"); Yap_Error(SYSTEM_ERROR,ARG1,"create_mmapped_array (mmap)");
@ -1502,40 +1518,43 @@ p_assign_static(void)
ptr = RepStaticArrayProp(ae->PropsOfAE); ptr = RepStaticArrayProp(ae->PropsOfAE);
while (!EndOfPAEntr(ptr) && ptr->KindOfPE != ArrayProperty) while (!EndOfPAEntr(ptr) && ptr->KindOfPE != ArrayProperty)
ptr = RepStaticArrayProp(ptr->NextOfPE); ptr = RepStaticArrayProp(ptr->NextOfPE);
READ_UNLOCK(ae->ARWLock);
}
if (EndOfPAEntr(ptr)) { if (EndOfPAEntr(ptr)) {
READ_UNLOCK(ae->ARWLock);
Yap_Error(EXISTENCE_ERROR_ARRAY,t1,"assign_static %s", RepAtom(AtomOfTerm(t1))->StrOfAE); Yap_Error(EXISTENCE_ERROR_ARRAY,t1,"assign_static %s", RepAtom(AtomOfTerm(t1))->StrOfAE);
return(FALSE); return FALSE;
} }
WRITE_LOCK(ptr->ArRWLock);
if (ArrayIsDynamic((ArrayEntry *)ptr)) { if (ArrayIsDynamic((ArrayEntry *)ptr)) {
ArrayEntry *pp = (ArrayEntry *)ptr; ArrayEntry *pp = (ArrayEntry *)ptr;
CELL *pt; CELL *pt;
WRITE_LOCK(pp->ArRWLock);
READ_UNLOCK(ae->ARWLock);
if (indx < 0 || indx >= pp->ArrayEArity) { if (indx < 0 || indx >= pp->ArrayEArity) {
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
READ_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
return(FALSE); return FALSE;
} }
pt = RepAppl(pp->ValueOfVE) + indx + 1; pt = RepAppl(pp->ValueOfVE) + indx + 1;
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
#ifdef MULTI_ASSIGNMENT_VARIABLES #ifdef MULTI_ASSIGNMENT_VARIABLES
/* the evil deed is to be done now */ /* the evil deed is to be done now */
MaBind(pt, t3); MaBind(pt, t3);
return(TRUE); return TRUE;
#else #else
Yap_Error(SYSTEM_ERROR,t2,"update_array"); Yap_Error(SYSTEM_ERROR,t2,"update_array");
return(FALSE); return FALSE;
#endif #endif
} }
WRITE_LOCK(ptr->ArRWLock);
READ_UNLOCK(ae->ARWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= - ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
return(FALSE); return FALSE;
} }
switch (ptr->ArrayType) { switch (ptr->ArrayType) {
case array_of_ints: case array_of_ints:
@ -1582,7 +1601,7 @@ p_assign_static(void)
if (i > 127 || i < -128) { if (i > 127 || i < -128) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_CHAR,t3,"assign_static"); Yap_Error(TYPE_ERROR_CHAR,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.chars[indx]= i; ptr->ValueOfVE.chars[indx]= i;
} }
@ -1605,12 +1624,12 @@ p_assign_static(void)
else { else {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_INTEGER,t3,"assign_static"); Yap_Error(TYPE_ERROR_INTEGER,t3,"assign_static");
return (FALSE); return FALSE;
} }
if (i > 255 || i < 0) { if (i > 255 || i < 0) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_UCHAR,t3,"assign_static"); Yap_Error(TYPE_ERROR_UCHAR,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.chars[indx]= i; ptr->ValueOfVE.chars[indx]= i;
} }
@ -1633,7 +1652,7 @@ p_assign_static(void)
else { else {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_FLOAT,t3,"assign_static"); Yap_Error(TYPE_ERROR_FLOAT,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.floats[indx]= f; ptr->ValueOfVE.floats[indx]= f;
} }
@ -1653,7 +1672,7 @@ p_assign_static(void)
else { else {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_PTR,t3,"assign_static"); Yap_Error(TYPE_ERROR_PTR,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.ptrs[indx]= (AtomEntry *)r; ptr->ValueOfVE.ptrs[indx]= (AtomEntry *)r;
} }
@ -1669,7 +1688,7 @@ p_assign_static(void)
if (!IsAtomTerm(t3)) { if (!IsAtomTerm(t3)) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_ATOM,t3,"assign_static"); Yap_Error(TYPE_ERROR_ATOM,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.atoms[indx]= t3; ptr->ValueOfVE.atoms[indx]= t3;
} }
@ -1689,7 +1708,7 @@ p_assign_static(void)
if (!IsDBRefTerm(t3)) { if (!IsDBRefTerm(t3)) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_DBREF,t3,"assign_static"); Yap_Error(TYPE_ERROR_DBREF,t3,"assign_static");
return (FALSE); return FALSE;
} }
ptr->ValueOfVE.dbrefs[indx]= t3; ptr->ValueOfVE.dbrefs[indx]= t3;
if (t0 != 0L) { if (t0 != 0L) {
@ -1771,7 +1790,8 @@ p_assign_static(void)
break; break;
} }
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
return(TRUE); return TRUE;
}
} }
static Int static Int
@ -1846,32 +1866,33 @@ p_assign_dynamic(void)
return(FALSE); return(FALSE);
} }
WRITE_LOCK(ptr->ArRWLock);
if (ArrayIsDynamic((ArrayEntry *)ptr)) { if (ArrayIsDynamic((ArrayEntry *)ptr)) {
ArrayEntry *pp = (ArrayEntry *)ptr; ArrayEntry *pp = (ArrayEntry *)ptr;
CELL *pt; CELL *pt;
WRITE_LOCK(pp->ArRWLock);
if (indx < 0 || indx >= pp->ArrayEArity) { if (indx < 0 || indx >= pp->ArrayEArity) {
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
READ_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
return(FALSE); return(FALSE);
} }
pt = RepAppl(pp->ValueOfVE) + indx + 1; pt = RepAppl(pp->ValueOfVE) + indx + 1;
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
#ifdef MULTI_ASSIGNMENT_VARIABLES #ifdef MULTI_ASSIGNMENT_VARIABLES
/* the evil deed is to be done now */ /* the evil deed is to be done now */
MaBind(pt, t3); MaBind(pt, t3);
return(TRUE); return TRUE;
#else #else
Yap_Error(SYSTEM_ERROR,t2,"update_array"); Yap_Error(SYSTEM_ERROR,t2,"update_array");
return FALSE; return FALSE;
#endif #endif
} }
WRITE_LOCK(ptr->ArRWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= - ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"assign_static");
return(FALSE); return FALSE;
} }
switch (ptr->ArrayType) { switch (ptr->ArrayType) {
case array_of_ints: case array_of_ints:
@ -1904,15 +1925,17 @@ p_assign_dynamic(void)
Yap_UpdateTimedVar(t, t3); Yap_UpdateTimedVar(t, t3);
} }
} }
WRITE_UNLOCK(ptr->ArRWLock);
return TRUE; return TRUE;
#else #else
WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(SYSTEM_ERROR,t2,"update_array"); Yap_Error(SYSTEM_ERROR,t2,"update_array");
return FALSE; return FALSE;
#endif #endif
} }
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
return(TRUE); return TRUE;
} }
static Int static Int
@ -2017,16 +2040,16 @@ p_add_to_array_element(void)
return(FALSE); return(FALSE);
} }
WRITE_LOCK(ptr->ArRWLock);
if (ArrayIsDynamic((ArrayEntry *)ptr)) { if (ArrayIsDynamic((ArrayEntry *)ptr)) {
ArrayEntry *pp = (ArrayEntry *)ptr; ArrayEntry *pp = (ArrayEntry *)ptr;
CELL *pt; CELL *pt;
Term ta; Term ta;
WRITE_LOCK(pp->ArRWLock);
if (indx < 0 || indx >= pp->ArrayEArity) { if (indx < 0 || indx >= pp->ArrayEArity) {
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element");
READ_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); READ_UNLOCK(pp->ArRWLock);
return(FALSE); return FALSE;
} }
pt = RepAppl(pp->ValueOfVE) + indx + 1; pt = RepAppl(pp->ValueOfVE) + indx + 1;
ta = RepAppl(pp->ValueOfVE)[indx+1]; ta = RepAppl(pp->ValueOfVE)[indx+1];
@ -2036,9 +2059,9 @@ p_add_to_array_element(void)
} else if (IsFloatTerm(t3)) { } else if (IsFloatTerm(t3)) {
ta = MkFloatTerm(IntegerOfTerm(ta)+FloatOfTerm(t3)); ta = MkFloatTerm(IntegerOfTerm(ta)+FloatOfTerm(t3));
} else { } else {
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element"); Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element");
return(FALSE); return FALSE;
} }
} else if (IsFloatTerm(ta)) { } else if (IsFloatTerm(ta)) {
if (IsFloatTerm(t3)) { if (IsFloatTerm(t3)) {
@ -2046,33 +2069,34 @@ p_add_to_array_element(void)
} else if (IsFloatTerm(t3)) { } else if (IsFloatTerm(t3)) {
ta = MkFloatTerm(FloatOfTerm(ta)+FloatOfTerm(t3)); ta = MkFloatTerm(FloatOfTerm(ta)+FloatOfTerm(t3));
} else { } else {
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element"); Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element");
return(FALSE); return FALSE;
} }
} else { } else {
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
Yap_Error(TYPE_ERROR_NUMBER,ta,"add_to_array_element"); Yap_Error(TYPE_ERROR_NUMBER,ta,"add_to_array_element");
return(FALSE); return FALSE;
} }
#ifdef MULTI_ASSIGNMENT_VARIABLES #ifdef MULTI_ASSIGNMENT_VARIABLES
/* the evil deed is to be done now */ /* the evil deed is to be done now */
t3 = MkIntegerTerm(IntegerOfTerm(t3)+1); t3 = MkIntegerTerm(IntegerOfTerm(t3)+1);
MaBind(pt, t3); MaBind(pt, t3);
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
return(Yap_unify(ARG4,t3)); return Yap_unify(ARG4,t3);
#else #else
Yap_Error(SYSTEM_ERROR,t2,"add_to_array_element"); Yap_Error(SYSTEM_ERROR,t2,"add_to_array_element");
WRITE_UNLOCK(((ArrayEntry *)ptr)->ArRWLock); WRITE_UNLOCK(pp->ArRWLock);
return(FALSE); return FALSE;
#endif #endif
} }
WRITE_LOCK(ptr->ArRWLock);
/* a static array */ /* a static array */
if (indx < 0 || indx >= - ptr->ArrayEArity) { if (indx < 0 || indx >= - ptr->ArrayEArity) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element"); Yap_Error(DOMAIN_ERROR_ARRAY_OVERFLOW,t2,"add_to_array_element");
return(FALSE); return FALSE;
} }
switch (ptr->ArrayType) { switch (ptr->ArrayType) {
case array_of_ints: case array_of_ints:
@ -2081,12 +2105,12 @@ p_add_to_array_element(void)
if (!IsIntegerTerm(t3)) { if (!IsIntegerTerm(t3)) {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_INTEGER,t3,"add_to_array_element"); Yap_Error(TYPE_ERROR_INTEGER,t3,"add_to_array_element");
return(FALSE); return FALSE;
} }
i += IntegerOfTerm(t3); i += IntegerOfTerm(t3);
ptr->ValueOfVE.ints[indx] = i; ptr->ValueOfVE.ints[indx] = i;
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
return(Yap_unify(ARG4,MkIntegerTerm(i))); return Yap_unify(ARG4,MkIntegerTerm(i));
} }
break; break;
case array_of_doubles: case array_of_doubles:
@ -2100,17 +2124,17 @@ p_add_to_array_element(void)
} else { } else {
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element"); Yap_Error(TYPE_ERROR_NUMBER,t3,"add_to_array_element");
return(FALSE); return FALSE;
} }
ptr->ValueOfVE.floats[indx] = fl; ptr->ValueOfVE.floats[indx] = fl;
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
return(Yap_unify(ARG4,MkFloatTerm(fl))); return Yap_unify(ARG4,MkFloatTerm(fl));
} }
break; break;
default: default:
WRITE_UNLOCK(ptr->ArRWLock); WRITE_UNLOCK(ptr->ArRWLock);
Yap_Error(TYPE_ERROR_INTEGER,t2,"add_to_array_element"); Yap_Error(TYPE_ERROR_INTEGER,t2,"add_to_array_element");
return(FALSE); return FALSE;
} }
} }
@ -2146,7 +2170,7 @@ p_static_array_to_term(void)
Term t = Deref(ARG1); Term t = Deref(ARG1);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
return (FALSE); return FALSE;
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
/* Create a named array */ /* Create a named array */
AtomEntry *ae = RepAtom(AtomOfTerm(t)); AtomEntry *ae = RepAtom(AtomOfTerm(t));
@ -2196,7 +2220,6 @@ p_static_array_to_term(void)
/* The object is now in use */ /* The object is now in use */
Term TRef = pp->ValueOfVE.dbrefs[indx]; Term TRef = pp->ValueOfVE.dbrefs[indx];
READ_UNLOCK(pp->ArRWLock);
if (TRef != 0L) { if (TRef != 0L) {
DBRef ref = DBRefOfTerm(TRef); DBRef ref = DBRefOfTerm(TRef);
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
@ -2300,6 +2323,7 @@ p_static_array_to_term(void)
return Yap_unify(AbsAppl(base),ARG2); return Yap_unify(AbsAppl(base),ARG2);
} }
} }
Yap_Error(TYPE_ERROR_ATOM,t,"add_to_array_element");
return FALSE; return FALSE;
} }

View File

@ -1524,7 +1524,7 @@ Yap_RunTopGoal(Term t)
READ_LOCK(ppe->PRWLock); READ_LOCK(ppe->PRWLock);
CodeAdr = ppe->CodeOfPred; CodeAdr = ppe->CodeOfPred;
READ_UNLOCK(ppe->PRWLock); READ_UNLOCK(ppe->PRWLock);
#if !USE_MALLOC #if !USE_SYSTEM_MALLOC
if (Yap_TrailTop - HeapTop < 2048) { if (Yap_TrailTop - HeapTop < 2048) {
Yap_PrologMode = BootMode; Yap_PrologMode = BootMode;
Yap_Error(OUT_OF_TRAIL_ERROR,TermNil, Yap_Error(OUT_OF_TRAIL_ERROR,TermNil,

View File

@ -219,9 +219,9 @@ MoveLocalAndTrail(void)
/* cpcellsd(To,From,NOfCells) - copy the cells downwards */ /* cpcellsd(To,From,NOfCells) - copy the cells downwards */
#if USE_SYSTEM_MALLOC #if USE_SYSTEM_MALLOC
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
cpcellsd(ASP, (CELL *)((char *)OldASP+GDiff), (CELL *)OldTR - OldASP); cpcellsd(ASP, (CELL *)((char *)OldASP+DelayDiff), (CELL *)OldTR - OldASP);
#else #else
cpcellsd((CELL *)TR, (CELL *)((char *)OldTR+Gdiff), (CELL *)OldTR - OldASP); cpcellsd((CELL *)TR, (CELL *)((char *)OldTR+Delaydiff), (CELL *)OldTR - OldASP);
#endif #endif
#else #else
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
@ -254,9 +254,9 @@ MoveGlobalOnly(void)
* absmi.asm * absmi.asm
*/ */
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
cpcellsd(H0, OldH0, OldH - OldH0); cpcellsd(H0, (CELL *)((ADDR)OldH0+DelayDiff), OldH - OldH0);
#else #else
cpcellsd(H, OldH, OldH - OldH0); cpcellsd(H, (CELL *)((ADDR)OldH+DelayDiff), OldH - OldH0);
#endif #endif
} }
@ -623,6 +623,8 @@ static_growglobal(long size, CELL **ptr)
UInt start_growth_time, growth_time; UInt start_growth_time, growth_time;
int gc_verbose; int gc_verbose;
char *omax = (ADDR)DelayTop(); char *omax = (ADDR)DelayTop();
ADDR old_GlobalBase = Yap_GlobalBase;
Int ReallocDiff;
/* adjust to a multiple of 256) */ /* adjust to a multiple of 256) */
if (size < (omax-Yap_GlobalBase)/8) if (size < (omax-Yap_GlobalBase)/8)
@ -631,7 +633,7 @@ static_growglobal(long size, CELL **ptr)
Yap_ErrorMessage = NULL; Yap_ErrorMessage = NULL;
if (!Yap_ExtendWorkSpace(size)) { if (!Yap_ExtendWorkSpace(size)) {
Yap_ErrorMessage = "Global Stack crashed against Local Stack"; Yap_ErrorMessage = "Global Stack crashed against Local Stack";
return(FALSE); return FALSE;
} }
start_growth_time = Yap_cputime(); start_growth_time = Yap_cputime();
gc_verbose = Yap_is_gc_verbose(); gc_verbose = Yap_is_gc_verbose();
@ -642,8 +644,11 @@ static_growglobal(long size, CELL **ptr)
} }
ASP -= 256; ASP -= 256;
YAPEnterCriticalSection(); YAPEnterCriticalSection();
TrDiff = LDiff = GDiff = size; ReallocDiff = Yap_GlobalBase-old_GlobalBase;
XDiff = HDiff = DelayDiff = 0; TrDiff = LDiff = GDiff = size + ReallocDiff;
DelayDiff = ReallocDiff;
XDiff = HDiff = 0;
Yap_GlobalBase = old_GlobalBase;
SetHeapRegs(); SetHeapRegs();
MoveLocalAndTrail(); MoveLocalAndTrail();
MoveGlobalOnly(); MoveGlobalOnly();

View File

@ -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.85 2005-10-28 17:38:50 vsc Exp $ * * version: $Id: Heap.h,v 1.86 2005-11-17 13:40:18 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* information that can be stored in Code Space */ /* information that can be stored in Code Space */
@ -46,7 +46,7 @@ typedef struct scratch_block_struct {
} scratch_block; } scratch_block;
typedef struct restore_info { typedef struct restore_info {
int cl_diff, Int cl_diff,
g_diff, g_diff,
h_diff, h_diff,
l_diff, l_diff,

View File

@ -943,9 +943,9 @@ typedef struct array_entry
Int ArrayEArity; /* Arity of Array (positive) */ Int ArrayEArity; /* Arity of Array (positive) */
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
rwlock_t ArRWLock; /* a read-write lock to protect the entry */ rwlock_t ArRWLock; /* a read-write lock to protect the entry */
#endif
#if THREADS #if THREADS
unsigned int owner_id; unsigned int owner_id;
#endif
#endif #endif
struct array_entry *NextAE; struct array_entry *NextAE;
Term ValueOfVE; /* Pointer to the actual array */ Term ValueOfVE; /* Pointer to the actual array */

View File

@ -16,6 +16,8 @@
<h2>Yap-5.1.0:</h2> <h2>Yap-5.1.0:</h2>
<ul> <ul>
<li> FIXED: growglobal with realloc was broken. </li>
<li> FIXED: with threads, self-deadlocking in new array codes. </li>
<li> FIXED: in tabling, use malloc when AllocCodeSpace fails. </li> <li> FIXED: in tabling, use malloc when AllocCodeSpace fails. </li>
<li> FIXED: in tabling don't look inside cp_ap == NULL and fix recent <li> FIXED: in tabling don't look inside cp_ap == NULL and fix recent
bug in walking dependency frames. </li> bug in walking dependency frames. </li>