integration work:
- use SWI flags whenever possible - support by module unknown, escapes, strings - accesss thread info fom SWI - allow strings to be input as strings. - remove some unused flags.
This commit is contained in:
@@ -3433,7 +3433,7 @@ YAP_SetCurrentModule(Term new)
|
||||
{
|
||||
CACHE_REGS
|
||||
Term omod = CurrentModule;
|
||||
CurrentModule = new;
|
||||
LOCAL_SourceModule = CurrentModule = new;
|
||||
return omod;
|
||||
}
|
||||
|
||||
|
||||
23
C/init.c
23
C/init.c
@@ -910,12 +910,10 @@ InitFlags(void)
|
||||
yap_flags[YAP_MAX_INTEGER_FLAG] = (Int)(~((CELL)1 << (sizeof(Int)*8-1)));
|
||||
yap_flags[YAP_MIN_INTEGER_FLAG] = (Int)(((CELL)1 << (sizeof(Int)*8-1)));
|
||||
yap_flags[CHAR_CONVERSION_FLAG] = 1;
|
||||
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = 1;
|
||||
yap_flags[YAP_TO_CHARS_FLAG] = ISO_TO_CHARS;
|
||||
yap_flags[LANGUAGE_MODE_FLAG] = 0;
|
||||
yap_flags[STRICT_ISO_FLAG] = FALSE;
|
||||
yap_flags[SOURCE_MODE_FLAG] = FALSE;
|
||||
yap_flags[CHARACTER_ESCAPE_FLAG] = SICSTUS_CHARACTER_ESCAPES;
|
||||
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
|
||||
/* we do not garantee safe assert in parallel mode */
|
||||
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = TRUE;
|
||||
@@ -1169,23 +1167,6 @@ Yap_InitThread(int new_id)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
#ifdef THREADS
|
||||
CACHE_REGS
|
||||
LOCAL_ThreadHandle.id = 0;
|
||||
LOCAL_ThreadHandle.in_use = TRUE;
|
||||
LOCAL_ThreadHandle.default_yaam_regs =
|
||||
&Yap_standard_regs;
|
||||
LOCAL_ThreadHandle.pthread_handle = pthread_self();
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
|
||||
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
||||
LOCAL_ThreadHandle.ref_count = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
InitScratchPad(int wid)
|
||||
{
|
||||
@@ -1240,9 +1221,9 @@ InitCodes(void)
|
||||
#if !THREADS
|
||||
InitWorker(0);
|
||||
#endif /* THREADS */
|
||||
InitFirstWorkerThreadHandle();
|
||||
Yap_InitFirstWorkerThreadHandle();
|
||||
/* make sure no one else can use these two atoms */
|
||||
CurrentModule = 0;
|
||||
LOCAL_SourceModule = CurrentModule = 0;
|
||||
Yap_ReleaseAtom(AtomOfTerm(TermReFoundVar));
|
||||
/* make sure we have undefp defined */
|
||||
/* predicates can only be defined after this point */
|
||||
|
||||
51
C/modules.c
51
C/modules.c
@@ -21,10 +21,16 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
#include "pl-shared.h"
|
||||
|
||||
static Int p_current_module( USES_REGS1 );
|
||||
static Int p_current_module1( USES_REGS1 );
|
||||
static ModEntry *LookupModule(Term a);
|
||||
|
||||
unsigned int
|
||||
getUnknownModule(ModEntry * m) {
|
||||
return m->flags & UNKNOWN_MASK;
|
||||
}
|
||||
|
||||
inline static ModEntry *
|
||||
FetchModuleEntry(Atom at)
|
||||
@@ -56,6 +62,7 @@ GetModuleEntry(Atom at)
|
||||
AtomEntry *ae = RepAtom(at);
|
||||
ModEntry *new;
|
||||
|
||||
|
||||
p0 = ae->PropsOfAE;
|
||||
while (p0) {
|
||||
ModEntry *me = RepModProp(p0);
|
||||
@@ -65,14 +72,21 @@ GetModuleEntry(Atom at)
|
||||
}
|
||||
p0 = me->NextOfPE;
|
||||
}
|
||||
new = (ModEntry *) Yap_AllocAtomSpace(sizeof(*new));
|
||||
INIT_RWLOCK(new->ModRWLock);
|
||||
new->KindOfPE = ModProperty;
|
||||
new->PredForME = NULL;
|
||||
new->NextME = CurrentModules;
|
||||
CurrentModules = new;
|
||||
new->AtomOfME = ae;
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
{
|
||||
CACHE_REGS
|
||||
new = (ModEntry *) Yap_AllocAtomSpace(sizeof(*new));
|
||||
INIT_RWLOCK(new->ModRWLock);
|
||||
new->KindOfPE = ModProperty;
|
||||
new->PredForME = NULL;
|
||||
new->NextME = CurrentModules;
|
||||
CurrentModules = new;
|
||||
new->AtomOfME = ae;
|
||||
if (at == AtomProlog)
|
||||
new->flags = UNKNOWN_FAIL|M_SYSTEM|M_CHARESCAPE;
|
||||
else
|
||||
new->flags = LookupModule(LOCAL_SourceModule)->flags;
|
||||
AddPropToAtom(ae, (PropEntry *)new);
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
@@ -100,14 +114,14 @@ Yap_Module_Name(PredEntry *ap)
|
||||
}
|
||||
|
||||
static ModEntry *
|
||||
LookupModule(Term a)
|
||||
LookupModule(Term a )
|
||||
{
|
||||
Atom at;
|
||||
ModEntry *me;
|
||||
|
||||
/* prolog module */
|
||||
if (a == 0)
|
||||
return GetModuleEntry(AtomOfTerm(TermProlog));
|
||||
return GetModuleEntry(AtomProlog);
|
||||
at = AtomOfTerm(a);
|
||||
me = GetModuleEntry(at);
|
||||
return me;
|
||||
@@ -120,6 +134,21 @@ Yap_Module(Term tmod)
|
||||
return tmod;
|
||||
}
|
||||
|
||||
ModEntry *
|
||||
Yap_GetModuleEntry(Term mod)
|
||||
{
|
||||
ModEntry *me;
|
||||
if (!(me = LookupModule(mod)))
|
||||
return NULL;
|
||||
return me;
|
||||
}
|
||||
|
||||
Term
|
||||
Yap_GetModuleFromEntry(ModEntry *me)
|
||||
{
|
||||
return MkAtomTerm(me->AtomOfME);;
|
||||
}
|
||||
|
||||
struct pred_entry *
|
||||
Yap_ModulePred(Term mod)
|
||||
{
|
||||
@@ -163,6 +192,7 @@ p_current_module( USES_REGS1 )
|
||||
CurrentModule = t;
|
||||
LookupModule(CurrentModule);
|
||||
}
|
||||
LOCAL_SourceModule = CurrentModule;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -180,6 +210,7 @@ p_change_module( USES_REGS1 )
|
||||
Term mod = Deref(ARG1);
|
||||
LookupModule(mod);
|
||||
CurrentModule = mod;
|
||||
LOCAL_SourceModule = mod;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
49
C/parser.c
49
C/parser.c
@@ -567,17 +567,22 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
|
||||
Volatile char *p = (char *) LOCAL_tokptr->TokInfo;
|
||||
if (*p == 0)
|
||||
t = MkAtomTerm(AtomNil);
|
||||
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_CHARS)
|
||||
t = Yap_StringToListOfAtoms(p);
|
||||
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_ATOM) {
|
||||
Atom at = Yap_LookupAtom(p);
|
||||
if (at == NIL) {
|
||||
LOCAL_ErrorMessage = "Heap Overflow";
|
||||
FAIL;
|
||||
}
|
||||
t = MkAtomTerm(at);
|
||||
} else
|
||||
t = Yap_StringToList(p);
|
||||
else {
|
||||
unsigned int flags = Yap_GetModuleEntry(CurrentModule)->flags;
|
||||
if (flags & DBLQ_CHARS)
|
||||
t = Yap_StringToListOfAtoms(p);
|
||||
else if (flags & DBLQ_ATOM) {
|
||||
Atom at = Yap_LookupAtom(p);
|
||||
if (at == NIL) {
|
||||
LOCAL_ErrorMessage = "Heap Overflow";
|
||||
FAIL;
|
||||
}
|
||||
t = MkAtomTerm(at);
|
||||
} else if (flags & DBLQ_STRING) {
|
||||
t = Yap_MkBlobStringTerm(p, strlen(p));
|
||||
} else
|
||||
t = Yap_StringToList(p);
|
||||
}
|
||||
NextToken;
|
||||
}
|
||||
break;
|
||||
@@ -587,12 +592,22 @@ ParseTerm(int prio, JMPBUFF *FailBuff USES_REGS)
|
||||
Volatile wchar_t *p = (wchar_t *) LOCAL_tokptr->TokInfo;
|
||||
if (*p == 0)
|
||||
t = MkAtomTerm(AtomNil);
|
||||
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_CHARS)
|
||||
t = Yap_WideStringToListOfAtoms(p);
|
||||
else if (yap_flags[YAP_DOUBLE_QUOTES_FLAG] == STRING_AS_ATOM)
|
||||
t = MkAtomTerm(Yap_LookupWideAtom(p));
|
||||
else
|
||||
t = Yap_WideStringToList(p);
|
||||
else {
|
||||
unsigned int flags = Yap_GetModuleEntry(CurrentModule)->flags;
|
||||
if (flags & DBLQ_CHARS)
|
||||
t = Yap_WideStringToListOfAtoms(p);
|
||||
else if (flags & DBLQ_ATOM) {
|
||||
Atom at = Yap_LookupWideAtom(p);
|
||||
if (at == NIL) {
|
||||
LOCAL_ErrorMessage = "Heap Overflow";
|
||||
FAIL;
|
||||
}
|
||||
t = MkAtomTerm(at);
|
||||
} else if (flags & DBLQ_STRING) {
|
||||
t = Yap_MkBlobWideStringTerm(p, wcslen(p));
|
||||
} else
|
||||
t = Yap_WideStringToList(p);
|
||||
}
|
||||
if (t == 0L) {
|
||||
LOCAL_ErrorMessage = "Stack Overflow";
|
||||
FAIL;
|
||||
|
||||
40
C/pl-yap.c
40
C/pl-yap.c
@@ -1321,8 +1321,48 @@ Yap_source_file_name( void )
|
||||
return YAP_AtomFromSWIAtom(source_file_name);
|
||||
}
|
||||
|
||||
atom_t
|
||||
accessLevel(void)
|
||||
{ GET_LD
|
||||
|
||||
switch(LD->prolog_flag.access_level)
|
||||
{ case ACCESS_LEVEL_USER: return ATOM_user;
|
||||
case ACCESS_LEVEL_SYSTEM: return ATOM_system;
|
||||
}
|
||||
|
||||
return NULL_ATOM;
|
||||
}
|
||||
|
||||
int
|
||||
getAccessLevelMask(atom_t a, access_level_t *val)
|
||||
{ if ( a == ATOM_user )
|
||||
*val = ACCESS_LEVEL_USER;
|
||||
else if ( a == ATOM_system )
|
||||
*val = ACCESS_LEVEL_SYSTEM;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
currentBreakLevel(void)
|
||||
{ GET_LD
|
||||
|
||||
return LD->break_level;
|
||||
}
|
||||
|
||||
#if THREADS
|
||||
|
||||
PL_thread_info_t *
|
||||
SWI_thread_info(int tid, PL_thread_info_t *info)
|
||||
{
|
||||
if (info)
|
||||
REMOTE_PL_local_data_p(tid)->thread.info = info;
|
||||
return REMOTE_PL_local_data_p(tid)->thread.info;
|
||||
}
|
||||
|
||||
static int
|
||||
recursive_attr(pthread_mutexattr_t **ap)
|
||||
{ static int done;
|
||||
|
||||
60
C/scanner.c
60
C/scanner.c
@@ -280,8 +280,8 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
int ch;
|
||||
|
||||
/* escape sequence */
|
||||
restart:
|
||||
ch = getchrq(inp_stream);
|
||||
do_switch:
|
||||
switch (ch) {
|
||||
case 10:
|
||||
return 0;
|
||||
@@ -292,17 +292,8 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
case 'b':
|
||||
return '\b';
|
||||
case 'c':
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
return send_error_message("invalid escape sequence \\c");
|
||||
} else {
|
||||
/* sicstus */
|
||||
ch = getchrq(inp_stream);
|
||||
if (chtype(ch) == SL) {
|
||||
goto restart;
|
||||
} else {
|
||||
return 'c';
|
||||
}
|
||||
}
|
||||
while (chtype((ch = getchrq(inp_stream))) == BS);
|
||||
goto do_switch;
|
||||
case 'd':
|
||||
return 127;
|
||||
case 'e':
|
||||
@@ -314,10 +305,7 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
case 'r':
|
||||
return '\r';
|
||||
case 's': /* space */
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
return send_error_message("invalid escape sequence \\s");
|
||||
} else
|
||||
return ' ';
|
||||
return ' ';
|
||||
case 't':
|
||||
return '\t';
|
||||
case 'u':
|
||||
@@ -369,7 +357,7 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
case '`':
|
||||
return '`';
|
||||
case '^':
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
if (FALSE /*yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES */) {
|
||||
return send_error_message("invalid escape sequence");
|
||||
} else {
|
||||
ch = getchrq(inp_stream);
|
||||
@@ -393,7 +381,7 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
case '7':
|
||||
/* character in octal: maximum of 3 digits, terminates with \ */
|
||||
/* follow ISO */
|
||||
if (TRUE || yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
{
|
||||
unsigned char so_far = ch-'0';
|
||||
ch = getchrq(inp_stream);
|
||||
if (ch >= '0' && ch < '8') {/* octal */
|
||||
@@ -416,27 +404,10 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
} else {
|
||||
return send_error_message("invalid octal escape sequence");
|
||||
}
|
||||
} else {
|
||||
/* sicstus */
|
||||
unsigned char so_far = ch-'0';
|
||||
ch = getchrq(inp_stream);
|
||||
if (ch >= '0' && ch < '8') {/* octal */
|
||||
so_far = so_far*8+(ch-'0');
|
||||
ch = getchrq(inp_stream);
|
||||
if (ch >= '0' && ch < '8') { /* octal */
|
||||
return so_far*8+(ch-'0');
|
||||
} else {
|
||||
*scan_nextp = FALSE;
|
||||
return so_far;
|
||||
}
|
||||
} else {
|
||||
*scan_nextp = FALSE;
|
||||
return so_far;
|
||||
}
|
||||
}
|
||||
case 'x':
|
||||
/* hexadecimal character (YAP allows empty hexadecimal */
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
{
|
||||
unsigned char so_far = 0;
|
||||
ch = getchrq(inp_stream);
|
||||
if (my_isxdigit(ch,'f','F')) {/* hexa */
|
||||
@@ -462,17 +433,6 @@ read_quoted_char(int *scan_nextp, IOSTREAM *inp_stream)
|
||||
} else {
|
||||
return send_error_message("invalid hexadecimal escape sequence");
|
||||
}
|
||||
} else {
|
||||
/* sicstus mode */
|
||||
unsigned char so_far = 0;
|
||||
ch = getchrq(inp_stream);
|
||||
so_far = (chtype(ch) == NU ? ch - '0' :
|
||||
my_isupper(ch) ? ch - 'A' + 10 :
|
||||
my_islower(ch) ? ch - 'a' +10 : 0);
|
||||
ch = getchrq(inp_stream);
|
||||
return so_far*16 + (chtype(ch) == NU ? ch - '0' :
|
||||
my_isupper(ch) ? ch - 'A' +10 :
|
||||
my_islower(ch) ? ch - 'a' + 10 : 0);
|
||||
}
|
||||
default:
|
||||
/* accept sequence. Note that the ISO standard does not
|
||||
@@ -531,7 +491,7 @@ get_num(int *chp, int *chbuffp, IOSTREAM *inp_stream, char *s, UInt max_size, in
|
||||
int scan_extra = TRUE;
|
||||
|
||||
if (ch == '\\' &&
|
||||
yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) {
|
||||
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||
ascii = read_quoted_char(&scan_extra, inp_stream);
|
||||
}
|
||||
/* a quick way to represent ASCII */
|
||||
@@ -1114,7 +1074,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
|
||||
LOCAL_ErrorMessage = "Heap Overflow While Scanning: please increase code space (-h)";
|
||||
break;
|
||||
}
|
||||
if (ch == 10 && yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES) {
|
||||
if (ch == 10 && FALSE /*yap_flags[CHARACTER_ESCAPE_FLAG] == ISO_CHARACTER_ESCAPES */) {
|
||||
/* in ISO a new line terminates a string */
|
||||
LOCAL_ErrorMessage = "layout character \n inside quotes";
|
||||
break;
|
||||
@@ -1125,7 +1085,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp)
|
||||
break;
|
||||
add_ch_to_buff(ch);
|
||||
ch = getchrq(inp_stream);
|
||||
} else if (ch == '\\' && yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) {
|
||||
} else if (ch == '\\' && Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||
int scan_next = TRUE;
|
||||
if ((ch = read_quoted_char(&scan_next, inp_stream))) {
|
||||
add_ch_to_buff(ch);
|
||||
|
||||
12
C/stdpreds.c
12
C/stdpreds.c
@@ -1654,11 +1654,6 @@ p_set_yap_flags( USES_REGS1 )
|
||||
return(FALSE);
|
||||
yap_flags[CHAR_CONVERSION_FLAG] = value;
|
||||
break;
|
||||
case YAP_DOUBLE_QUOTES_FLAG:
|
||||
if (value < 0 || value > 2)
|
||||
return(FALSE);
|
||||
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = value;
|
||||
break;
|
||||
case YAP_TO_CHARS_FLAG:
|
||||
if (value != 0 && value != 1)
|
||||
return(FALSE);
|
||||
@@ -1684,13 +1679,6 @@ p_set_yap_flags( USES_REGS1 )
|
||||
return(FALSE);
|
||||
yap_flags[SOURCE_MODE_FLAG] = value;
|
||||
break;
|
||||
case CHARACTER_ESCAPE_FLAG:
|
||||
if (value != ISO_CHARACTER_ESCAPES
|
||||
&& value != CPROLOG_CHARACTER_ESCAPES
|
||||
&& value != SICSTUS_CHARACTER_ESCAPES)
|
||||
return(FALSE);
|
||||
yap_flags[CHARACTER_ESCAPE_FLAG] = value;
|
||||
break;
|
||||
case WRITE_QUOTED_STRING_FLAG:
|
||||
if (value != 0 && value != 1)
|
||||
return(FALSE);
|
||||
|
||||
71
C/threads.c
71
C/threads.c
@@ -23,6 +23,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "yapio.h"
|
||||
#include "pl-shared.h"
|
||||
#include <stdio.h>
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
@@ -51,6 +52,27 @@ static Int p_nodebug_locks( USES_REGS1 ) { debug_locks = 0; return TRUE; }
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
set_system_thread_id(int wid, PL_thread_info_t *info)
|
||||
{
|
||||
if (!info)
|
||||
info = (PL_thread_info_t *)malloc(sizeof(PL_thread_info_t));
|
||||
info = SWI_thread_info(wid, info);
|
||||
info->tid = pthread_self();
|
||||
info->has_tid = TRUE;
|
||||
#ifdef HAVE_GETTID_SYSCALL
|
||||
info->pid = syscall(__NR_gettid);
|
||||
#else
|
||||
#ifdef HAVE_GETTID_MACRO
|
||||
info->pid = gettid();
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
info->w32id = GetCurrentThreadId();
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
allocate_new_tid(void)
|
||||
{
|
||||
@@ -237,6 +259,7 @@ setup_engine(int myworker_id, int init_thread)
|
||||
CACHE_REGS
|
||||
REGSTORE *standard_regs;
|
||||
|
||||
set_system_thread_id( myworker_id, NULL );
|
||||
standard_regs = (REGSTORE *)calloc(1,sizeof(REGSTORE));
|
||||
if (!standard_regs)
|
||||
return FALSE;
|
||||
@@ -244,7 +267,7 @@ setup_engine(int myworker_id, int init_thread)
|
||||
/* create the YAAM descriptor */
|
||||
REMOTE_ThreadHandle(myworker_id).default_yaam_regs = standard_regs;
|
||||
Yap_InitExStacks(myworker_id, REMOTE_ThreadHandle(myworker_id).tsize, REMOTE_ThreadHandle(myworker_id).ssize);
|
||||
CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
||||
LOCAL_SourceModule = CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
||||
Yap_InitTime( myworker_id );
|
||||
Yap_InitYaamRegs( myworker_id );
|
||||
REFRESH_CACHE_REGS
|
||||
@@ -509,7 +532,6 @@ Yap_thread_create_engine(thread_attr *ops)
|
||||
Int
|
||||
Yap_thread_attach_engine(int wid)
|
||||
{
|
||||
CACHE_REGS
|
||||
/*
|
||||
already locked
|
||||
MUTEX_LOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
@@ -517,13 +539,14 @@ Yap_thread_attach_engine(int wid)
|
||||
if (REMOTE_ThreadHandle(wid).ref_count ) {
|
||||
REMOTE_ThreadHandle(wid).ref_count++;
|
||||
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||
set_system_thread_id(wid, SWI_thread_info(wid, NULL));
|
||||
MUTEX_UNLOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||
set_system_thread_id(wid, SWI_thread_info(wid, NULL));
|
||||
REMOTE_ThreadHandle(wid).ref_count++;
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(wid).current_yaam_regs);
|
||||
REFRESH_CACHE_REGS;
|
||||
MUTEX_UNLOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
@@ -955,6 +978,43 @@ p_thread_unlock( USES_REGS1 )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
intptr_t
|
||||
system_thread_id(PL_thread_info_t *info)
|
||||
{ if ( !info )
|
||||
{ CACHE_REGS
|
||||
if ( LOCAL )
|
||||
info = SWI_thread_info(worker_id, NULL);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#ifdef __linux__
|
||||
return info->pid;
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
return info->w32id;
|
||||
#else
|
||||
return (intptr_t)info->tid;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
CACHE_REGS
|
||||
LOCAL_ThreadHandle.id = 0;
|
||||
LOCAL_ThreadHandle.in_use = TRUE;
|
||||
LOCAL_ThreadHandle.default_yaam_regs =
|
||||
&Yap_standard_regs;
|
||||
LOCAL_ThreadHandle.pthread_handle = pthread_self();
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
|
||||
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
||||
LOCAL_ThreadHandle.ref_count = 1;
|
||||
set_system_thread_id(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$no_threads", 0, p_no_threads, 0);
|
||||
@@ -1057,6 +1117,11 @@ p_max_workers(void)
|
||||
return Yap_unify(ARG1,MkIntTerm(1));
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$max_workers", 1, p_max_workers, 0);
|
||||
|
||||
11
C/write.c
11
C/write.c
@@ -463,7 +463,8 @@ AtomIsSymbols(unsigned char *s) /* Is this atom just formed by symbols ? */
|
||||
static void
|
||||
write_quoted(int ch, int quote, wrf stream)
|
||||
{
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == CPROLOG_CHARACTER_ESCAPES) {
|
||||
CACHE_REGS
|
||||
if (!(Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE)) {
|
||||
wrputc(ch, stream);
|
||||
if (ch == '\'')
|
||||
wrputc('\'', stream); /* be careful about quotes */
|
||||
@@ -514,12 +515,8 @@ write_quoted(int ch, int quote, wrf stream)
|
||||
if ( ch <= 0xff ) {
|
||||
char esc[8];
|
||||
|
||||
if (yap_flags[CHARACTER_ESCAPE_FLAG] == SICSTUS_CHARACTER_ESCAPES) {
|
||||
sprintf(esc, "\\%03o", ch);
|
||||
} else {
|
||||
/* last backslash in ISO mode */
|
||||
sprintf(esc, "\\%03o\\", ch);
|
||||
}
|
||||
/* last backslash in ISO mode */
|
||||
sprintf(esc, "\\%03o\\", ch);
|
||||
wrputs(esc, stream);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user