improve SWI compatibility, especilaly for threaded stuff.

This commit is contained in:
Vítor Santos Costa
2010-08-04 11:37:12 +01:00
parent 6ee0ce8e48
commit bebb236e32
16 changed files with 439 additions and 73 deletions

View File

@@ -128,6 +128,12 @@ typedef struct {
{ Table table; /* global (read-only) features */
} prolog_flag;
#if THREADS
struct
{ int enabled; /* threads are enabled */
} thread;
#endif
struct
{ Table tmp_files; /* Known temporary files */
CanonicalDir _canonical_dirlist;
@@ -387,8 +393,70 @@ extern PL_local_data_t lds;
/* Support PL_LOCK in the interface */
#define PL_LOCK(X)
#define PL_UNLOCK(X)
#if THREADS
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)
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
#define IF_MT(id, g) if ( id == L_THREAD || GD->thread.enabled ) g
#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]))
#else
#define PL_LOCK(X)
#define PL_UNLOCK(X)
#endif
#ifndef TRUE
@@ -658,6 +726,9 @@ void initFiles(void);
int RemoveFile(const char *path);
int PL_get_file_name(term_t n, char **namep, int flags);
/**** stuff from pl-utf8.c ****/
size_t utf8_strlen(const char *s, size_t len);
/* empty stub */
void setPrologFlag(const char *name, int flags, ...);
void PL_set_prolog_flag(const char *name, int flags, ...);