begin of support for named mutexes.
This commit is contained in:
parent
ff6184863f
commit
50659967ed
30
C/adtdefs.c
30
C/adtdefs.c
@ -1242,7 +1242,7 @@ Yap_PutValue(Atom a, Term v)
|
|||||||
WRITE_UNLOCK(p->VRWLock);
|
WRITE_UNLOCK(p->VRWLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
Yap_PutAtomTranslation(Atom a, Int i)
|
Yap_PutAtomTranslation(Atom a, Int i)
|
||||||
{
|
{
|
||||||
AtomEntry *ae = RepAtom(a);
|
AtomEntry *ae = RepAtom(a);
|
||||||
@ -1255,7 +1255,7 @@ Yap_PutAtomTranslation(Atom a, Int i)
|
|||||||
p = (TranslationEntry *) Yap_AllocAtomSpace(sizeof(TranslationEntry));
|
p = (TranslationEntry *) Yap_AllocAtomSpace(sizeof(TranslationEntry));
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
WRITE_UNLOCK(ae->ARWLock);
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
p->KindOfPE = TranslationProperty;
|
p->KindOfPE = TranslationProperty;
|
||||||
p->Translation = i;
|
p->Translation = i;
|
||||||
@ -1264,6 +1264,32 @@ Yap_PutAtomTranslation(Atom a, Int i)
|
|||||||
/* take care that the lock for the property will be inited even
|
/* take care that the lock for the property will be inited even
|
||||||
if someone else searches for the property */
|
if someone else searches for the property */
|
||||||
WRITE_UNLOCK(ae->ARWLock);
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Yap_PutAtomMutex(Atom a, void * i)
|
||||||
|
{
|
||||||
|
AtomEntry *ae = RepAtom(a);
|
||||||
|
Prop p0;
|
||||||
|
MutexEntry *p;
|
||||||
|
|
||||||
|
WRITE_LOCK(ae->ARWLock);
|
||||||
|
p0 = GetAPropHavingLock(ae, MutexProperty);
|
||||||
|
if (p0 == NIL) {
|
||||||
|
p = (MutexEntry *) Yap_AllocAtomSpace(sizeof(MutexEntry));
|
||||||
|
if (p == NULL) {
|
||||||
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
p->KindOfPE = MutexProperty;
|
||||||
|
p->Mutex = i;
|
||||||
|
AddPropToAtom(RepAtom(a), (PropEntry *)p);
|
||||||
|
}
|
||||||
|
/* take care that the lock for the property will be inited even
|
||||||
|
if someone else searches for the property */
|
||||||
|
WRITE_UNLOCK(ae->ARWLock);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Term
|
Term
|
||||||
|
17
C/threads.c
17
C/threads.c
@ -832,13 +832,10 @@ p_thread_exit( USES_REGS1 )
|
|||||||
static Int
|
static Int
|
||||||
p_thread_set_concurrency( USES_REGS1 )
|
p_thread_set_concurrency( USES_REGS1 )
|
||||||
{
|
{
|
||||||
Term tnew = Deref(ARG2);
|
|
||||||
int newc;
|
|
||||||
#if HAVE_PTHREAD_GETCONCURRENCY
|
#if HAVE_PTHREAD_GETCONCURRENCY
|
||||||
|
int newc;
|
||||||
int cur;
|
int cur;
|
||||||
#endif
|
Term tnew = Deref(ARG2);
|
||||||
|
|
||||||
|
|
||||||
if (IsVarTerm(tnew)) {
|
if (IsVarTerm(tnew)) {
|
||||||
newc = 0;
|
newc = 0;
|
||||||
} else if (IsIntegerTerm(tnew)) {
|
} else if (IsIntegerTerm(tnew)) {
|
||||||
@ -847,7 +844,6 @@ int cur;
|
|||||||
Yap_Error(TYPE_ERROR_INTEGER,tnew,"thread_set_concurrency/2");
|
Yap_Error(TYPE_ERROR_INTEGER,tnew,"thread_set_concurrency/2");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
#if HAVE_PTHREAD_GETCONCURRENCY
|
|
||||||
cur = MkIntegerTerm(pthread_getconcurrency());
|
cur = MkIntegerTerm(pthread_getconcurrency());
|
||||||
if (pthread_setconcurrency(newc) != 0) {
|
if (pthread_setconcurrency(newc) != 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -906,7 +902,11 @@ p_new_mutex( USES_REGS1 )
|
|||||||
pthread_mutex_init(&mutp->m, &mat);
|
pthread_mutex_init(&mutp->m, &mat);
|
||||||
mutp->owners = 0;
|
mutp->owners = 0;
|
||||||
mutp->tid_own = 0;
|
mutp->tid_own = 0;
|
||||||
return Yap_unify(ARG1, MkIntegerTerm((Int)mutp));
|
if (IsVarTerm((t1 = Deref(ARG1)))) {
|
||||||
|
return Yap_unify(t1, MkAddressTerm(mutp));
|
||||||
|
} else if(IsAtomTerm(t1)) {
|
||||||
|
return Yap_PutAtomMutex( AtomOfTerm(t1), mutp );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1276,7 +1276,8 @@ p_new_mutex( USES_REGS1 )
|
|||||||
|
|
||||||
if (pthread_cond_broadcast(condp) < 0)
|
if (pthread_cond_broadcast(condp) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
v return TRUE;
|
else
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
|
88
H/Yatom.h
88
H/Yatom.h
@ -1252,7 +1252,7 @@ AbsTranslationProp (TranslationEntry * p)
|
|||||||
#endif
|
#endif
|
||||||
#define TranslationProperty 0xfff4
|
#define TranslationProperty 0xfff4
|
||||||
|
|
||||||
void Yap_PutAtomTranslation(Atom a, Int i);
|
bool Yap_PutAtomTranslation(Atom a, Int i);
|
||||||
|
|
||||||
/* get translation prop for atom; */
|
/* get translation prop for atom; */
|
||||||
static inline TranslationEntry *
|
static inline TranslationEntry *
|
||||||
@ -1271,9 +1271,6 @@ Yap_GetTranslationProp(Atom at)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* only unary and binary expressions are acceptable */
|
|
||||||
|
|
||||||
INLINE_ONLY inline EXTERN PropFlags IsTranslationProperty (int);
|
INLINE_ONLY inline EXTERN PropFlags IsTranslationProperty (int);
|
||||||
|
|
||||||
INLINE_ONLY inline EXTERN PropFlags
|
INLINE_ONLY inline EXTERN PropFlags
|
||||||
@ -1282,6 +1279,89 @@ IsTranslationProperty (int flags)
|
|||||||
return (PropFlags) ((flags == TranslationProperty));
|
return (PropFlags) ((flags == TranslationProperty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** handle named mutexes */
|
||||||
|
|
||||||
|
/* translationnamed mutex property entry structure */
|
||||||
|
typedef struct mutex_entry
|
||||||
|
{
|
||||||
|
Prop NextOfPE; /* used to chain properties */
|
||||||
|
PropFlags KindOfPE; /* kind of property */
|
||||||
|
void *Mutex; /* used to hash the atom as an integer; */
|
||||||
|
} MutexEntry;
|
||||||
|
|
||||||
|
#if USE_OFFSETS_IN_PROPS
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN MutexEntry *RepMutexProp (Prop p);
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN MutexEntry *
|
||||||
|
RepMutexProp (Prop p)
|
||||||
|
{
|
||||||
|
return (MutexEntry *) (AtomBase + Unsigned (p));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN Prop AbsMutexProp (MutexEntry * p);
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN Prop
|
||||||
|
AbsMutexProp (MutexEntry * p)
|
||||||
|
{
|
||||||
|
return (Prop) (Addr (p) - AtomBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN MutexEntry *RepMutexProp (Prop p);
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN MutexEntry *
|
||||||
|
RepMutexProp (Prop p)
|
||||||
|
{
|
||||||
|
return (MutexEntry *) (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN Prop AbsMutexProp (MutexEntry * p);
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN Prop
|
||||||
|
AbsMutexProp (MutexEntry * p)
|
||||||
|
{
|
||||||
|
return (Prop) (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#define MutexProperty 0xfff5
|
||||||
|
|
||||||
|
bool Yap_PutAtomMutex(Atom a, void *ptr);
|
||||||
|
|
||||||
|
/* get mutex prop for atom; */
|
||||||
|
static inline MutexEntry *
|
||||||
|
Yap_GetMutexProp(Atom at)
|
||||||
|
{
|
||||||
|
Prop p0;
|
||||||
|
AtomEntry *ae = RepAtom(at);
|
||||||
|
MutexEntry *p;
|
||||||
|
|
||||||
|
READ_LOCK(ae->ARWLock);
|
||||||
|
p = RepMutexProp(p0 = ae->PropsOfAE);
|
||||||
|
while (p0 && p->KindOfPE != MutexProperty)
|
||||||
|
p = RepMutexProp(p0 = p->NextOfPE);
|
||||||
|
READ_UNLOCK(ae->ARWLock);
|
||||||
|
if (p0 == NIL) return NULL;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN PropFlags IsMutexProperty (int);
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN PropFlags
|
||||||
|
IsMutexProperty (int flags)
|
||||||
|
{
|
||||||
|
return (PropFlags) ((flags == MutexProperty));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code for named mutexes */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STATIC_ARRAY = 1,
|
STATIC_ARRAY = 1,
|
||||||
|
Reference in New Issue
Block a user