Merge branch 'master' of ssh://yap.git.sourceforge.net/gitroot/yap/yap-6.3

This commit is contained in:
Vítor Santos Costa 2012-06-29 21:40:10 +01:00
commit 0ed4e15925
17 changed files with 4495 additions and 14728 deletions

2
C/load_dll.c Normal file → Executable file
View File

@ -62,7 +62,7 @@ static Int
LoadForeign(StringList ofiles, StringList libs, LoadForeign(StringList ofiles, StringList libs,
char *proc_name, YapInitProc *init_proc) char *proc_name, YapInitProc *init_proc)
{ {
CACHE_REGS
while (ofiles) { while (ofiles) {
HINSTANCE handle; HINSTANCE handle;

View File

@ -22,6 +22,9 @@
#include <limits.h> #include <limits.h>
#endif #endif
#define LOCK() PL_LOCK(L_PLFLAG)
#define UNLOCK() PL_UNLOCK(L_PLFLAG)
int fileerrors; int fileerrors;
PL_local_data_t lds; 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]; { PL_thread_info_t *info = GD->thread.threads[i];
if ( info && info->w32id == id && info->thread_data ) if ( info && info->w32id == id && info->thread_data )
{ raiseSignal(info->thread_data, sig); { Yap_signal(sig); //raiseSignal(info->thread_data, sig);
if ( info->w32id ) if ( info->w32id )
PostThreadMessage(info->w32id, WM_SIGNALLED, 0, 0L); PostThreadMessage(info->w32id, WM_SIGNALLED, 0, 0L);
UNLOCK(); UNLOCK();

View File

@ -3227,7 +3227,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
FunctorEntry *pp = RepFunctorProp(pf); FunctorEntry *pp = RepFunctorProp(pf);
if (IsFunctorProperty(pp->KindOfPE)) { if (IsFunctorProperty(pp->KindOfPE)) {
Prop p0; Prop p0;
READ_LOCK(pp->RWLock); READ_LOCK(pp->FRWLock);
p0 = pp->PropsOfFE; p0 = pp->PropsOfFE;
if (p0) { if (p0) {
PredEntry *p = RepPredProp(p0); PredEntry *p = RepPredProp(p0);
@ -3236,7 +3236,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
UInt ar = p->ArityOfPE; UInt ar = p->ArityOfPE;
/* we found the predicate */ /* we found the predicate */
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE)); EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
READ_UNLOCK(pp->RWLock); READ_UNLOCK(pp->FRWLock);
return return
Yap_unify(ARG3,MkIntegerTerm(ar)); Yap_unify(ARG3,MkIntegerTerm(ar));
} else if (p->NextOfPE) { } else if (p->NextOfPE) {
@ -3249,7 +3249,7 @@ cont_current_predicate_for_atom( USES_REGS1 )
p->ModuleOfPred == mod) p->ModuleOfPred == mod)
{ {
READ_UNLOCK(PredHashRWLock); READ_UNLOCK(PredHashRWLock);
READ_UNLOCK(pp->RWLock); READ_UNLOCK(pp->FRWLock);
/* we found the predicate */ /* we found the predicate */
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(p->NextOfPE)); EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(p->NextOfPE));
return Yap_unify(ARG3,MkIntegerTerm(p->ArityOfPE)); return Yap_unify(ARG3,MkIntegerTerm(p->ArityOfPE));
@ -3259,18 +3259,18 @@ cont_current_predicate_for_atom( USES_REGS1 )
READ_UNLOCK(PredHashRWLock); READ_UNLOCK(PredHashRWLock);
} }
} }
READ_UNLOCK(pp->RWLock); READ_UNLOCK(pp->FRWLock);
} else if (pp->KindOfPE == PEProp) { } else if (pp->KindOfPE == PEProp) {
PredEntry *pe = RepPredProp(pf); PredEntry *pe = RepPredProp(pf);
READ_LOCK(pp->RWLock); READ_LOCK(pp->FRWLock);
if (pe->ModuleOfPred == mod || if (pe->ModuleOfPred == mod ||
pe->ModuleOfPred == 0) { pe->ModuleOfPred == 0) {
/* we found the predicate */ /* we found the predicate */
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE)); EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)(pp->NextOfPE));
READ_UNLOCK(pp->RWLock); READ_UNLOCK(pp->FRWLock);
return Yap_unify(ARG3,MkIntTerm(0)); return Yap_unify(ARG3,MkIntTerm(0));
} }
READ_UNLOCK(pp->RWLock); READ_UNLOCK(pp->FRWLock);
} }
pf = pp->NextOfPE; pf = pp->NextOfPE;
} }

