fix to thread support.
This commit is contained in:
@@ -5,29 +5,41 @@
|
||||
static inline Word
|
||||
INIT_SEQ_STRING(size_t n)
|
||||
{
|
||||
return (Word)YAP_OpenList(n);
|
||||
return RepPair(YAP_OpenList(n));
|
||||
}
|
||||
|
||||
static inline Word
|
||||
EXTEND_SEQ_CODES(Word gstore, int c) {
|
||||
return (Word)YAP_ExtendList((YAP_Term)gstore, YAP_MkIntTerm(c));
|
||||
EXTEND_SEQ_CODES(Word ptr, int c) {
|
||||
ptr[0] = MkIntegerTerm(c);
|
||||
ptr[1] = AbsPair(ptr+2);
|
||||
|
||||
return ptr+2;
|
||||
}
|
||||
|
||||
static inline Word
|
||||
EXTEND_SEQ_CHARS(Word gstore, int c) {
|
||||
return (Word)YAP_ExtendList((YAP_Term)gstore, codeToAtom(c));
|
||||
EXTEND_SEQ_CHARS(Word ptr, int c) {
|
||||
ptr[0] = codeToAtom(c);
|
||||
ptr[1] = AbsPair(ptr+2);
|
||||
|
||||
return ptr+2;
|
||||
}
|
||||
|
||||
static inline int
|
||||
CLOSE_SEQ_STRING(Word gstore, Word lp, word arg2, word arg3, term_t l) {
|
||||
if (arg2 == 0) {
|
||||
if (!YAP_CloseList((YAP_Term)gstore, YAP_TermNil()))
|
||||
return FALSE;
|
||||
CLOSE_SEQ_STRING(Word p, Word p0, term_t tail, term_t term, term_t l) {
|
||||
CACHE_REGS
|
||||
Yap_PutInSlot(l, AbsPair(p0) PASS_REGS);
|
||||
p--;
|
||||
if (tail) {
|
||||
RESET_VARIABLE(p);
|
||||
if (Yap_unify(Yap_GetFromSlot(l PASS_REGS), Yap_GetFromSlot(term PASS_REGS))) {
|
||||
Yap_PutInSlot(tail, (CELL)(p) PASS_REGS);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
} else {
|
||||
if (!YAP_CloseList((YAP_Term)gstore, YAP_GetFromSlot(arg2)))
|
||||
return FALSE;
|
||||
p[0] = YAP_TermNil();
|
||||
return Yap_unify(Yap_GetFromSlot(l PASS_REGS), Yap_GetFromSlot(term PASS_REGS));
|
||||
}
|
||||
return YAP_Unify(YAP_GetFromSlot(arg3), (YAP_Term)lp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -774,7 +774,7 @@ BeginPredDefs(ctype)
|
||||
PRED_DEF("setlocale", 3, setlocale, 0)
|
||||
PRED_DEF("downcase_atom", 2, downcase_atom, 0)
|
||||
PRED_DEF("upcase_atom", 2, upcase_atom, 0)
|
||||
PRED_DEF("swi_normalize_space", 2, normalize_space, 0)
|
||||
PRED_DEF("normalize_space", 2, normalize_space, 0)
|
||||
EndPredDefs
|
||||
|
||||
|
||||
|
@@ -4672,6 +4672,18 @@ EndPredDefs
|
||||
|
||||
#if __YAP_PROLOG__
|
||||
|
||||
|
||||
static word
|
||||
pl_sleep(term_t time)
|
||||
{ double t;
|
||||
|
||||
if ( PL_get_float_ex(time, &t) )
|
||||
return Pause(t);
|
||||
|
||||
fail;
|
||||
}
|
||||
|
||||
|
||||
static const PL_extension foreigns[] = {
|
||||
FRG("nl", 0, pl_nl, ISO),
|
||||
FRG("write_canonical", 1, pl_write_canonical, ISO),
|
||||
@@ -4688,6 +4700,7 @@ static const PL_extension foreigns[] = {
|
||||
FRG("print", 2, pl_print2, 0),
|
||||
FRG("write_canonical", 2, pl_write_canonical2, ISO),
|
||||
FRG("format", 3, pl_format3, META),
|
||||
FRG("sleep", 1, pl_sleep, 0),
|
||||
|
||||
// vsc
|
||||
FRG("format_predicate", 2, pl_format_predicate, META),
|
||||
@@ -4701,9 +4714,19 @@ static const PL_extension foreigns[] = {
|
||||
|
||||
struct PL_local_data *Yap_InitThreadIO(int wid)
|
||||
{
|
||||
struct PL_local_data *p = (struct PL_local_data *)calloc(sizeof(struct PL_local_data), 1);
|
||||
CACHE_REGS
|
||||
struct PL_local_data *p;
|
||||
if (wid)
|
||||
p = (struct PL_local_data *)malloc(sizeof(struct PL_local_data));
|
||||
else
|
||||
p = (struct PL_local_data *)calloc(sizeof(struct PL_local_data), 1);
|
||||
if (!p) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, 0L, "Creating thread %d\n", wid);
|
||||
return p;
|
||||
}
|
||||
if (wid) {
|
||||
/* copy from other worker */
|
||||
memcpy(p, Yap_WLocal[worker_id]->Yap_ld_, sizeof(struct PL_local_data));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@@ -342,6 +342,15 @@ setCurrentSourceLocation(IOSTREAM *s ARG_LD)
|
||||
source_file_name = NULL_ATOM;
|
||||
}
|
||||
|
||||
#if __YAP_PROLOG__
|
||||
void
|
||||
Yap_setCurrentSourceLocation(IOSTREAM *s)
|
||||
{
|
||||
GET_LD
|
||||
setCurrentSourceLocation(s PASS_LD);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static inline int
|
||||
getchr__(ReadData _PL_rd)
|
||||
|
@@ -473,7 +473,6 @@ PL_unify_text(term_t term, term_t tail, PL_chars_t *text, int type)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return CLOSE_SEQ_STRING(p, p0, tail, term, l );
|
||||
}
|
||||
}
|
||||
|
@@ -698,6 +698,27 @@ PL_get_list_chars(term_t l, char **s, unsigned flags)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
PL_unify_wchars_diff(term_t t, term_t tail, int flags,
|
||||
size_t len, const pl_wchar_t *s)
|
||||
{ PL_chars_t text;
|
||||
int rc;
|
||||
|
||||
if ( len == (size_t)-1 )
|
||||
len = wcslen(s);
|
||||
|
||||
text.text.w = (pl_wchar_t *)s;
|
||||
text.encoding = ENC_WCHAR;
|
||||
text.storage = PL_CHARS_HEAP;
|
||||
text.length = len;
|
||||
text.canonical = FALSE;
|
||||
|
||||
rc = PL_unify_text(t, tail, &text, flags);
|
||||
PL_free_text(&text);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
PL_get_wchars(term_t l, size_t *length, pl_wchar_t **s, unsigned flags)
|
||||
{ GET_LD
|
||||
@@ -1046,6 +1067,16 @@ recursiveMutexInit(recursiveMutex *m)
|
||||
|
||||
}
|
||||
|
||||
word
|
||||
pl_sleep(term_t time)
|
||||
{ double t;
|
||||
|
||||
if ( PL_get_float_ex(time, &t) )
|
||||
return Pause(t);
|
||||
|
||||
fail;
|
||||
}
|
||||
|
||||
|
||||
|
||||
counting_mutex _PL_mutexes[] =
|
||||
|
@@ -114,7 +114,7 @@ void PL_license(const char *license, const char *module);
|
||||
#define arityFunctor(f) YAP_PLArityOfSWIFunctor(f)
|
||||
|
||||
#define stringAtom(w) YAP_AtomName((YAP_Atom)(w))
|
||||
#define isInteger(A) (YAP_IsIntTerm((A)) && YAP_IsBigNumTerm((A)))
|
||||
#define isInteger(A) (YAP_IsIntTerm((A)) || YAP_IsBigNumTerm((A)))
|
||||
#define isString(A) FALSE
|
||||
#define isAtom(A) YAP_IsAtomTerm((A))
|
||||
#define isList(A) YAP_IsPairTerm((A))
|
||||
|
Reference in New Issue
Block a user