Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3
This commit is contained in:
commit
0ed4e15925
2
C/load_dll.c
Normal file → Executable file
2
C/load_dll.c
Normal file → Executable file
@ -62,7 +62,7 @@ static Int
|
||||
LoadForeign(StringList ofiles, StringList libs,
|
||||
char *proc_name, YapInitProc *init_proc)
|
||||
{
|
||||
|
||||
CACHE_REGS
|
||||
while (ofiles) {
|
||||
HINSTANCE handle;
|
||||
|
||||
|
@ -22,6 +22,9 @@
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#define LOCK() PL_LOCK(L_PLFLAG)
|
||||
#define UNLOCK() PL_UNLOCK(L_PLFLAG)
|
||||
|
||||
int fileerrors;
|
||||
|
||||
PL_local_data_t lds;
|
||||
@ -1020,7 +1023,7 @@ PL_w32thread_raise(DWORD id, int sig)
|
||||
{ PL_thread_info_t *info = GD->thread.threads[i];
|
||||
|
||||
if ( info && info->w32id == id && info->thread_data )
|
||||
{ raiseSignal(info->thread_data, sig);
|
||||
{ Yap_signal(sig); //raiseSignal(info->thread_data, sig);
|
||||
if ( info->w32id )
|
||||
PostThreadMessage(info->w32id, WM_SIGNALLED, 0, 0L);
|
||||
UNLOCK();
|
||||
|
14
C/stdpreds.c
14
C/stdpreds.c
@ -3227,7 +3227,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
|
||||
FunctorEntry *pp = RepFunctorProp(pf);
|
||||
if (IsFunctorProperty(pp->KindOfPE)) {
|
||||
Prop p0;
|
||||
READ_LOCK(pp->RWLock);
|
||||
READ_LOCK(pp->FRWLock);
|
||||
p0 = pp->PropsOfFE;
|
||||
if (p0) {
|
||||
PredEntry *p = RepPredProp(p0);
|
||||
@ -3236,7 +3236,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
|
||||
UInt ar = p->ArityOfPE;
|
||||
/* we found the predicate */
|
||||
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
|
||||
READ_UNLOCK(pp->RWLock);
|
||||
READ_UNLOCK(pp->FRWLock);
|
||||
return
|
||||
Yap_unify(ARG3,MkIntegerTerm(ar));
|
||||
} else if (p->NextOfPE) {
|
||||
@ -3249,7 +3249,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
|
||||
p->ModuleOfPred == mod)
|
||||
{
|
||||
READ_UNLOCK(PredHashRWLock);
|
||||
READ_UNLOCK(pp->RWLock);
|
||||
READ_UNLOCK(pp->FRWLock);
|
||||
/* we found the predicate */
|
||||
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(p->NextOfPE));
|
||||
return Yap_unify(ARG3,MkIntegerTerm(p->ArityOfPE));
|
||||
@ -3259,18 +3259,18 @@ cont_current_predicate_for_atom( USES_REGS1 )
|
||||
READ_UNLOCK(PredHashRWLock);
|
||||
}
|
||||
}
|
||||
READ_UNLOCK(pp->RWLock);
|
||||
READ_UNLOCK(pp->FRWLock);
|
||||
} else if (pp->KindOfPE == PEProp) {
|
||||
PredEntry *pe = RepPredProp(pf);
|
||||
READ_LOCK(pp->RWLock);
|
||||
READ_LOCK(pp->FRWLock);
|
||||
if (pe->ModuleOfPred == mod ||
|
||||
pe->ModuleOfPred == 0) {
|
||||
/* we found the predicate */
|
||||
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
|
||||
READ_UNLOCK(pp->RWLock);
|
||||
READ_UNLOCK(pp->FRWLock);
|
||||
return Yap_unify(ARG3,MkIntTerm(0));
|
||||
}
|
||||
READ_UNLOCK(pp->RWLock);
|
||||
READ_UNLOCK(pp->FRWLock);
|
||||
}
|
||||
pf = pp->NextOfPE;
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ sub_utime(FILETIME t1, FILETIME t2)
|
||||
#endif
|
||||
|
||||
UInt
|
||||
Yap_cputime ( USES_REGS1 )
|
||||
Yap_cputime ( void )
|
||||
{
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
FILETIME CreationTime, ExitTime, KernelTime, UserTime;
|
||||
@ -1775,6 +1775,7 @@ ReceiveSignal (int s)
|
||||
#if (_MSC_VER || defined(__MINGW32__))
|
||||
static BOOL WINAPI
|
||||
MSCHandleSignal(DWORD dwCtrlType) {
|
||||
CACHE_REGS
|
||||
if (LOCAL_InterruptsDisabled) {
|
||||
return FALSE;
|
||||
}
|
||||
|
12
C/threads.c
Normal file → Executable file
12
C/threads.c
Normal file → Executable file
@ -346,7 +346,7 @@ p_create_thread( USES_REGS1 )
|
||||
/* make sure we can proceed */
|
||||
if (!init_thread_engine(new_worker_id, ssize, tsize, sysize, &ARG1, &ARG5, &ARG6))
|
||||
return FALSE;
|
||||
REMOTE_ThreadHandle(new_worker_id).pthread_handle = 0L;
|
||||
//REMOTE_ThreadHandle(new_worker_id).pthread_handle = 0L;
|
||||
REMOTE_ThreadHandle(new_worker_id).id = new_worker_id;
|
||||
REMOTE_ThreadHandle(new_worker_id).ref_count = 1;
|
||||
if ((REMOTE_ThreadHandle(new_worker_id).ret = pthread_create(&REMOTE_ThreadHandle(new_worker_id).pthread_handle, NULL, thread_run, (void *)(&(REMOTE_ThreadHandle(new_worker_id).id)))) == 0) {
|
||||
@ -470,19 +470,19 @@ Yap_thread_create_engine(thread_attr *ops)
|
||||
ops->sysize = 0;
|
||||
ops->egoal = t;
|
||||
}
|
||||
if (pthread_self() != GLOBAL_master_thread) {
|
||||
if (!pthread_equal(pthread_self() , GLOBAL_master_thread) ) {
|
||||
/* we are worker_id 0 for now, lock master thread so that no one messes with us */
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
|
||||
pthread_mutex_lock(&(REMOTE_ThreadHandle(0).tlock));
|
||||
}
|
||||
if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
|
||||
return -1;
|
||||
REMOTE_ThreadHandle(new_id).pthread_handle = 0L;
|
||||
//REMOTE_ThreadHandle(new_id).pthread_handle = 0L;
|
||||
REMOTE_ThreadHandle(new_id).id = new_id;
|
||||
REMOTE_ThreadHandle(new_id).ref_count = 0;
|
||||
if (!setup_engine(new_id, FALSE))
|
||||
return -1;
|
||||
if (pthread_self() != GLOBAL_master_thread) {
|
||||
if (!pthread_equal(pthread_self(), GLOBAL_master_thread)) {
|
||||
pthread_setspecific(Yap_yaamregs_key, NULL);
|
||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(0).tlock));
|
||||
}
|
||||
@ -518,7 +518,7 @@ Yap_thread_detach_engine(int wid)
|
||||
{
|
||||
DEBUG_TLOCK_ACCESS(10, wid);
|
||||
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
REMOTE_ThreadHandle(wid).pthread_handle = 0;
|
||||
//REMOTE_ThreadHandle(wid).pthread_handle = 0;
|
||||
REMOTE_ThreadHandle(wid).ref_count--;
|
||||
pthread_setspecific(Yap_yaamregs_key, NULL);
|
||||
DEBUG_TLOCK_ACCESS(11, wid);
|
||||
@ -678,7 +678,7 @@ p_new_mutex( USES_REGS1 )
|
||||
{
|
||||
SWIMutex* mutp;
|
||||
pthread_mutexattr_t mat;
|
||||
#ifdef HAVE_PTHREAD_MUTEXATTR_SETKIND_NP
|
||||
#if defined(HAVE_PTHREAD_MUTEXATTR_SETKIND_NP) && !defined(__MINGW32__)
|
||||
extern int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
|
||||
#endif
|
||||
|
||||
|
17
H/pl-incl.h
17
H/pl-incl.h
@ -170,7 +170,9 @@ typedef enum
|
||||
#if __YAP_PROLOG__
|
||||
#include "pl-yap.h"
|
||||
#if _WIN32
|
||||
#ifndef THREADS
|
||||
typedef int pthread_t;
|
||||
#endif
|
||||
#define __WINDOWS__ 1
|
||||
#else
|
||||
#include <pthread.h>
|
||||
@ -198,6 +200,21 @@ typedef uintptr_t PL_atomic_t; /* same a word */
|
||||
#define TRAIL_OVERFLOW (-3)
|
||||
#define ARGUMENT_OVERFLOW (-4)
|
||||
|
||||
|
||||
/********************************
|
||||
* THREADS *
|
||||
*********************************/
|
||||
|
||||
#include "pl-thread.h"
|
||||
|
||||
#if O_PLMT
|
||||
/*******************************
|
||||
* WINDOWS *
|
||||
*******************************/
|
||||
|
||||
#define WM_SIGNALLED (WM_USER+4201) /* how to select a good number!? */
|
||||
#endif
|
||||
|
||||
/********************************
|
||||
* UTILITIES *
|
||||
*********************************/
|
||||
|
@ -126,6 +126,7 @@ INTERFACE_HEADERS = \
|
||||
$(srcdir)/include/YapRegs.h \
|
||||
$(srcdir)/H/YapTerm.h \
|
||||
$(srcdir)/library/dialect/bprolog/fli/bprolog.h \
|
||||
$(srcdir)/os/pl-thread.h \
|
||||
$(srcdir)/os/SWI-Stream.h
|
||||
|
||||
IOLIB_HEADERS=$(srcdir)/os/pl-buffer.h \
|
||||
|
1
config.h.in
Normal file → Executable file
1
config.h.in
Normal file → Executable file
@ -153,6 +153,7 @@
|
||||
/* Define return type for signal */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
#undef HAVE__CHSIZE_S
|
||||
#undef HAVE__NSGETENVIRON
|
||||
#undef HAVE_ACCESS
|
||||
#undef HAVE_ACOSH
|
||||
|
16
configure.in
16
configure.in
@ -675,15 +675,19 @@ then
|
||||
YAP_TARGET=amd64
|
||||
AC_CHECK_LIB(ws2_32,main)
|
||||
AC_CHECK_LIB(comdlg32,main)
|
||||
AC_CHECK_LIB(shell32,main)
|
||||
EXTRA_LIBS_FOR_DLLS="-lws2_32"
|
||||
elif test "$target_os" = "cygwin"
|
||||
then
|
||||
CC="${CC} -mno-cygwin"
|
||||
CXX="${CXX} -mno-cygwin"
|
||||
AC_CHECK_LIB(comdlg32,main)
|
||||
AC_CHECK_LIB(wsock32,main)
|
||||
AC_CHECK_LIB(shell32,main)
|
||||
else
|
||||
AC_CHECK_LIB(wsock32,main)
|
||||
AC_CHECK_LIB(comdlg32,main)
|
||||
AC_CHECK_LIB(shell32,main)
|
||||
fi
|
||||
EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll $EXTRA_LIBS_FOR_DLLS"
|
||||
AC_CHECK_LIB(psapi,main)
|
||||
@ -1029,6 +1033,7 @@ if test "$yap_cv_java" = no; then
|
||||
ENABLE_JPL="@#"
|
||||
elif test -e "$srcdir"/packages/jpl/Makefile.in; then
|
||||
ENABLE_JPL=""
|
||||
LIBJPL=libjpl
|
||||
JAVA=java
|
||||
JAVA_HOME="$yap_cv_java"
|
||||
case "$target_os" in
|
||||
@ -1063,10 +1068,10 @@ elif test -e "$srcdir"/packages/jpl/Makefile.in; then
|
||||
JAVAC=javac
|
||||
JAVADOC=javadoc
|
||||
else
|
||||
JAVA="$yap_cv_java"/bin/java
|
||||
JAR="$yap_cv_java"/bin/jar
|
||||
JAVAC="$yap_cv_java"/bin/javac
|
||||
JAVADOC="$yap_cv_java"/bin/javadoc
|
||||
JAVA=$yap_cv_java/bin/java
|
||||
JAR=$yap_cv_java/bin/jar
|
||||
JAVAC=$yap_cv_java/bin/javac
|
||||
JAVADOC=$yap_cv_java/bin/javadoc
|
||||
fi
|
||||
else
|
||||
ENABLE_JPL="@#"
|
||||
@ -1800,6 +1805,7 @@ AC_SUBST(JUNIT)
|
||||
AC_SUBST(JAVAC)
|
||||
AC_SUBST(JAVADOC)
|
||||
AC_SUBST(JAR)
|
||||
AC_SUBST(LIBJPL)
|
||||
AC_SUBST(IN_UNIX)
|
||||
AC_SUBST(YAPMPILIB)
|
||||
AC_SUBST(LAM_MPI_CC)
|
||||
@ -2004,7 +2010,7 @@ fi
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS(_NSGetEnviron access acosh)
|
||||
AC_CHECK_FUNCS(_NSGetEnviron _chsize_s access acosh)
|
||||
AC_CHECK_FUNCS(alloca asinh atanh chdir clock clock_gettime)
|
||||
AC_CHECK_FUNCS(ctime dlopen dup2)
|
||||
AC_CHECK_FUNCS(erf feclearexcept)
|
||||
|
2
console/LGPL/pl-ntconsole.c
Normal file → Executable file
2
console/LGPL/pl-ntconsole.c
Normal file → Executable file
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#define WINDOWS_LEAN_AND_MEAN 1
|
||||
#if (_MSC_VER >= 1300)
|
||||
#if (_MSC_VER >= 1300) || defined(__MINGW32__)
|
||||
#include <winsock2.h> /* Needed on VC8 */
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
4
include/SWI-Prolog.h
Normal file → Executable file
4
include/SWI-Prolog.h
Normal file → Executable file
@ -662,11 +662,13 @@ PL_EXPORT(pl_wchar_t*) PL_atom_generator_w(const pl_wchar_t *pref,
|
||||
* WINDOWS MESSAGES *
|
||||
*******************************/
|
||||
|
||||
#ifdef _WINDOWS_ /* <windows.h> is included */
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__) /* <windows.h> is included */
|
||||
#define PL_MSG_EXCEPTION_RAISED -1
|
||||
#define PL_MSG_IGNORED 0
|
||||
#define PL_MSG_HANDLED 1
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
PL_EXPORT(LRESULT) PL_win_message_proc(HWND hwnd,
|
||||
UINT message,
|
||||
WPARAM wParam,
|
||||
|
@ -2595,7 +2595,7 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&(REMOTE_ThreadHandle(nwid).tlock));
|
||||
if (REMOTE_ThreadHandle(nwid).pthread_handle) {
|
||||
if (REMOTE_ThreadHandle(nwid).ref_count) {
|
||||
pthread_mutex_unlock(&(REMOTE_ThreadHandle(nwid).tlock));
|
||||
if (cwid != nwid) {
|
||||
return PL_ENGINE_INUSE;
|
||||
|
102
os/SWI-Stream.h
Normal file → Executable file
102
os/SWI-Stream.h
Normal file → Executable file
@ -94,107 +94,7 @@ typedef int64_t (*Sseek64_function)(void *handle, int64_t pos, int whence);
|
||||
typedef int (*Sclose_function)(void *handle);
|
||||
typedef int (*Scontrol_function)(void *handle, int action, void *arg);
|
||||
|
||||
#if defined(THREADS) && !defined(O_PLMT)
|
||||
#define O_PLMT 1
|
||||
#endif
|
||||
|
||||
#if defined(O_PLMT) && defined(PL_KERNEL)
|
||||
/* Support PL_LOCK in the interface */
|
||||
#if THREADS
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_mutex_t simpleMutex;
|
||||
|
||||
#define simpleMutexInit(p) pthread_mutex_init(p, NULL)
|
||||
#define simpleMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define simpleMutexLock(p) pthread_mutex_lock(p)
|
||||
#define simpleMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
typedef pthread_mutex_t recursiveMutex;
|
||||
|
||||
#define NEED_RECURSIVE_MUTEX_INIT 1
|
||||
extern int recursiveMutexInit(recursiveMutex *m);
|
||||
#define recursiveMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define recursiveMutexLock(p) pthread_mutex_lock(p)
|
||||
#define recursiveMutexTryLock(p) pthread_mutex_trylock(p)
|
||||
#define recursiveMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
#define IF_MT(id, g) if ( id == L_THREAD || GD->thread.enabled ) g
|
||||
|
||||
typedef struct counting_mutex
|
||||
{ simpleMutex mutex; /* mutex itself */
|
||||
const char *name; /* name of the mutex */
|
||||
long count; /* # times locked */
|
||||
long unlocked; /* # times unlocked */
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
long collisions; /* # contentions */
|
||||
#endif
|
||||
struct counting_mutex *next; /* next of allocated chain */
|
||||
} counting_mutex;
|
||||
|
||||
extern counting_mutex *allocSimpleMutex(const char *name);
|
||||
extern void freeSimpleMutex(counting_mutex *m);
|
||||
|
||||
extern counting_mutex _PL_mutexes[]; /* Prolog mutexes */
|
||||
|
||||
#define L_MISC 0
|
||||
#define L_ALLOC 1
|
||||
#define L_ATOM 2
|
||||
#define L_FLAG 3
|
||||
#define L_FUNCTOR 4
|
||||
#define L_RECORD 5
|
||||
#define L_THREAD 6
|
||||
#define L_PREDICATE 7
|
||||
#define L_MODULE 8
|
||||
#define L_TABLE 9
|
||||
#define L_BREAK 10
|
||||
#define L_FILE 11
|
||||
#define L_PLFLAG 12
|
||||
#define L_OP 13
|
||||
#define L_INIT 14
|
||||
#define L_TERM 15
|
||||
#define L_GC 16
|
||||
#define L_AGC 17
|
||||
#define L_FOREIGN 18
|
||||
#define L_OS 19
|
||||
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ if ( pthread_mutex_trylock(&(cm)->mutex) == EBUSY ) \
|
||||
{ (cm)->collisions++; \
|
||||
pthread_mutex_lock(&(cm)->mutex); \
|
||||
} \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#else
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ simpleMutexLock(&(cm)->mutex); \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#endif
|
||||
#define countingMutexUnlock(cm) \
|
||||
do \
|
||||
{ (cm)->unlocked++; \
|
||||
assert((cm)->unlocked <= (cm)->count); \
|
||||
simpleMutexUnlock(&(cm)->mutex); \
|
||||
} while(0)
|
||||
|
||||
#define PL_LOCK(id) IF_MT(id, countingMutexLock(&_PL_mutexes[id]))
|
||||
#define PL_UNLOCK(id) IF_MT(id, countingMutexUnlock(&_PL_mutexes[id]))
|
||||
|
||||
#define IOLOCK recursiveMutex
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define PL_LOCK(X)
|
||||
#define PL_UNLOCK(X)
|
||||
|
||||
typedef void * IOLOCK;
|
||||
#endif
|
||||
#include "pl-thread.h"
|
||||
|
||||
typedef struct io_functions
|
||||
{ Sread_function read; /* fill the buffer */
|
||||
|
14
os/pl-nt.c
14
os/pl-nt.c
@ -38,7 +38,7 @@
|
||||
|
||||
#include "pl-incl.h"
|
||||
#include "pl-utf8.h"
|
||||
#include <crtdbg.h>
|
||||
//#include <crtdbg.h>
|
||||
#include <process.h>
|
||||
#include "pl-ctype.h"
|
||||
#include <stdio.h>
|
||||
@ -234,10 +234,16 @@ Pause(double t)
|
||||
|
||||
int
|
||||
ftruncate(int fileno, int64_t length)
|
||||
{ errno_t e;
|
||||
{ int e;
|
||||
|
||||
#if HAVE__CHSIZE_S
|
||||
/* not always available in mingw */
|
||||
if ( (e=_chsize_s(fileno, length)) == 0 )
|
||||
return 0;
|
||||
#else
|
||||
if ( (e=_chsize(fileno, (long)length)) == 0 )
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
errno = e;
|
||||
return -1;
|
||||
@ -338,7 +344,7 @@ typedef struct
|
||||
} showtype;
|
||||
|
||||
static int
|
||||
get_showCmd(term_t show, int *cmd)
|
||||
get_showCmd(term_t show, UINT *cmd)
|
||||
{ char *s;
|
||||
showtype *st;
|
||||
static showtype types[] =
|
||||
@ -721,7 +727,7 @@ static int
|
||||
unify_csidl_path(term_t t, int csidl)
|
||||
{ wchar_t buf[MAX_PATH];
|
||||
|
||||
if ( SHGetSpecialFolderPathW(0, buf, csidl, FALSE) )
|
||||
if ( SHGetFolderPathW(0, csidl, NULL, FALSE, buf) )
|
||||
{ wchar_t *p;
|
||||
|
||||
for(p=buf; *p; p++)
|
||||
|
107
os/pl-thread.h
Executable file
107
os/pl-thread.h
Executable file
@ -0,0 +1,107 @@
|
||||
#ifndef PL_THREAD_H
|
||||
|
||||
#define PL_THREAD_H 1
|
||||
|
||||
#if defined(THREADS) && !defined(O_PLMT)
|
||||
#define O_PLMT 1
|
||||
#endif
|
||||
|
||||
#if defined(O_PLMT) // && defined(PL_KERNEL)
|
||||
/* Support PL_LOCK in the interface */
|
||||
#if THREADS
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_mutex_t simpleMutex;
|
||||
|
||||
#define simpleMutexInit(p) pthread_mutex_init(p, NULL)
|
||||
#define simpleMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define simpleMutexLock(p) pthread_mutex_lock(p)
|
||||
#define simpleMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
typedef pthread_mutex_t recursiveMutex;
|
||||
|
||||
#define NEED_RECURSIVE_MUTEX_INIT 1
|
||||
extern int recursiveMutexInit(recursiveMutex *m);
|
||||
#define recursiveMutexDelete(p) pthread_mutex_destroy(p)
|
||||
#define recursiveMutexLock(p) pthread_mutex_lock(p)
|
||||
#define recursiveMutexTryLock(p) pthread_mutex_trylock(p)
|
||||
#define recursiveMutexUnlock(p) pthread_mutex_unlock(p)
|
||||
|
||||
#define IF_MT(id, g) if ( id == L_THREAD || GD->thread.enabled ) g
|
||||
|
||||
typedef struct counting_mutex
|
||||
{ simpleMutex mutex; /* mutex itself */
|
||||
const char *name; /* name of the mutex */
|
||||
long count; /* # times locked */
|
||||
long unlocked; /* # times unlocked */
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
long collisions; /* # contentions */
|
||||
#endif
|
||||
struct counting_mutex *next; /* next of allocated chain */
|
||||
} counting_mutex;
|
||||
|
||||
extern counting_mutex *allocSimpleMutex(const char *name);
|
||||
extern void freeSimpleMutex(counting_mutex *m);
|
||||
|
||||
extern counting_mutex _PL_mutexes[]; /* Prolog mutexes */
|
||||
|
||||
#define L_MISC 0
|
||||
#define L_ALLOC 1
|
||||
#define L_ATOM 2
|
||||
#define L_FLAG 3
|
||||
#define L_FUNCTOR 4
|
||||
#define L_RECORD 5
|
||||
#define L_THREAD 6
|
||||
#define L_PREDICATE 7
|
||||
#define L_MODULE 8
|
||||
#define L_TABLE 9
|
||||
#define L_BREAK 10
|
||||
#define L_FILE 11
|
||||
#define L_PLFLAG 12
|
||||
#define L_OP 13
|
||||
#define L_INIT 14
|
||||
#define L_TERM 15
|
||||
#define L_GC 16
|
||||
#define L_AGC 17
|
||||
#define L_FOREIGN 18
|
||||
#define L_OS 19
|
||||
|
||||
#ifdef O_CONTENTION_STATISTICS
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ if ( pthread_mutex_trylock(&(cm)->mutex) == EBUSY ) \
|
||||
{ (cm)->collisions++; \
|
||||
pthread_mutex_lock(&(cm)->mutex); \
|
||||
} \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#else
|
||||
#define countingMutexLock(cm) \
|
||||
do \
|
||||
{ simpleMutexLock(&(cm)->mutex); \
|
||||
(cm)->count++; \
|
||||
} while(0)
|
||||
#endif
|
||||
#define countingMutexUnlock(cm) \
|
||||
do \
|
||||
{ (cm)->unlocked++; \
|
||||
assert((cm)->unlocked <= (cm)->count); \
|
||||
simpleMutexUnlock(&(cm)->mutex); \
|
||||
} while(0)
|
||||
|
||||
#define PL_LOCK(id) IF_MT(id, countingMutexLock(&_PL_mutexes[id]))
|
||||
#define PL_UNLOCK(id) IF_MT(id, countingMutexUnlock(&_PL_mutexes[id]))
|
||||
|
||||
#define IOLOCK recursiveMutex
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define PL_LOCK(X)
|
||||
#define PL_UNLOCK(X)
|
||||
|
||||
typedef void * IOLOCK;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -53,6 +53,12 @@ volatile(P) :-
|
||||
'$new_mutex'(Id),
|
||||
assert_static(prolog:'$with_mutex_mutex'(Id)).
|
||||
|
||||
'$reinit_thread0' :-
|
||||
'$create_thread_mq'(0),
|
||||
% abolish(prolog:'$with_mutex_mutex',1),
|
||||
'$new_mutex'(Id),
|
||||
asserta_static((prolog:'$with_mutex_mutex'(Id) :- !)).
|
||||
|
||||
'$top_thread_goal'(G, Detached) :-
|
||||
'$thread_self'(Id),
|
||||
(Detached == true -> '$detach_thread'(Id) ; true),
|
||||
|
Reference in New Issue
Block a user