View File

@ -471,7 +471,7 @@ sub_utime(FILETIME t1, FILETIME t2)
#endif #endif
UInt UInt
Yap_cputime ( USES_REGS1 ) Yap_cputime ( void )
{ {
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
FILETIME CreationTime, ExitTime, KernelTime, UserTime; FILETIME CreationTime, ExitTime, KernelTime, UserTime;
@ -1775,6 +1775,7 @@ ReceiveSignal (int s)
#if (_MSC_VER || defined(__MINGW32__)) #if (_MSC_VER || defined(__MINGW32__))
static BOOL WINAPI static BOOL WINAPI
MSCHandleSignal(DWORD dwCtrlType) { MSCHandleSignal(DWORD dwCtrlType) {
CACHE_REGS
if (LOCAL_InterruptsDisabled) { if (LOCAL_InterruptsDisabled) {
return FALSE; return FALSE;
} }

12
C/threads.c Normal file → Executable file
View File

@ -346,7 +346,7 @@ p_create_thread( USES_REGS1 )
/* make sure we can proceed */ /* make sure we can proceed */
if (!init_thread_engine(new_worker_id, ssize, tsize, sysize, &ARG1, &ARG5, &ARG6)) if (!init_thread_engine(new_worker_id, ssize, tsize, sysize, &ARG1, &ARG5, &ARG6))
return FALSE; 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).id = new_worker_id;
REMOTE_ThreadHandle(new_worker_id).ref_count = 1; 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) { 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->sysize = 0;
ops->egoal = t; 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 */ /* 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_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
pthread_mutex_lock(&(REMOTE_ThreadHandle(0).tlock)); pthread_mutex_lock(&(REMOTE_ThreadHandle(0).tlock));
} }
if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal))) if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
return -1; 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).id = new_id;
REMOTE_ThreadHandle(new_id).ref_count = 0; REMOTE_ThreadHandle(new_id).ref_count = 0;
if (!setup_engine(new_id, FALSE)) if (!setup_engine(new_id, FALSE))
return -1; return -1;
if (pthread_self() != GLOBAL_master_thread) { if (!pthread_equal(pthread_self(), GLOBAL_master_thread)) {
pthread_setspecific(Yap_yaamregs_key, NULL); pthread_setspecific(Yap_yaamregs_key, NULL);
pthread_mutex_unlock(&(REMOTE_ThreadHandle(0).tlock)); pthread_mutex_unlock(&(REMOTE_ThreadHandle(0).tlock));
} }
@ -518,7 +518,7 @@ Yap_thread_detach_engine(int wid)
{ {
DEBUG_TLOCK_ACCESS(10, wid); DEBUG_TLOCK_ACCESS(10, wid);
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock)); pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
REMOTE_ThreadHandle(wid).pthread_handle = 0; //REMOTE_ThreadHandle(wid).pthread_handle = 0;
REMOTE_ThreadHandle(wid).ref_count--; REMOTE_ThreadHandle(wid).ref_count--;
pthread_setspecific(Yap_yaamregs_key, NULL); pthread_setspecific(Yap_yaamregs_key, NULL);
DEBUG_TLOCK_ACCESS(11, wid); DEBUG_TLOCK_ACCESS(11, wid);
@ -678,7 +678,7 @@ p_new_mutex( USES_REGS1 )
{ {
SWIMutex* mutp; SWIMutex* mutp;
pthread_mutexattr_t mat; 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); extern int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
#endif #endif

View File

@ -170,7 +170,9 @@ typedef enum
#if __YAP_PROLOG__ #if __YAP_PROLOG__
#include "pl-yap.h" #include "pl-yap.h"
#if _WIN32 #if _WIN32
#ifndef THREADS
typedef int pthread_t; typedef int pthread_t;
#endif
#define __WINDOWS__ 1 #define __WINDOWS__ 1
#else #else
#include <pthread.h> #include <pthread.h>
@ -198,6 +200,21 @@ typedef uintptr_t PL_atomic_t; /* same a word */
#define TRAIL_OVERFLOW (-3) #define TRAIL_OVERFLOW (-3)
#define ARGUMENT_OVERFLOW (-4) #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 * * UTILITIES *
*********************************/ *********************************/

View File

@ -126,6 +126,7 @@ INTERFACE_HEADERS = \
$(srcdir)/include/YapRegs.h \ $(srcdir)/include/YapRegs.h \
$(srcdir)/H/YapTerm.h \ $(srcdir)/H/YapTerm.h \
$(srcdir)/library/dialect/bprolog/fli/bprolog.h \ $(srcdir)/library/dialect/bprolog/fli/bprolog.h \
$(srcdir)/os/pl-thread.h \
$(srcdir)/os/SWI-Stream.h $(srcdir)/os/SWI-Stream.h
IOLIB_HEADERS=$(srcdir)/os/pl-buffer.h \ IOLIB_HEADERS=$(srcdir)/os/pl-buffer.h \

1
config.h.in Normal file → Executable file
View File

@ -153,6 +153,7 @@
/* Define return type for signal */ /* Define return type for signal */
#undef RETSIGTYPE #undef RETSIGTYPE
#undef HAVE__CHSIZE_S
#undef HAVE__NSGETENVIRON #undef HAVE__NSGETENVIRON
#undef HAVE_ACCESS #undef HAVE_ACCESS
#undef HAVE_ACOSH #undef HAVE_ACOSH

18915
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -675,15 +675,19 @@ then
YAP_TARGET=amd64 YAP_TARGET=amd64
AC_CHECK_LIB(ws2_32,main) AC_CHECK_LIB(ws2_32,main)
AC_CHECK_LIB(comdlg32,main) AC_CHECK_LIB(comdlg32,main)
AC_CHECK_LIB(shell32,main)
EXTRA_LIBS_FOR_DLLS="-lws2_32" EXTRA_LIBS_FOR_DLLS="-lws2_32"
elif test "$target_os" = "cygwin" elif test "$target_os" = "cygwin"
then then
CC="${CC} -mno-cygwin" CC="${CC} -mno-cygwin"
CXX="${CXX} -mno-cygwin" CXX="${CXX} -mno-cygwin"
AC_CHECK_LIB(comdlg32,main)
AC_CHECK_LIB(wsock32,main) AC_CHECK_LIB(wsock32,main)
AC_CHECK_LIB(shell32,main)
else else
AC_CHECK_LIB(wsock32,main) AC_CHECK_LIB(wsock32,main)
AC_CHECK_LIB(comdlg32,main) AC_CHECK_LIB(comdlg32,main)
AC_CHECK_LIB(shell32,main)
fi fi
EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll $EXTRA_LIBS_FOR_DLLS" EXTRA_LIBS_FOR_DLLS="\$(abs_top_builddir)/yap.dll $EXTRA_LIBS_FOR_DLLS"
AC_CHECK_LIB(psapi,main) AC_CHECK_LIB(psapi,main)
@ -1029,6 +1033,7 @@ if test "$yap_cv_java" = no; then
ENABLE_JPL="@#" ENABLE_JPL="@#"
elif test -e "$srcdir"/packages/jpl/Makefile.in; then elif test -e "$srcdir"/packages/jpl/Makefile.in; then
ENABLE_JPL="" ENABLE_JPL=""
LIBJPL=libjpl
JAVA=java JAVA=java
JAVA_HOME="$yap_cv_java" JAVA_HOME="$yap_cv_java"
case "$target_os" in case "$target_os" in
@ -1063,10 +1068,10 @@ elif test -e "$srcdir"/packages/jpl/Makefile.in; then
JAVAC=javac JAVAC=javac
JAVADOC=javadoc JAVADOC=javadoc
else else
JAVA="$yap_cv_java"/bin/java JAVA=$yap_cv_java/bin/java
JAR="$yap_cv_java"/bin/jar JAR=$yap_cv_java/bin/jar
JAVAC="$yap_cv_java"/bin/javac JAVAC=$yap_cv_java/bin/javac
JAVADOC="$yap_cv_java"/bin/javadoc JAVADOC=$yap_cv_java/bin/javadoc
fi fi
else else
ENABLE_JPL="@#" ENABLE_JPL="@#"
@ -1800,6 +1805,7 @@ AC_SUBST(JUNIT)
AC_SUBST(JAVAC) AC_SUBST(JAVAC)
AC_SUBST(JAVADOC) AC_SUBST(JAVADOC)
AC_SUBST(JAR) AC_SUBST(JAR)
AC_SUBST(LIBJPL)
AC_SUBST(IN_UNIX) AC_SUBST(IN_UNIX)
AC_SUBST(YAPMPILIB) AC_SUBST(YAPMPILIB)
AC_SUBST(LAM_MPI_CC) AC_SUBST(LAM_MPI_CC)
@ -2004,7 +2010,7 @@ fi
dnl Checks for library functions. dnl Checks for library functions.
AC_TYPE_SIGNAL 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(alloca asinh atanh chdir clock clock_gettime)
AC_CHECK_FUNCS(ctime dlopen dup2) AC_CHECK_FUNCS(ctime dlopen dup2)
AC_CHECK_FUNCS(erf feclearexcept) AC_CHECK_FUNCS(erf feclearexcept)

2
console/LGPL/pl-ntconsole.c Normal file → Executable file
View File

@ -24,7 +24,7 @@
*/ */
#define WINDOWS_LEAN_AND_MEAN 1 #define WINDOWS_LEAN_AND_MEAN 1
#if (_MSC_VER >= 1300) #if (_MSC_VER >= 1300) || defined(__MINGW32__)
#include <winsock2.h> /* Needed on VC8 */ #include <winsock2.h> /* Needed on VC8 */
#include <windows.h> #include <windows.h>
#else #else

4
include/SWI-Prolog.h Normal file → Executable file
View File

@ -662,11 +662,13 @@ PL_EXPORT(pl_wchar_t*) PL_atom_generator_w(const pl_wchar_t *pref,
* WINDOWS MESSAGES * * 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_EXCEPTION_RAISED -1
#define PL_MSG_IGNORED 0 #define PL_MSG_IGNORED 0
#define PL_MSG_HANDLED 1 #define PL_MSG_HANDLED 1
#include <windows.h>
PL_EXPORT(LRESULT) PL_win_message_proc(HWND hwnd, PL_EXPORT(LRESULT) PL_win_message_proc(HWND hwnd,
UINT message, UINT message,
WPARAM wParam, WPARAM wParam,

View File

@ -2595,7 +2595,7 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
} }
pthread_mutex_lock(&(REMOTE_ThreadHandle(nwid).tlock)); 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)); pthread_mutex_unlock(&(REMOTE_ThreadHandle(nwid).tlock));
if (cwid != nwid) { if (cwid != nwid) {
return PL_ENGINE_INUSE; return PL_ENGINE_INUSE;

102
os/SWI-Stream.h Normal file → Executable file
View 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 (*Sclose_function)(void *handle);
typedef int (*Scontrol_function)(void *handle, int action, void *arg); typedef int (*Scontrol_function)(void *handle, int action, void *arg);
#if defined(THREADS) && !defined(O_PLMT) #include "pl-thread.h"
#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
typedef struct io_functions typedef struct io_functions
{ Sread_function read; /* fill the buffer */ { Sread_function read; /* fill the buffer */

View File

@ -38,7 +38,7 @@
#include "pl-incl.h" #include "pl-incl.h"
#include "pl-utf8.h" #include "pl-utf8.h"
#include <crtdbg.h> //#include <crtdbg.h>
#include <process.h> #include <process.h>
#include "pl-ctype.h" #include "pl-ctype.h"
#include <stdio.h> #include <stdio.h>
@ -234,10 +234,16 @@ Pause(double t)
int int
ftruncate(int fileno, int64_t length) 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 ) if ( (e=_chsize_s(fileno, length)) == 0 )
return 0; return 0;
#else
if ( (e=_chsize(fileno, (long)length)) == 0 )
return 0;
#endif
errno = e; errno = e;
return -1; return -1;
@ -338,7 +344,7 @@ typedef struct
} showtype; } showtype;
static int static int
get_showCmd(term_t show, int *cmd) get_showCmd(term_t show, UINT *cmd)
{ char *s; { char *s;
showtype *st; showtype *st;
static showtype types[] = static showtype types[] =
@ -721,7 +727,7 @@ static int
unify_csidl_path(term_t t, int csidl) unify_csidl_path(term_t t, int csidl)
{ wchar_t buf[MAX_PATH]; { wchar_t buf[MAX_PATH];
if ( SHGetSpecialFolderPathW(0, buf, csidl, FALSE) ) if ( SHGetFolderPathW(0, csidl, NULL, FALSE, buf) )
{ wchar_t *p; { wchar_t *p;
for(p=buf; *p; p++) for(p=buf; *p; p++)

107
os/pl-thread.h Executable file
View 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

View File

@ -53,6 +53,12 @@ volatile(P) :-
'$new_mutex'(Id), '$new_mutex'(Id),
assert_static(prolog:'$with_mutex_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) :- '$top_thread_goal'(G, Detached) :-
'$thread_self'(Id), '$thread_self'(Id),
(Detached == true -> '$detach_thread'(Id) ; true), (Detached == true -> '$detach_thread'(Id) ; true),