support thread local IDB
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@979 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
eec29d7c27
commit
e612cb2f84
24
C/adtdefs.c
24
C/adtdefs.c
@ -311,6 +311,12 @@ GetPredPropByAtomHavingLock(AtomEntry* ae, SMALLUNSGN cur_mod)
|
||||
if ( pe->KindOfPE == PEProp &&
|
||||
(pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) {
|
||||
return(p0);
|
||||
#if THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (pe->PredFlags & ThreadLocalPredFlag) {
|
||||
return AbsPredProp(Yap_GetThreadPred(pe));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
p0 = pe->NextOfPE;
|
||||
}
|
||||
@ -341,6 +347,12 @@ GetPredPropByAtomHavingLockInThisModule(AtomEntry* ae, SMALLUNSGN cur_mod)
|
||||
while (p0) {
|
||||
PredEntry *pe = RepPredProp(p0);
|
||||
if ( pe->KindOfPE == PEProp && pe->ModuleOfPred == cur_mod ) {
|
||||
#if THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (pe->PredFlags & ThreadLocalPredFlag) {
|
||||
return AbsPredProp(Yap_GetThreadPred(pe));
|
||||
}
|
||||
#endif
|
||||
return(p0);
|
||||
}
|
||||
p0 = pe->NextOfPE;
|
||||
@ -374,6 +386,12 @@ GetPredPropByFuncHavingLock(Functor f, SMALLUNSGN cur_mod)
|
||||
PredEntry *p = RepPredProp(p0);
|
||||
if (/* p->KindOfPE != 0 || only props */
|
||||
(p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) {
|
||||
#if THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (p->PredFlags & ThreadLocalPredFlag) {
|
||||
return AbsPredProp(Yap_GetThreadPred(p));
|
||||
}
|
||||
#endif
|
||||
return (p0);
|
||||
}
|
||||
p0 = p->NextOfPE;
|
||||
@ -404,6 +422,12 @@ GetPredPropByFuncHavingLockInThisModule(Functor f, SMALLUNSGN cur_mod)
|
||||
while (p0) {
|
||||
PredEntry *p = RepPredProp(p0);
|
||||
if (p->ModuleOfPred == cur_mod) {
|
||||
#if THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (p->PredFlags & ThreadLocalPredFlag) {
|
||||
return AbsPredProp(Yap_GetThreadPred(p));
|
||||
}
|
||||
#endif
|
||||
return (p0);
|
||||
}
|
||||
p0 = p->NextOfPE;
|
||||
|
43
C/dbase.c
43
C/dbase.c
@ -4902,6 +4902,48 @@ Yap_ReleaseTermFromDB(DBTerm *ref)
|
||||
ReleaseTermFromDB(ref);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_install_thread_local(void)
|
||||
{ /* '$is_dynamic'(+P) */
|
||||
PredEntry *pe;
|
||||
Term t = Deref(ARG1);
|
||||
Term t2 = Deref(ARG2);
|
||||
SMALLUNSGN mod = Yap_LookupModule(t2);
|
||||
|
||||
if (IsVarTerm(t)) {
|
||||
return (FALSE);
|
||||
}
|
||||
if (mod == IDB_MODULE) {
|
||||
pe = find_lu_entry(t);
|
||||
if (!pe->cs.p_code.NOfClauses) {
|
||||
if (IsIntegerTerm(t))
|
||||
pe->PredFlags |= LogUpdatePredFlag|NumberDBPredFlag;
|
||||
else if (IsAtomTerm(t))
|
||||
pe->PredFlags |= LogUpdatePredFlag|AtomDBPredFlag;
|
||||
else
|
||||
pe->PredFlags |= LogUpdatePredFlag;
|
||||
}
|
||||
} else if (IsAtomTerm(t)) {
|
||||
Atom at = AtomOfTerm(t);
|
||||
pe = RepPredProp(PredPropByAtom(at, mod));
|
||||
} else if (IsApplTerm(t)) {
|
||||
Functor fun = FunctorOfTerm(t);
|
||||
pe = RepPredProp(PredPropByFunc(fun, mod));
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
if (pe->PredFlags & (UserCPredFlag|HiddenPredFlag|CArgsPredFlag|SyncPredFlag|TestPredFlag|AsmPredFlag|StandardPredFlag|CPredFlag|SafePredFlag|IndexedPredFlag|BinaryTestPredFlag) ||
|
||||
pe->cs.p_code.NOfClauses) {
|
||||
return FALSE;
|
||||
}
|
||||
pe->PredFlags |= ThreadLocalPredFlag;
|
||||
pe->OpcodeOfPred = Yap_opcode(_thread_local);
|
||||
pe->CodeOfPred = (yamop *)&pe->OpcodeOfPred;
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitDBPreds(void)
|
||||
{
|
||||
@ -4943,6 +4985,7 @@ Yap_InitDBPreds(void)
|
||||
Yap_InitCPred("nth_instance", 3, p_nth_instance, SyncPredFlag);
|
||||
Yap_InitCPred("$nth_instancep", 3, p_nth_instancep, SyncPredFlag);
|
||||
Yap_InitCPred("$jump_to_next_dynamic_clause", 0, p_jump_to_next_dynamic_clause, SyncPredFlag);
|
||||
Yap_InitCPred("$install_thread_local", 2, p_install_thread_local, SafePredFlag);
|
||||
}
|
||||
|
||||
void
|
||||
|
30
C/threads.c
30
C/threads.c
@ -354,35 +354,6 @@ p_cond_wait(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_install_thread_local(void)
|
||||
{ /* '$is_dynamic'(+P) */
|
||||
PredEntry *pe;
|
||||
Term t = Deref(ARG1);
|
||||
Term t2 = Deref(ARG2);
|
||||
SMALLUNSGN mod = Yap_LookupModule(t2);
|
||||
|
||||
if (IsVarTerm(t)) {
|
||||
return (FALSE);
|
||||
} else if (IsAtomTerm(t)) {
|
||||
Atom at = AtomOfTerm(t);
|
||||
pe = RepPredProp(PredPropByAtom(at, mod));
|
||||
} else if (IsApplTerm(t)) {
|
||||
Functor fun = FunctorOfTerm(t);
|
||||
pe = RepPredProp(PredPropByFunc(fun, mod));
|
||||
} else
|
||||
return FALSE;
|
||||
WRITE_LOCK(pe->PRWLock);
|
||||
if (pe->PredFlags & (UserCPredFlag|HiddenPredFlag|CArgsPredFlag|SyncPredFlag|TestPredFlag|AsmPredFlag|StandardPredFlag|CPredFlag|SafePredFlag|IndexedPredFlag|BinaryTestPredFlag) ||
|
||||
pe->cs.p_code.FirstClause != NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
pe->PredFlags |= ThreadLocalPredFlag;
|
||||
pe->OpcodeOfPred = Yap_opcode(_thread_local);
|
||||
pe->CodeOfPred = (yamop *)&pe->OpcodeOfPred;
|
||||
WRITE_UNLOCK(pe->PRWLock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_thread_signal(void)
|
||||
@ -426,7 +397,6 @@ void Yap_InitThreadPreds(void)
|
||||
Yap_InitCPred("$cond_signal", 1, p_cond_signal, SafePredFlag);
|
||||
Yap_InitCPred("$cond_broadcast", 1, p_cond_broadcast, SafePredFlag);
|
||||
Yap_InitCPred("$cond_wait", 2, p_cond_wait, SafePredFlag);
|
||||
Yap_InitCPred("$install_thread_local", 2, p_install_thread_local, SafePredFlag);
|
||||
Yap_InitCPred("$signal_thread", 1, p_thread_signal, SafePredFlag);
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
#undef SUPPORT_CONDOR
|
||||
#undef SUPPORT_THREADS
|
||||
#undef USE_PTHREAD_LOCKING
|
||||
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
#undef NO_UNION_WAIT
|
||||
|
Reference in New Issue
Block a user