MT support in mingw win32.
This commit is contained in:
parent
2d71a96d54
commit
5989af937b
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
|
||||
|
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
|
Reference in New Issue
Block a user