improve SWI compatibility, especilaly for threaded stuff.
This commit is contained in:
@@ -4322,6 +4322,7 @@ init_yap_extras()
|
||||
swiio.put_c = Sputc;
|
||||
swiio.get_w = Sgetcode;
|
||||
swiio.put_w = Sputcode;
|
||||
swiio.flush_s = Sflush;
|
||||
swiio.close_s = Sclose;
|
||||
PL_YAP_InitSWIIO(&swiio);
|
||||
initCharTypes();
|
||||
|
@@ -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, ...);
|
||||
|
@@ -133,7 +133,9 @@ callProlog(module_t module, term_t goal, int flags, term_t *ex)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
extern X_API int PL_write_term(IOSTREAM *s, term_t term, int precedence, int flags);
|
||||
|
||||
X_API int
|
||||
PL_write_term(IOSTREAM *s, term_t term, int precedence, int flags)
|
||||
{
|
||||
int nflags = 0;
|
||||
@@ -709,10 +711,41 @@ PL_dispatch(int fd, int wait)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern size_t PL_utf8_strlen(const char *s, size_t len);
|
||||
extern size_t PL_utf8_strlen(const char *s, size_t len);
|
||||
|
||||
X_API size_t
|
||||
PL_utf8_strlen(const char *s, size_t len)
|
||||
{ return utf8_strlen(s, len);
|
||||
}
|
||||
|
||||
#define COUNT_MUTEX_INITIALIZER(name) \
|
||||
{ PTHREAD_MUTEX_INITIALIZER, \
|
||||
name, \
|
||||
0L \
|
||||
}
|
||||
|
||||
#if THREADS
|
||||
counting_mutex _PL_mutexes[] =
|
||||
{ COUNT_MUTEX_INITIALIZER("L_MISC"),
|
||||
COUNT_MUTEX_INITIALIZER("L_ALLOC"),
|
||||
COUNT_MUTEX_INITIALIZER("L_ATOM"),
|
||||
COUNT_MUTEX_INITIALIZER("L_FLAG"),
|
||||
COUNT_MUTEX_INITIALIZER("L_FUNCTOR"),
|
||||
COUNT_MUTEX_INITIALIZER("L_RECORD"),
|
||||
COUNT_MUTEX_INITIALIZER("L_THREAD"),
|
||||
COUNT_MUTEX_INITIALIZER("L_PREDICATE"),
|
||||
COUNT_MUTEX_INITIALIZER("L_MODULE"),
|
||||
COUNT_MUTEX_INITIALIZER("L_TABLE"),
|
||||
COUNT_MUTEX_INITIALIZER("L_BREAK"),
|
||||
COUNT_MUTEX_INITIALIZER("L_FILE"),
|
||||
COUNT_MUTEX_INITIALIZER("L_PLFLAG"),
|
||||
COUNT_MUTEX_INITIALIZER("L_OP"),
|
||||
COUNT_MUTEX_INITIALIZER("L_INIT"),
|
||||
COUNT_MUTEX_INITIALIZER("L_TERM"),
|
||||
COUNT_MUTEX_INITIALIZER("L_GC"),
|
||||
COUNT_MUTEX_INITIALIZER("L_AGC"),
|
||||
COUNT_MUTEX_INITIALIZER("L_FOREIGN"),
|
||||
COUNT_MUTEX_INITIALIZER("L_OS")
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -97,7 +97,7 @@ YAP_Int YAP_PLArityOfSWIFunctor(functor_t f);
|
||||
#define valReal(w) YAP_FloatOfTerm((w))
|
||||
#define valFloat(w) YAP_FloatOfTerm((w))
|
||||
#define AtomLength(w) YAP_AtomNameLength(w)
|
||||
#define atomValue(atom) AtomOfTerm(atom)
|
||||
#define atomValue(atom) YAP_AtomOfTerm(atom)
|
||||
#define argTermP(w,i) ((Word)((YAP_ArgsOfTerm(w)+(i))))
|
||||
#define deRef(t) (t = YAP_Deref(t))
|
||||
#define canBind(t) FALSE
|
||||
|
Reference in New Issue
Block a user