new interface to access globals. They are not in a file called GLOBALS, from which
we generate several files automatically.
This commit is contained in:
parent
499f2c5368
commit
d5e1ff38f4
@ -718,7 +718,7 @@ Yap_absmi(int inp)
|
||||
/* the registers are all set up, let's swap */
|
||||
#ifdef THREADS
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)&absmi_regs);
|
||||
ThreadHandle[worker_id].current_yaam_regs = &absmi_regs;
|
||||
MY_ThreadHandle.current_yaam_regs = &absmi_regs;
|
||||
#else
|
||||
Yap_regp = &absmi_regs;
|
||||
#endif
|
||||
|
@ -800,8 +800,8 @@ Yap_NewThreadPred(PredEntry *ap)
|
||||
p->beamTable = NULL;
|
||||
#endif
|
||||
/* careful that they don't cross MkFunctor */
|
||||
p->NextOfPE = AbsPredProp(ThreadHandle[worker_id].local_preds);
|
||||
ThreadHandle[worker_id].local_preds = p;
|
||||
p->NextOfPE = AbsPredProp(MY_ThreadHandle.local_preds);
|
||||
MY_ThreadHandle.local_preds = p;
|
||||
p->FunctorOfPred = ap->FunctorOfPred;
|
||||
#ifdef LOW_PROF
|
||||
if (ProfilerOn &&
|
||||
|
9
C/agc.c
9
C/agc.c
@ -93,6 +93,14 @@ AtomTermAdjust(Term t)
|
||||
return(t);
|
||||
}
|
||||
|
||||
static inline Term
|
||||
TermToGlobalOrAtomAdjust(Term t)
|
||||
{
|
||||
if (t && IsAtomTerm(t))
|
||||
return AtomTermAdjust(t);
|
||||
return(t);
|
||||
}
|
||||
|
||||
static inline Atom
|
||||
AtomAdjust(Atom a)
|
||||
{
|
||||
@ -163,6 +171,7 @@ AtomAdjust(Atom a)
|
||||
#define PtoGloAdjust(P) (P)
|
||||
#define PtoLocAdjust(P) (P)
|
||||
#define PtoHeapCellAdjust(P) (P)
|
||||
#define TermToGlobalAdjust(P) (P)
|
||||
#define PtoOpAdjust(P) (P)
|
||||
#define PtoLUClauseAdjust(P) (P)
|
||||
#define PtoLUIndexAdjust(P) (P)
|
||||
|
@ -351,7 +351,7 @@ InitExStacks(int Trail, int Stack)
|
||||
|
||||
#ifdef THREADS
|
||||
if (worker_id)
|
||||
Yap_GlobalBase = (ADDR)ThreadHandle[worker_id].stack_address;
|
||||
Yap_GlobalBase = (ADDR)MY_ThreadHandle.stack_address;
|
||||
#endif
|
||||
Yap_TrailTop = Yap_GlobalBase + pm;
|
||||
Yap_LocalBase = Yap_GlobalBase + sa;
|
||||
@ -385,10 +385,10 @@ Yap_InitExStacks(int Trail, int Stack)
|
||||
void
|
||||
Yap_KillStacks(int wid)
|
||||
{
|
||||
ADDR gb = ThreadHandle[wid].stack_address;
|
||||
ADDR gb = FOREIGN_ThreadHandle(wid).stack_address;
|
||||
if (gb) {
|
||||
free(gb);
|
||||
ThreadHandle[wid].stack_address = NULL;
|
||||
FOREIGN_ThreadHandle(wid).stack_address = NULL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
@ -417,7 +417,7 @@ Yap_ExtendWorkSpace(Int s)
|
||||
if (nbp == NULL)
|
||||
return FALSE;
|
||||
#if defined(THREADS)
|
||||
ThreadHandle[worker_id].stack_address = (char *)nbp;
|
||||
MY_ThreadHandle.stack_address = (char *)nbp;
|
||||
#endif
|
||||
Yap_GlobalBase = (char *)nbp;
|
||||
return TRUE;
|
||||
|
@ -2368,8 +2368,8 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
}
|
||||
#if THREADS
|
||||
/* don't forget this is a thread */
|
||||
ThreadHandle[worker_id].stack_address = Yap_GlobalBase;
|
||||
ThreadHandle[worker_id].ssize = Trail+Stack;
|
||||
MY_ThreadHandle.stack_address = Yap_GlobalBase;
|
||||
MY_ThreadHandle.ssize = Trail+Stack;
|
||||
#endif
|
||||
#endif
|
||||
Yap_AllowGlobalExpansion = TRUE;
|
||||
@ -2414,6 +2414,8 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
}
|
||||
yap_flags[FAST_BOOT_FLAG] = yap_init->FastBoot;
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
/* make sure we initialise this field */
|
||||
GLOBAL_root_dep_fr = NULL;
|
||||
make_root_frames();
|
||||
#ifdef YAPOR
|
||||
init_workers();
|
||||
|
35
C/cdmgr.c
35
C/cdmgr.c
@ -631,6 +631,31 @@ Yap_PredForChoicePt(choiceptr cp) {
|
||||
return PredForChoicePt(cp->cp_ap);
|
||||
}
|
||||
|
||||
static void
|
||||
InitConsultStack(void)
|
||||
{
|
||||
ConsultLow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
||||
if (ConsultLow == NULL) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
||||
return;
|
||||
}
|
||||
ConsultCapacity = InitialConsultCapacity;
|
||||
ConsultBase = ConsultSp =
|
||||
ConsultLow + ConsultCapacity;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_ResetConsultStack(void)
|
||||
{
|
||||
Yap_FreeCodeSpace((char *)ConsultLow);
|
||||
ConsultBase =
|
||||
ConsultSp =
|
||||
ConsultLow =
|
||||
NULL;
|
||||
ConsultCapacity = InitialConsultCapacity;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************
|
||||
|
||||
EXECUTING PROLOG CLAUSES
|
||||
@ -1961,6 +1986,9 @@ not_was_reconsulted(PredEntry *p, Term t, int mode)
|
||||
if (p == LastAssertedPred)
|
||||
return FALSE;
|
||||
LastAssertedPred = p;
|
||||
if (!ConsultSp) {
|
||||
InitConsultStack();
|
||||
}
|
||||
if (p->cs.p_code.NOfClauses) {
|
||||
for (fp = ConsultSp; fp < ConsultBase; ++fp)
|
||||
if (fp->p == p0)
|
||||
@ -2431,7 +2459,7 @@ p_in_this_f_before(void)
|
||||
p0 = PredPropByFunc(Yap_MkFunctor(at, arity), mod);
|
||||
else
|
||||
p0 = PredPropByAtom(at, mod);
|
||||
if (ConsultSp == ConsultBase || LastAssertedPred == RepPredProp(p0) || (fp = ConsultSp)->p == p0)
|
||||
if (!ConsultSp || ConsultSp == ConsultBase || LastAssertedPred == RepPredProp(p0) || (fp = ConsultSp)->p == p0)
|
||||
return FALSE;
|
||||
else
|
||||
fp++;
|
||||
@ -2471,6 +2499,8 @@ p_first_cl_in_f(void)
|
||||
p0 = PredPropByAtom(at, mod);
|
||||
if (LastAssertedPred == RepPredProp(p0))
|
||||
return FALSE;
|
||||
if (!ConsultSp)
|
||||
return FALSE;
|
||||
for (fp = ConsultSp; fp < ConsultBase; ++fp)
|
||||
if (fp->p == p0)
|
||||
break;
|
||||
@ -2593,6 +2623,9 @@ Yap_ConsultingFile (void)
|
||||
static void
|
||||
init_consult(int mode, char *file)
|
||||
{
|
||||
if (!ConsultSp) {
|
||||
InitConsultStack();
|
||||
}
|
||||
ConsultSp--;
|
||||
ConsultSp->filename = file;
|
||||
ConsultSp--;
|
||||
|
4
C/exec.c
4
C/exec.c
@ -1586,8 +1586,8 @@ Yap_InitYaamRegs(void)
|
||||
machine registers */
|
||||
#ifdef THREADS
|
||||
int myworker_id = worker_id;
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)ThreadHandle[myworker_id].default_yaam_regs);
|
||||
ThreadHandle[myworker_id].current_yaam_regs = ThreadHandle[myworker_id].default_yaam_regs;
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)FOREIGN_ThreadHandle(myworker_id).default_yaam_regs);
|
||||
FOREIGN_ThreadHandle(myworker_id).current_yaam_regs = FOREIGN_ThreadHandle(myworker_id).default_yaam_regs;
|
||||
worker_id = myworker_id;
|
||||
#else
|
||||
Yap_regp = &Yap_standard_regs;
|
||||
|
36
C/grow.c
36
C/grow.c
@ -241,11 +241,11 @@ static CELL
|
||||
worker_p_binding(int worker_p, CELL *aux_ptr)
|
||||
{
|
||||
if (aux_ptr > H) {
|
||||
CELL reg = ThreadHandle[worker_p].current_yaam_regs->LCL0_[aux_ptr-LCL0];
|
||||
CELL reg = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->LCL0_[aux_ptr-LCL0];
|
||||
reg = AdjustGlobTerm(reg);
|
||||
return reg;
|
||||
} else {
|
||||
CELL reg = ThreadHandle[worker_p].current_yaam_regs-> H0_[aux_ptr-H0];
|
||||
CELL reg = FOREIGN_ThreadHandle(worker_p).current_yaam_regs-> H0_[aux_ptr-H0];
|
||||
reg = AdjustGlobTerm(reg);
|
||||
return reg;
|
||||
}
|
||||
@ -1823,38 +1823,38 @@ Yap_CopyThreadStacks(int worker_q, int worker_p, int incremental)
|
||||
Int size;
|
||||
|
||||
/* make sure both stacks have same size */
|
||||
Int p_size = ThreadHandle[worker_p].ssize+ThreadHandle[worker_p].tsize;
|
||||
Int q_size = ThreadHandle[worker_q].ssize+ThreadHandle[worker_q].tsize;
|
||||
Int p_size = FOREIGN_ThreadHandle(worker_p).ssize+FOREIGN_ThreadHandle(worker_p).tsize;
|
||||
Int q_size = FOREIGN_ThreadHandle(worker_q).ssize+FOREIGN_ThreadHandle(worker_q).tsize;
|
||||
if (p_size != q_size) {
|
||||
if (!(ThreadHandle[worker_q].stack_address = realloc(ThreadHandle[worker_q].stack_address,p_size*1024))) {
|
||||
if (!(FOREIGN_ThreadHandle(worker_q).stack_address = realloc(FOREIGN_ThreadHandle(worker_q).stack_address,p_size*1024))) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
ThreadHandle[worker_q].ssize = ThreadHandle[worker_p].ssize;
|
||||
ThreadHandle[worker_q].tsize = ThreadHandle[worker_p].tsize;
|
||||
FOREIGN_ThreadHandle(worker_q).ssize = FOREIGN_ThreadHandle(worker_p).ssize;
|
||||
FOREIGN_ThreadHandle(worker_q).tsize = FOREIGN_ThreadHandle(worker_p).tsize;
|
||||
/* compute offset indicators */
|
||||
Yap_GlobalBase = Yap_thread_gl[worker_p].global_base;
|
||||
Yap_LocalBase = Yap_thread_gl[worker_p].local_base;
|
||||
Yap_TrailBase = Yap_thread_gl[worker_p].trail_base;
|
||||
Yap_TrailTop = Yap_thread_gl[worker_p].trail_top;
|
||||
size = ThreadHandle[worker_q].stack_address-ThreadHandle[worker_p].stack_address;
|
||||
size = FOREIGN_ThreadHandle(worker_q).stack_address-FOREIGN_ThreadHandle(worker_p).stack_address;
|
||||
TrDiff = LDiff = GDiff = GDiff0 = DelayDiff = BaseDiff = size;
|
||||
XDiff = HDiff = 0;
|
||||
GSplit = NULL;
|
||||
H = ThreadHandle[worker_p].current_yaam_regs->H_;
|
||||
H0 = ThreadHandle[worker_p].current_yaam_regs->H0_;
|
||||
B = ThreadHandle[worker_p].current_yaam_regs->B_;
|
||||
ENV = ThreadHandle[worker_p].current_yaam_regs->ENV_;
|
||||
YENV = ThreadHandle[worker_p].current_yaam_regs->YENV_;
|
||||
ASP = ThreadHandle[worker_p].current_yaam_regs->ASP_;
|
||||
TR = ThreadHandle[worker_p].current_yaam_regs->TR_;
|
||||
H = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->H_;
|
||||
H0 = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->H0_;
|
||||
B = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->B_;
|
||||
ENV = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->ENV_;
|
||||
YENV = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->YENV_;
|
||||
ASP = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->ASP_;
|
||||
TR = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->TR_;
|
||||
if (ASP > CellPtr(B))
|
||||
ASP = CellPtr(B);
|
||||
LCL0 = ThreadHandle[worker_p].current_yaam_regs->LCL0_;
|
||||
LCL0 = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->LCL0_;
|
||||
#ifdef CUT_C
|
||||
Yap_REGS.CUT_C_TOP = ThreadHandle[worker_p].current_yaam_regs->CUT_C_TOP;
|
||||
Yap_REGS.CUT_C_TOP = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->CUT_C_TOP;
|
||||
#endif
|
||||
DelayedVars = ThreadHandle[worker_p].current_yaam_regs->DelayedVars_;
|
||||
DelayedVars = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->DelayedVars_;
|
||||
DynamicArrays = NULL;
|
||||
StaticArrays = NULL;
|
||||
GlobalVariables = NULL;
|
||||
|
139
C/init.c
139
C/init.c
@ -1124,93 +1124,78 @@ InitInvisibleAtoms(void)
|
||||
}
|
||||
|
||||
#ifdef THREADS
|
||||
static void
|
||||
InitThreadHandles(void)
|
||||
InitThreadHandle(wid)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < MAX_THREADS; i++) {
|
||||
Yap_heap_regs->thread_handle[i].in_use = FALSE;
|
||||
Yap_heap_regs->thread_handle[i].zombie = FALSE;
|
||||
Yap_heap_regs->thread_handle[i].local_preds = NULL;
|
||||
FOREIGN_ThreadHandle(wid).in_use = FALSE;
|
||||
FOREIGN_ThreadHandle(wid).zombie = FALSE;
|
||||
FOREIGN_ThreadHandle(wid).local_preds = NULL;
|
||||
#ifdef LOW_LEVEL_TRACER
|
||||
Yap_heap_regs->thread_handle[i].thread_inst_count = 0LL;
|
||||
FOREIGN_ThreadHandle(wid).thread_inst_count = 0LL;
|
||||
#endif
|
||||
pthread_mutex_init(&Yap_heap_regs->thread_handle[i].tlock, NULL);
|
||||
pthread_mutex_init(&(FOREIGN_ThreadHandle(wid).tlock), NULL);
|
||||
}
|
||||
Yap_heap_regs->thread_handle[0].id = 0;
|
||||
Yap_heap_regs->thread_handle[0].in_use = TRUE;
|
||||
Yap_heap_regs->thread_handle[0].default_yaam_regs =
|
||||
#endif
|
||||
|
||||
static void
|
||||
InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
#ifdef THREADS
|
||||
ThreadHandle.id = 0;
|
||||
ThreadHandle.in_use = TRUE;
|
||||
ThreadHandle.default_yaam_regs =
|
||||
&Yap_standard_regs;
|
||||
Yap_heap_regs->thread_handle[0].pthread_handle = pthread_self();
|
||||
Yap_heap_regs->thread_handle[0].pthread_handle = pthread_self();
|
||||
pthread_mutex_init(&ThreadHandle[0].tlock, NULL);
|
||||
pthread_mutex_init(&ThreadHandle[0].tlock_status, NULL);
|
||||
Yap_heap_regs->thread_handle[0].tdetach = MkAtomTerm(AtomFalse);
|
||||
ThreadHandle.pthread_handle = pthread_self();
|
||||
ThreadHandle.pthread_handle = pthread_self();
|
||||
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock, NULL);
|
||||
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock_status, NULL);
|
||||
ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
InitScratchPad(int wid)
|
||||
{
|
||||
FOREIGN_WL(wid)->scratchpad.ptr = NULL;
|
||||
FOREIGN_WL(wid)->scratchpad.sz = SCRATCH_START_SIZE;
|
||||
FOREIGN_WL(wid)->scratchpad.msz = SCRATCH_START_SIZE;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_CloseScratchPad(void)
|
||||
{
|
||||
Yap_FreeCodeSpace(ScratchPad.ptr);
|
||||
ScratchPad.sz = SCRATCH_START_SIZE;
|
||||
ScratchPad.msz = SCRATCH_START_SIZE;
|
||||
}
|
||||
|
||||
#include "iglobals.h"
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
#define MAX_INITS 1
|
||||
#else
|
||||
#define MAX_INITS 1
|
||||
#endif
|
||||
|
||||
struct worker_shared Yap_Global;
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
struct worker_local Yap_WLocal[MAX_WORKERS];
|
||||
#else
|
||||
struct worker_local Yap_WLocal;
|
||||
#endif
|
||||
|
||||
static void
|
||||
InitCodes(void)
|
||||
{
|
||||
int wid;
|
||||
#include "ihstruct.h"
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < MAX_AGENTS; i++) {
|
||||
INIT_LOCK(Yap_heap_regs->wl[i].signal_lock);
|
||||
Yap_heap_regs->wl[i].active_signals = 0;
|
||||
Yap_heap_regs->wl[i].scratchpad.ptr = NULL;
|
||||
Yap_heap_regs->wl[i].scratchpad.sz = SCRATCH_START_SIZE;
|
||||
Yap_heap_regs->wl[i].scratchpad.msz = SCRATCH_START_SIZE;
|
||||
Yap_heap_regs->wl[i].dynamic_arrays = NULL;
|
||||
Yap_heap_regs->wl[i].static_arrays = NULL;
|
||||
Yap_heap_regs->wl[i].global_variables = NULL;
|
||||
Yap_heap_regs->wl[i].global_arena = 0L;
|
||||
Yap_heap_regs->wl[i].global_arena_overflows = 0;
|
||||
Yap_heap_regs->wl[i].allow_restart = FALSE;
|
||||
Yap_heap_regs->wl[i].tot_gc_time = 0;
|
||||
Yap_heap_regs->wl[i].tot_gc_recovered = 0;
|
||||
Yap_heap_regs->wl[i].gc_calls = 0;
|
||||
Yap_heap_regs->wl[i].last_gc_time = 0;
|
||||
Yap_heap_regs->wl[i].last_ss_time = 0;
|
||||
Yap_heap_regs->wl[i].consultlow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
||||
if (Yap_heap_regs->wl[i].consultlow == NULL) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
||||
return;
|
||||
}
|
||||
Yap_heap_regs->wl[i].consultcapacity = InitialConsultCapacity;
|
||||
Yap_heap_regs->wl[i].consultbase = Yap_heap_regs->wl[i].consultsp =
|
||||
Yap_heap_regs->wl[i].consultlow + Yap_heap_regs->wl[i].consultcapacity;
|
||||
Yap_heap_regs->wl[i].Gc_timestamp = 0;
|
||||
Yap_heap_regs->wl[i].ball_term = NULL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
Yap_heap_regs->wl.dynamic_arrays = NULL;
|
||||
Yap_heap_regs->wl.static_arrays = NULL;
|
||||
Yap_heap_regs->wl.global_variables = NULL;
|
||||
Yap_heap_regs->wl.global_arena = 0L;
|
||||
Yap_heap_regs->wl.global_arena_overflows = 0;
|
||||
Yap_heap_regs->wl.allow_restart = FALSE;
|
||||
Yap_heap_regs->wl.tot_gc_time = 0;
|
||||
Yap_heap_regs->wl.tot_gc_recovered = 0;
|
||||
Yap_heap_regs->wl.gc_calls = 0;
|
||||
Yap_heap_regs->wl.last_gc_time = 0;
|
||||
Yap_heap_regs->wl.last_ss_time = 0;
|
||||
Yap_heap_regs->wl.consultlow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj)*InitialConsultCapacity);
|
||||
if (Yap_heap_regs->wl.consultlow == NULL) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCodes");
|
||||
return;
|
||||
}
|
||||
Yap_heap_regs->wl.consultcapacity = InitialConsultCapacity;
|
||||
Yap_heap_regs->wl.consultbase = Yap_heap_regs->wl.consultsp =
|
||||
Yap_heap_regs->wl.consultlow + Yap_heap_regs->wl.consultcapacity;
|
||||
Yap_heap_regs->wl.ball_term = NULL;
|
||||
#endif /* YAPOR */
|
||||
|
||||
InitGlobal();
|
||||
for (wid = 0; wid < MAX_INITS; wid++)
|
||||
InitWorker(wid);
|
||||
InitFirstWorkerThreadHandle();
|
||||
/* make sure no one else can use these two atoms */
|
||||
CurrentModule = 0;
|
||||
Yap_ReleaseAtom(AtomOfTerm(Yap_heap_regs->term_refound_var));
|
||||
Yap_ReleaseAtom(AtomOfTerm(TermReFoundVar));
|
||||
/* make sure we have undefp defined */
|
||||
/* predicates can only be defined after this point */
|
||||
{
|
||||
@ -1304,14 +1289,6 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
|
||||
for (i = 0; i <= LAST_FLAG; i++) {
|
||||
yap_flags[i] = 0;
|
||||
}
|
||||
ActiveSignals = 0;
|
||||
DoingUndefp = FALSE;
|
||||
DelayArenaOverflows = 0;
|
||||
ArenaOverflows = 0;
|
||||
DepthArenas = 0;
|
||||
DBErasedList = NULL;
|
||||
DBErasedIList = NULL;
|
||||
Yap_heap_regs->IntLUKeys = NULL;
|
||||
#ifdef MPW
|
||||
Yap_InitAbsmi(REGS, FunctorList);
|
||||
#else
|
||||
|
3
C/save.c
3
C/save.c
@ -475,7 +475,10 @@ save_heap(void)
|
||||
#endif
|
||||
int j;
|
||||
/* Then save the whole heap */
|
||||
Yap_ResetConsultStack();
|
||||
#if defined(YAPOR) || (defined(TABLING) && !defined(YAP_MEMORY_ALLOC_SCHEME))
|
||||
Yap_ResetConsultStack();
|
||||
Yap_CloseScratchPad();
|
||||
/* skip the local and global data structures */
|
||||
j = Unsigned(&GLOBAL) - Unsigned(Yap_HeapBase);
|
||||
putout(j);
|
||||
|
42
C/sysbits.c
42
C/sysbits.c
@ -332,8 +332,8 @@ bla bla
|
||||
#endif
|
||||
|
||||
#if THREADS
|
||||
#define StartOfTimes (*(ThreadHandle[worker_id].start_of_timesp))
|
||||
#define last_time (*(ThreadHandle[worker_id].last_timep))
|
||||
#define StartOfTimes (*(MY_ThreadHandle.start_of_timesp))
|
||||
#define last_time (*(MY_ThreadHandle.last_timep))
|
||||
|
||||
#else
|
||||
/* since the point YAP was started */
|
||||
@ -352,8 +352,8 @@ InitTime (void)
|
||||
struct rusage rusage;
|
||||
|
||||
#if THREADS
|
||||
ThreadHandle[worker_id].start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
ThreadHandle[worker_id].last_timep = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
MY_ThreadHandle.start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
MY_ThreadHandle.last_timep = (struct timeval *)malloc(sizeof(struct timeval));
|
||||
#endif
|
||||
getrusage(RUSAGE_SELF, &rusage);
|
||||
last_time.tv_sec = StartOfTimes.tv_sec = rusage.ru_utime.tv_sec;
|
||||
@ -2724,14 +2724,14 @@ p_first_signal(void)
|
||||
{
|
||||
LOCK(SignalLock);
|
||||
#ifdef THREADS
|
||||
pthread_mutex_lock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_lock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
/* always do wakeups first, because you don't want to keep the
|
||||
non-backtrackable variable bad */
|
||||
if (ActiveSignals & YAP_WAKEUP_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_WAKEUP_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigWakeUp));
|
||||
@ -2739,7 +2739,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_ITI_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_ITI_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigIti));
|
||||
@ -2747,7 +2747,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_INT_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_INT_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigInt));
|
||||
@ -2755,7 +2755,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_USR2_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_USR2_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr2));
|
||||
@ -2763,7 +2763,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_USR1_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_USR1_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigUsr1));
|
||||
@ -2771,7 +2771,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_PIPE_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_PIPE_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigPipe));
|
||||
@ -2779,7 +2779,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_HUP_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_HUP_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigHup));
|
||||
@ -2797,7 +2797,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_DELAY_CREEP_SIGNAL) {
|
||||
ActiveSignals &= ~(YAP_CREEP_SIGNAL|YAP_DELAY_CREEP_SIGNAL);
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigDelayCreep));
|
||||
@ -2805,7 +2805,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_CREEP_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_CREEP_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigCreep));
|
||||
@ -2813,7 +2813,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_TRACE_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_TRACE_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigTrace));
|
||||
@ -2821,7 +2821,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_DEBUG_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_DEBUG_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigDebug));
|
||||
@ -2829,7 +2829,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_BREAK_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_BREAK_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigBreak));
|
||||
@ -2837,7 +2837,7 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_STACK_DUMP_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_STACK_DUMP_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigStackDump));
|
||||
@ -2845,13 +2845,13 @@ p_first_signal(void)
|
||||
if (ActiveSignals & YAP_STATISTICS_SIGNAL) {
|
||||
ActiveSignals &= ~YAP_STATISTICS_SIGNAL;
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return Yap_unify(ARG1, MkAtomTerm(AtomSigStatistics));
|
||||
}
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
UNLOCK(SignalLock);
|
||||
return FALSE;
|
||||
@ -2904,7 +2904,7 @@ p_continue_signals(void)
|
||||
Yap_signal(YAP_STATISTICS_SIGNAL);
|
||||
}
|
||||
#ifdef THREADS
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
199
C/threads.c
199
C/threads.c
@ -1,3 +1,4 @@
|
||||
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
@ -52,13 +53,13 @@ allocate_new_tid(void)
|
||||
int new_worker_id = 0;
|
||||
LOCK(ThreadHandlesLock);
|
||||
while(new_worker_id < MAX_THREADS &&
|
||||
(ThreadHandle[new_worker_id].in_use == TRUE ||
|
||||
ThreadHandle[new_worker_id].zombie == TRUE) )
|
||||
(FOREIGN_ThreadHandle(new_worker_id).in_use == TRUE ||
|
||||
FOREIGN_ThreadHandle(new_worker_id).zombie == TRUE) )
|
||||
new_worker_id++;
|
||||
if (new_worker_id < MAX_THREADS) {
|
||||
DEBUG_TLOCK_ACCESS(new_worker_id, 0);
|
||||
pthread_mutex_lock(&(ThreadHandle[new_worker_id].tlock));
|
||||
ThreadHandle[new_worker_id].in_use = TRUE;
|
||||
pthread_mutex_lock(&(FOREIGN_ThreadHandle(new_worker_id).tlock));
|
||||
FOREIGN_ThreadHandle(new_worker_id).in_use = TRUE;
|
||||
} else {
|
||||
new_worker_id = -1;
|
||||
}
|
||||
@ -77,28 +78,28 @@ store_specs(int new_worker_id, UInt ssize, UInt tsize, UInt sysize, Term *tpgoal
|
||||
tsize = MinTrailSpace;
|
||||
if (ssize < MinStackSpace)
|
||||
ssize = MinStackSpace;
|
||||
ThreadHandle[new_worker_id].ssize = ssize;
|
||||
ThreadHandle[new_worker_id].tsize = tsize;
|
||||
ThreadHandle[new_worker_id].sysize = sysize;
|
||||
FOREIGN_ThreadHandle(new_worker_id).ssize = ssize;
|
||||
FOREIGN_ThreadHandle(new_worker_id).tsize = tsize;
|
||||
FOREIGN_ThreadHandle(new_worker_id).sysize = sysize;
|
||||
pm = (ssize + tsize)*1024;
|
||||
if (!(ThreadHandle[new_worker_id].stack_address = malloc(pm))) {
|
||||
if (!(FOREIGN_ThreadHandle(new_worker_id).stack_address = malloc(pm))) {
|
||||
return FALSE;
|
||||
}
|
||||
ThreadHandle[new_worker_id].tgoal =
|
||||
FOREIGN_ThreadHandle(new_worker_id).tgoal =
|
||||
Yap_StoreTermInDB(Deref(*tpgoal),7);
|
||||
ThreadHandle[new_worker_id].cmod =
|
||||
FOREIGN_ThreadHandle(new_worker_id).cmod =
|
||||
CurrentModule;
|
||||
tdetach = Deref(*tpdetach);
|
||||
if (IsVarTerm(tdetach)){
|
||||
ThreadHandle[new_worker_id].tdetach =
|
||||
FOREIGN_ThreadHandle(new_worker_id).tdetach =
|
||||
MkAtomTerm(AtomFalse);
|
||||
} else {
|
||||
ThreadHandle[new_worker_id].tdetach =
|
||||
FOREIGN_ThreadHandle(new_worker_id).tdetach =
|
||||
tdetach;
|
||||
}
|
||||
tgoal = Yap_StripModule(Deref(*tpexit), &tmod);
|
||||
ThreadHandle[new_worker_id].texit_mod = tmod;
|
||||
ThreadHandle[new_worker_id].texit =
|
||||
FOREIGN_ThreadHandle(new_worker_id).texit_mod = tmod;
|
||||
FOREIGN_ThreadHandle(new_worker_id).texit =
|
||||
Yap_StoreTermInDB(tgoal,7);
|
||||
return TRUE;
|
||||
}
|
||||
@ -107,7 +108,7 @@ store_specs(int new_worker_id, UInt ssize, UInt tsize, UInt sysize, Term *tpgoal
|
||||
static void
|
||||
kill_thread_engine (int wid, int always_die)
|
||||
{
|
||||
Prop p0 = AbsPredProp(Yap_heap_regs->thread_handle[wid].local_preds);
|
||||
Prop p0 = AbsPredProp(FOREIGN_ThreadHandle(wid).local_preds);
|
||||
GlobalEntry *gl = GlobalVariables;
|
||||
|
||||
/* kill all thread local preds */
|
||||
@ -122,20 +123,20 @@ kill_thread_engine (int wid, int always_die)
|
||||
gl = gl->NextGE;
|
||||
}
|
||||
Yap_KillStacks(wid);
|
||||
Yap_heap_regs->wl[wid].active_signals = 0L;
|
||||
free(Yap_heap_regs->wl[wid].scratchpad.ptr);
|
||||
free(ThreadHandle[wid].default_yaam_regs);
|
||||
ThreadHandle[wid].current_yaam_regs = NULL;
|
||||
free(ThreadHandle[wid].start_of_timesp);
|
||||
free(ThreadHandle[wid].last_timep);
|
||||
Yap_FreeCodeSpace((ADDR)ThreadHandle[wid].texit);
|
||||
FOREIGN_WL(wid)->active_signals = 0L;
|
||||
free(FOREIGN_WL(wid)->scratchpad.ptr);
|
||||
free(FOREIGN_ThreadHandle(wid).default_yaam_regs);
|
||||
FOREIGN_ThreadHandle(wid).current_yaam_regs = NULL;
|
||||
free(FOREIGN_ThreadHandle(wid).start_of_timesp);
|
||||
free(FOREIGN_ThreadHandle(wid).last_timep);
|
||||
Yap_FreeCodeSpace((ADDR)FOREIGN_ThreadHandle(wid).texit);
|
||||
LOCK(ThreadHandlesLock);
|
||||
if (ThreadHandle[wid].tdetach == MkAtomTerm(AtomTrue) ||
|
||||
if (FOREIGN_ThreadHandle(wid).tdetach == MkAtomTerm(AtomTrue) ||
|
||||
always_die) {
|
||||
ThreadHandle[wid].zombie = FALSE;
|
||||
ThreadHandle[wid].in_use = FALSE;
|
||||
FOREIGN_ThreadHandle(wid).zombie = FALSE;
|
||||
FOREIGN_ThreadHandle(wid).in_use = FALSE;
|
||||
DEBUG_TLOCK_ACCESS(1, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
}
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
}
|
||||
@ -157,11 +158,11 @@ setup_engine(int myworker_id)
|
||||
|
||||
standard_regs = (REGSTORE *)calloc(1,sizeof(REGSTORE));
|
||||
/* create the YAAM descriptor */
|
||||
ThreadHandle[myworker_id].default_yaam_regs = standard_regs;
|
||||
FOREIGN_ThreadHandle(myworker_id).default_yaam_regs = standard_regs;
|
||||
pthread_setspecific(Yap_yaamregs_key, (void *)standard_regs);
|
||||
worker_id = myworker_id;
|
||||
Yap_InitExStacks(ThreadHandle[myworker_id].tsize, ThreadHandle[myworker_id].ssize);
|
||||
CurrentModule = ThreadHandle[myworker_id].cmod;
|
||||
Yap_InitExStacks(FOREIGN_ThreadHandle(myworker_id).tsize, FOREIGN_ThreadHandle(myworker_id).ssize);
|
||||
CurrentModule = FOREIGN_ThreadHandle(myworker_id).cmod;
|
||||
Yap_InitTime();
|
||||
Yap_InitYaamRegs();
|
||||
#ifdef YAPOR
|
||||
@ -171,7 +172,7 @@ setup_engine(int myworker_id)
|
||||
/* I exist */
|
||||
NOfThreadsCreated++;
|
||||
DEBUG_TLOCK_ACCESS(2, myworker_id);
|
||||
pthread_mutex_unlock(&(ThreadHandle[myworker_id].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(myworker_id).tlock));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -190,7 +191,7 @@ thread_run(void *widp)
|
||||
|
||||
start_thread(myworker_id);
|
||||
do {
|
||||
t = tgs[0] = Yap_PopTermFromDB(ThreadHandle[worker_id].tgoal);
|
||||
t = tgs[0] = Yap_PopTermFromDB(MY_ThreadHandle.tgoal);
|
||||
if (t == 0) {
|
||||
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
@ -201,7 +202,7 @@ thread_run(void *widp)
|
||||
}
|
||||
} else {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
if (!Yap_growstack(ThreadHandle[worker_id].tgoal->NOfCells*CellSize)) {
|
||||
if (!Yap_growstack(MY_ThreadHandle.tgoal->NOfCells*CellSize)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
thread_die(worker_id, FALSE);
|
||||
return NULL;
|
||||
@ -209,8 +210,8 @@ thread_run(void *widp)
|
||||
}
|
||||
}
|
||||
} while (t == 0);
|
||||
ThreadHandle[myworker_id].tgoal = NULL;
|
||||
tgs[1] = ThreadHandle[worker_id].tdetach;
|
||||
FOREIGN_ThreadHandle(myworker_id).tgoal = NULL;
|
||||
tgs[1] = MY_ThreadHandle.tdetach;
|
||||
tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs);
|
||||
Yap_RunTopGoal(tgoal);
|
||||
thread_die(worker_id, FALSE);
|
||||
@ -261,9 +262,9 @@ p_create_thread(void)
|
||||
/* make sure we can proceed */
|
||||
if (!init_thread_engine(new_worker_id, ssize, tsize, sysize, &ARG1, &ARG5, &ARG6))
|
||||
return FALSE;
|
||||
ThreadHandle[new_worker_id].id = new_worker_id;
|
||||
ThreadHandle[new_worker_id].ref_count = 1;
|
||||
if ((ThreadHandle[new_worker_id].ret = pthread_create(&ThreadHandle[new_worker_id].pthread_handle, NULL, thread_run, (void *)(&(ThreadHandle[new_worker_id].id)))) == 0) {
|
||||
FOREIGN_ThreadHandle(new_worker_id).id = new_worker_id;
|
||||
FOREIGN_ThreadHandle(new_worker_id).ref_count = 1;
|
||||
if ((FOREIGN_ThreadHandle(new_worker_id).ret = pthread_create(&FOREIGN_ThreadHandle(new_worker_id).pthread_handle, NULL, thread_run, (void *)(&(FOREIGN_ThreadHandle(new_worker_id).id)))) == 0) {
|
||||
/* wait until the client is initialised */
|
||||
return TRUE;
|
||||
}
|
||||
@ -321,15 +322,15 @@ p_thread_zombie_self(void)
|
||||
if (pthread_getspecific(Yap_yaamregs_key) == NULL)
|
||||
return Yap_unify(MkIntegerTerm(-1), ARG1);
|
||||
DEBUG_TLOCK_ACCESS(4, worker_id);
|
||||
pthread_mutex_lock(&(ThreadHandle[worker_id].tlock));
|
||||
if (Yap_heap_regs->wl[worker_id].active_signals &= YAP_ITI_SIGNAL) {
|
||||
pthread_mutex_lock(&(MY_ThreadHandle.tlock));
|
||||
if (ActiveSignals &= YAP_ITI_SIGNAL) {
|
||||
DEBUG_TLOCK_ACCESS(5, worker_id);
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock));
|
||||
return FALSE;
|
||||
}
|
||||
// fprintf(stderr," -- %d\n", worker_id);
|
||||
Yap_heap_regs->thread_handle[worker_id].in_use = FALSE;
|
||||
Yap_heap_regs->thread_handle[worker_id].zombie = TRUE;
|
||||
MY_ThreadHandle.in_use = FALSE;
|
||||
MY_ThreadHandle.zombie = TRUE;
|
||||
return Yap_unify(MkIntegerTerm(worker_id), ARG1);
|
||||
}
|
||||
|
||||
@ -339,7 +340,7 @@ p_thread_status_lock(void)
|
||||
/* make sure the lock is available */
|
||||
if (pthread_getspecific(Yap_yaamregs_key) == NULL)
|
||||
return FALSE;
|
||||
pthread_mutex_lock(&(ThreadHandle[worker_id].tlock_status));
|
||||
pthread_mutex_lock(&(MY_ThreadHandle.tlock_status));
|
||||
return Yap_unify(MkIntegerTerm(worker_id), ARG1);
|
||||
}
|
||||
|
||||
@ -349,7 +350,7 @@ p_thread_status_unlock(void)
|
||||
/* make sure the lock is available */
|
||||
if (pthread_getspecific(Yap_yaamregs_key) == NULL)
|
||||
return FALSE;
|
||||
pthread_mutex_unlock(&(ThreadHandle[worker_id].tlock_status));
|
||||
pthread_mutex_unlock(&(MY_ThreadHandle.tlock_status));
|
||||
return Yap_unify(MkIntegerTerm(worker_id), ARG1);
|
||||
}
|
||||
|
||||
@ -372,9 +373,9 @@ Yap_thread_create_engine(thread_attr *ops)
|
||||
}
|
||||
if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
|
||||
return FALSE;
|
||||
ThreadHandle[new_id].id = new_id;
|
||||
ThreadHandle[new_id].pthread_handle = pthread_self();
|
||||
ThreadHandle[new_id].ref_count = 0;
|
||||
FOREIGN_ThreadHandle(new_id).id = new_id;
|
||||
FOREIGN_ThreadHandle(new_id).pthread_handle = pthread_self();
|
||||
FOREIGN_ThreadHandle(new_id).ref_count = 0;
|
||||
setup_engine(new_id);
|
||||
return TRUE;
|
||||
}
|
||||
@ -383,17 +384,17 @@ Int
|
||||
Yap_thread_attach_engine(int wid)
|
||||
{
|
||||
DEBUG_TLOCK_ACCESS(7, wid);
|
||||
pthread_mutex_lock(&(ThreadHandle[wid].tlock));
|
||||
if (ThreadHandle[wid].ref_count ) {
|
||||
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
if (FOREIGN_ThreadHandle(wid).ref_count ) {
|
||||
DEBUG_TLOCK_ACCESS(8, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return FALSE;
|
||||
}
|
||||
ThreadHandle[wid].pthread_handle = pthread_self();
|
||||
ThreadHandle[wid].ref_count++;
|
||||
FOREIGN_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||
FOREIGN_ThreadHandle(wid).ref_count++;
|
||||
worker_id = wid;
|
||||
DEBUG_TLOCK_ACCESS(9, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -401,22 +402,22 @@ Int
|
||||
Yap_thread_detach_engine(int wid)
|
||||
{
|
||||
DEBUG_TLOCK_ACCESS(10, wid);
|
||||
pthread_mutex_lock(&(ThreadHandle[wid].tlock));
|
||||
ThreadHandle[wid].ref_count--;
|
||||
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
FOREIGN_ThreadHandle(wid).ref_count--;
|
||||
DEBUG_TLOCK_ACCESS(11, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Int
|
||||
Yap_thread_destroy_engine(int wid)
|
||||
{
|
||||
if (ThreadHandle[wid].ref_count == 0) {
|
||||
if (FOREIGN_ThreadHandle(wid).ref_count == 0) {
|
||||
kill_thread_engine(wid, TRUE);
|
||||
return TRUE;
|
||||
} else {
|
||||
DEBUG_TLOCK_ACCESS(12, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@ -428,18 +429,18 @@ p_thread_join(void)
|
||||
Int tid = IntegerOfTerm(Deref(ARG1));
|
||||
|
||||
LOCK(ThreadHandlesLock);
|
||||
if (!ThreadHandle[tid].in_use &&
|
||||
!ThreadHandle[tid].zombie) {
|
||||
if (!FOREIGN_ThreadHandle(tid).in_use &&
|
||||
!FOREIGN_ThreadHandle(tid).zombie) {
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return FALSE;
|
||||
}
|
||||
if (!ThreadHandle[tid].tdetach == MkAtomTerm(AtomTrue)) {
|
||||
if (!FOREIGN_ThreadHandle(tid).tdetach == MkAtomTerm(AtomTrue)) {
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return FALSE;
|
||||
}
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
/* make sure this lock is accessible */
|
||||
if (pthread_join(ThreadHandle[tid].pthread_handle, NULL) < 0) {
|
||||
if (pthread_join(FOREIGN_ThreadHandle(tid).pthread_handle, NULL) < 0) {
|
||||
/* ERROR */
|
||||
return FALSE;
|
||||
}
|
||||
@ -453,10 +454,10 @@ p_thread_destroy(void)
|
||||
Int tid = IntegerOfTerm(Deref(ARG1));
|
||||
|
||||
LOCK(ThreadHandlesLock);
|
||||
ThreadHandle[tid].zombie = FALSE;
|
||||
ThreadHandle[tid].in_use = FALSE;
|
||||
FOREIGN_ThreadHandle(tid).zombie = FALSE;
|
||||
FOREIGN_ThreadHandle(tid).in_use = FALSE;
|
||||
DEBUG_TLOCK_ACCESS(32, tid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[tid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return TRUE;
|
||||
}
|
||||
@ -465,26 +466,26 @@ static Int
|
||||
p_thread_detach(void)
|
||||
{
|
||||
Int tid = IntegerOfTerm(Deref(ARG1));
|
||||
pthread_mutex_lock(&(ThreadHandle[tid].tlock));
|
||||
pthread_mutex_lock(&(FOREIGN_ThreadHandle(tid).tlock));
|
||||
DEBUG_TLOCK_ACCESS(14, tid);
|
||||
if (pthread_detach(ThreadHandle[tid].pthread_handle) < 0) {
|
||||
if (pthread_detach(FOREIGN_ThreadHandle(tid).pthread_handle) < 0) {
|
||||
/* ERROR */
|
||||
DEBUG_TLOCK_ACCESS(15, tid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[tid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
|
||||
return FALSE;
|
||||
}
|
||||
ThreadHandle[tid].tdetach =
|
||||
FOREIGN_ThreadHandle(tid).tdetach =
|
||||
MkAtomTerm(AtomTrue);
|
||||
DEBUG_TLOCK_ACCESS(30, tid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[tid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_thread_detached(void)
|
||||
{
|
||||
if (ThreadHandle[worker_id].tdetach)
|
||||
return Yap_unify(ARG1,ThreadHandle[worker_id].tdetach);
|
||||
if (MY_ThreadHandle.tdetach)
|
||||
return Yap_unify(ARG1,MY_ThreadHandle.tdetach);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
@ -493,8 +494,8 @@ static Int
|
||||
p_thread_detached2(void)
|
||||
{
|
||||
Int tid = IntegerOfTerm(Deref(ARG1));
|
||||
if (ThreadHandle[tid].tdetach)
|
||||
return Yap_unify(ARG2,ThreadHandle[tid].tdetach);
|
||||
if (FOREIGN_ThreadHandle(tid).tdetach)
|
||||
return Yap_unify(ARG2,FOREIGN_ThreadHandle(tid).tdetach);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
@ -542,7 +543,7 @@ static Int
|
||||
p_valid_thread(void)
|
||||
{
|
||||
Int i = IntegerOfTerm(Deref(ARG1));
|
||||
return ThreadHandle[i].in_use || ThreadHandle[i].zombie;
|
||||
return FOREIGN_ThreadHandle(i).in_use || FOREIGN_ThreadHandle(i).zombie;
|
||||
}
|
||||
|
||||
/* Mutex Support */
|
||||
@ -694,14 +695,14 @@ p_thread_stacks(void)
|
||||
Int status= TRUE;
|
||||
|
||||
LOCK(ThreadHandlesLock);
|
||||
if (!ThreadHandle[tid].in_use &&
|
||||
!ThreadHandle[tid].zombie) {
|
||||
if (!FOREIGN_ThreadHandle(tid).in_use &&
|
||||
!FOREIGN_ThreadHandle(tid).zombie) {
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return FALSE;
|
||||
}
|
||||
status &= Yap_unify(ARG2,MkIntegerTerm(ThreadHandle[tid].ssize));
|
||||
status &= Yap_unify(ARG3,MkIntegerTerm(ThreadHandle[tid].tsize));
|
||||
status &= Yap_unify(ARG4,MkIntegerTerm(ThreadHandle[tid].sysize));
|
||||
status &= Yap_unify(ARG2,MkIntegerTerm(FOREIGN_ThreadHandle(tid).ssize));
|
||||
status &= Yap_unify(ARG3,MkIntegerTerm(FOREIGN_ThreadHandle(tid).tsize));
|
||||
status &= Yap_unify(ARG4,MkIntegerTerm(FOREIGN_ThreadHandle(tid).sysize));
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
return status;
|
||||
}
|
||||
@ -711,13 +712,13 @@ p_thread_atexit(void)
|
||||
{ /* '$thread_signal'(+P) */
|
||||
Term t;
|
||||
|
||||
if (!ThreadHandle[worker_id].texit ||
|
||||
ThreadHandle[worker_id].texit->Entry == MkAtomTerm(AtomTrue)) {
|
||||
if (!MY_ThreadHandle.texit ||
|
||||
MY_ThreadHandle.texit->Entry == MkAtomTerm(AtomTrue)) {
|
||||
return FALSE;
|
||||
}
|
||||
do {
|
||||
t = Yap_PopTermFromDB(ThreadHandle[worker_id].texit);
|
||||
ThreadHandle[worker_id].texit = NULL;
|
||||
t = Yap_PopTermFromDB(MY_ThreadHandle.texit);
|
||||
MY_ThreadHandle.texit = NULL;
|
||||
if (t == 0) {
|
||||
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
@ -728,7 +729,7 @@ p_thread_atexit(void)
|
||||
}
|
||||
} else {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
if (!Yap_growstack(ThreadHandle[worker_id].tgoal->NOfCells*CellSize)) {
|
||||
if (!Yap_growstack(MY_ThreadHandle.tgoal->NOfCells*CellSize)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
thread_die(worker_id, FALSE);
|
||||
return FALSE;
|
||||
@ -736,7 +737,7 @@ p_thread_atexit(void)
|
||||
}
|
||||
}
|
||||
} while (t == 0);
|
||||
return Yap_unify(ARG1, t) && Yap_unify(ARG2, ThreadHandle[worker_id].texit_mod);
|
||||
return Yap_unify(ARG1, t) && Yap_unify(ARG2, MY_ThreadHandle.texit_mod);
|
||||
}
|
||||
|
||||
|
||||
@ -746,21 +747,21 @@ p_thread_signal(void)
|
||||
{ /* '$thread_signal'(+P) */
|
||||
Int wid = IntegerOfTerm(Deref(ARG1));
|
||||
/* make sure the lock is available */
|
||||
pthread_mutex_lock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
DEBUG_TLOCK_ACCESS(16, wid);
|
||||
if (!ThreadHandle[wid].in_use ||
|
||||
!ThreadHandle[wid].current_yaam_regs) {
|
||||
if (!FOREIGN_ThreadHandle(wid).in_use ||
|
||||
!FOREIGN_ThreadHandle(wid).current_yaam_regs) {
|
||||
DEBUG_TLOCK_ACCESS(17, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
LOCK(Yap_heap_regs->wl[wid].signal_lock);
|
||||
ThreadHandle[wid].current_yaam_regs->CreepFlag_ =
|
||||
Unsigned(ThreadHandle[wid].current_yaam_regs->LCL0_);
|
||||
Yap_heap_regs->wl[wid].active_signals |= YAP_ITI_SIGNAL;
|
||||
UNLOCK(Yap_heap_regs->wl[wid].signal_lock);
|
||||
LOCK(FOREIGN_WL(wid)->signal_lock);
|
||||
FOREIGN_ThreadHandle(wid).current_yaam_regs->CreepFlag_ =
|
||||
Unsigned(FOREIGN_ThreadHandle(wid).current_yaam_regs->LCL0_);
|
||||
FOREIGN_WL(wid)->active_signals |= YAP_ITI_SIGNAL;
|
||||
UNLOCK(FOREIGN_WL(wid)->signal_lock);
|
||||
DEBUG_TLOCK_ACCESS(18, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -776,7 +777,7 @@ p_nof_threads(void)
|
||||
int i = 0, wid;
|
||||
LOCK(ThreadHandlesLock);
|
||||
for (wid = 0; wid < MAX_THREADS; wid++) {
|
||||
if (ThreadHandle[wid].in_use)
|
||||
if (FOREIGN_ThreadHandle(wid).in_use)
|
||||
i++;
|
||||
}
|
||||
UNLOCK(ThreadHandlesLock);
|
||||
@ -810,7 +811,7 @@ p_thread_runtime(void)
|
||||
static Int
|
||||
p_thread_self_lock(void)
|
||||
{ /* '$thread_unlock' */
|
||||
pthread_mutex_lock(&(ThreadHandle[worker_id].tlock));
|
||||
pthread_mutex_lock(&(MY_ThreadHandle.tlock));
|
||||
return Yap_unify(ARG1,MkIntegerTerm(worker_id));
|
||||
}
|
||||
|
||||
@ -819,7 +820,7 @@ p_thread_unlock(void)
|
||||
{ /* '$thread_unlock' */
|
||||
Int wid = IntegerOfTerm(Deref(ARG1));
|
||||
DEBUG_TLOCK_ACCESS(19, wid);
|
||||
pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
|
||||
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
sc = Yap_heap_regs;
|
||||
vsc_count++;
|
||||
#ifdef THREADS
|
||||
Yap_heap_regs->thread_handle[worker_id].thread_inst_count++;
|
||||
MY_ThreadHandle.thread_inst_count++;
|
||||
#endif
|
||||
#ifdef COMMENTED
|
||||
//*(H0+(0xb65f2850-0xb64b2008)/sizeof(CELL))==0xc ||
|
||||
|
2
H/Yap.h
2
H/Yap.h
@ -261,7 +261,7 @@ extern char Yap_Option[20];
|
||||
#endif
|
||||
#endif /* !IN_SECOND_QUADRANT */
|
||||
|
||||
/* #define RANDOMIZE_START_ADDRESS 1*/
|
||||
#define RANDOMIZE_START_ADDRESS 1
|
||||
|
||||
#ifdef USE_SYSTEM_MALLOC
|
||||
#define HEAP_INIT_BASE 0L
|
||||
|
284
H/YapHeap.h
284
H/YapHeap.h
@ -22,12 +22,6 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(THREADS)
|
||||
#define RINFO rinfo[worker_id]
|
||||
#else
|
||||
#define RINFO rinfo
|
||||
#endif
|
||||
|
||||
#ifndef INT_KEYS_DEFAULT_SIZE
|
||||
#define INT_KEYS_DEFAULT_SIZE 256
|
||||
#endif
|
||||
@ -77,118 +71,28 @@ typedef struct scratch_block_struct {
|
||||
} scratch_block;
|
||||
|
||||
typedef struct restore_info {
|
||||
Int
|
||||
base_diff,
|
||||
cl_diff,
|
||||
g_diff,
|
||||
g_diff0,
|
||||
h_diff,
|
||||
l_diff,
|
||||
tr_diff,
|
||||
x_diff,
|
||||
delay_diff;
|
||||
CELL *old_ASP, *old_LCL0;
|
||||
Int base_diff;
|
||||
Int cl_diff;
|
||||
Int g_diff;
|
||||
Int g_diff0;
|
||||
Int h_diff;
|
||||
Int l_diff;
|
||||
Int tr_diff;
|
||||
Int x_diff;
|
||||
Int delay_diff;
|
||||
CELL *old_ASP;
|
||||
CELL *old_LCL0;
|
||||
CELL *g_split;
|
||||
tr_fr_ptr old_TR;
|
||||
CELL *old_GlobalBase, *old_H, *old_H0;
|
||||
ADDR old_TrailBase, old_TrailTop;
|
||||
ADDR old_HeapBase, old_HeapTop;
|
||||
CELL *old_GlobalBase;
|
||||
CELL *old_H;
|
||||
CELL *old_H0;
|
||||
ADDR old_TrailBase;
|
||||
ADDR old_TrailTop;
|
||||
ADDR old_HeapBase;
|
||||
ADDR old_HeapTop;
|
||||
} restoreinfo;
|
||||
|
||||
#if defined(THREADS)
|
||||
extern struct restore_info rinfo[MAX_THREADS];
|
||||
#else
|
||||
extern struct restore_info rinfo;
|
||||
#endif
|
||||
|
||||
typedef struct worker_local_struct {
|
||||
struct format_status *f_info;
|
||||
Int delay_arena_overflows;
|
||||
Int arena_overflows;
|
||||
Int depth_arenas;
|
||||
char *scanner_stack;
|
||||
struct scanner_extra_alloc *scanner_extra_blocks;
|
||||
struct DB_TERM *ball_term;
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar signal_lock; /* protect signal handlers from IPIs */
|
||||
struct pred_entry *wpp;
|
||||
#endif
|
||||
#ifdef USE_GMP
|
||||
mpz_t big_tmp;
|
||||
#endif
|
||||
union CONSULT_OBJ *consultsp;
|
||||
union CONSULT_OBJ *consultbase;
|
||||
union CONSULT_OBJ *consultlow;
|
||||
struct pred_entry *last_asserted_pred;
|
||||
int debug_on;
|
||||
int interrupts_disabled;
|
||||
UInt consultcapacity;
|
||||
UInt active_signals;
|
||||
UInt i_pred_arity;
|
||||
yamop *prof_end;
|
||||
Int start_line;
|
||||
int uncaught_throw;
|
||||
int doing_undefp;
|
||||
int arith_error;
|
||||
scratch_block scratchpad;
|
||||
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
||||
Term woken_goals;
|
||||
Term atts_mutable_list;
|
||||
#endif
|
||||
/* gc_stuff */
|
||||
Term gc_generation; /* global stack limit at last generation */
|
||||
Term gc_phase; /* gc phase to be sure we are on a valid compression */
|
||||
UInt gc_current_phase; /* gc currrent phase */
|
||||
unsigned int gc_calls; /* number of times GC has been called */
|
||||
Int tot_gc_time; /* total time spent in GC */
|
||||
YAP_ULONG_LONG tot_gc_recovered; /* number of heap objects in all garbage collections */
|
||||
Int last_gc_time, last_ss_time; /* number of heap objects in all garbage collections */
|
||||
/* in a single gc */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
/* otherwise, use global variables for speed */
|
||||
unsigned long int tot_marked, tot_oldies; /* number of heap objects marked */
|
||||
#ifdef COROUTINING
|
||||
unsigned long int tot_smarked;
|
||||
#endif
|
||||
struct choicept *wl_current_B;
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
struct trail_frame *wl_sTR, *wl_sTR0;
|
||||
struct trail_frame *new_tr;
|
||||
#else
|
||||
Term *wl_sTR, *wl_sTR0;
|
||||
Term *new_tr;
|
||||
#endif
|
||||
CELL *wl_prev_HB;
|
||||
CELL *hgen;
|
||||
CELL **ip_top;
|
||||
#if GC_NO_TAGS
|
||||
char *b_p;
|
||||
#endif
|
||||
struct gc_mark_continuation *conttop0;
|
||||
struct gc_mark_continuation *conttop;
|
||||
int disc_trail_entries;
|
||||
gc_ma_hash_entry Gc_ma_hash_table[GC_MAVARS_HASH_SIZE];
|
||||
gc_ma_hash_entry *Gc_ma_h_top;
|
||||
gc_ma_hash_entry *Gc_ma_h_list;
|
||||
UInt Gc_timestamp; /* an unsigned int */
|
||||
ADDR DB_vec, DB_vec0;
|
||||
struct RB_red_blk_node *DB_root, *DB_nil;
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
jmp_buf gc_restore; /* where to jump if garbage collection crashes */
|
||||
struct array_entry *dynamic_arrays;
|
||||
struct static_array_entry *static_arrays;
|
||||
struct global_entry *global_variables;
|
||||
struct reduction_counters call_counters;
|
||||
int allow_restart;
|
||||
Term global_arena;
|
||||
UInt global_arena_overflows;
|
||||
yamop trust_lu_code[3];
|
||||
#if (defined(YAPOR) || defined(TABLING) ) && defined(THREADS)
|
||||
#ifdef YAPOR
|
||||
struct worker worker;
|
||||
#endif /* YAPOR */
|
||||
#endif
|
||||
} worker_local;
|
||||
|
||||
#ifdef THREADS
|
||||
typedef struct thandle {
|
||||
@ -224,155 +128,53 @@ typedef struct thandle {
|
||||
|
||||
typedef int (*Agc_hook)(Atom);
|
||||
|
||||
/*******************
|
||||
this is the data base: everything here should be possible to restore
|
||||
********************/
|
||||
typedef struct various_codes {
|
||||
/* memory allocation and management */
|
||||
special_functors funcs;
|
||||
|
||||
#include "hstruct.h"
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
struct global_data global;
|
||||
struct local_data remote[MAX_WORKERS];
|
||||
#endif /* YAPOR || TABLING */
|
||||
} all_heap_codes;
|
||||
|
||||
#include "hglobals.h"
|
||||
|
||||
extern struct worker_shared Yap_Global;
|
||||
#define Yap_global (&Yap_Global)
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
extern struct worker_local Yap_WLocal[MAX_WORKERS];
|
||||
#define WL (Yap_WLocal+worker_id)
|
||||
#define FOREIGN_WL(wid) (Yap_WLocal+(wid))
|
||||
#else
|
||||
extern struct worker_local Yap_WLocal;
|
||||
#define WL (&Yap_WLocal)
|
||||
#define FOREIGN_WL(wid) (&Yap_WLocal)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_SYSTEM_MALLOC
|
||||
extern struct various_codes *Yap_heap_regs;
|
||||
#else
|
||||
#define Yap_heap_regs ((all_heap_codes *)HEAP_INIT_BASE)
|
||||
#endif
|
||||
|
||||
#define FloatFormat Yap_heap_regs->float_format
|
||||
|
||||
#define PROLOG_MODULE 0
|
||||
|
||||
#include "dhstruct.h"
|
||||
#include "dglobals.h"
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
#define SignalLock Yap_heap_regs->wl[worker_id].signal_lock
|
||||
#define WPP Yap_heap_regs->wl[worker_id].wpp
|
||||
#define total_marked Yap_heap_regs->wl[worker_id].tot_marked
|
||||
#define total_oldies Yap_heap_regs->wl[worker_id].tot_oldies
|
||||
#if DEBUG
|
||||
#ifdef COROUTINING
|
||||
#define total_smarked Yap_heap_regs->wl[worker_id].tot_smarked
|
||||
#endif
|
||||
#endif /* DEBUG */
|
||||
#define current_B Yap_heap_regs->wl[worker_id].wl_current_B
|
||||
#define sTR Yap_heap_regs->wl[worker_id].wl_sTR
|
||||
#define sTR0 Yap_heap_regs->wl[worker_id].wl_sTR0
|
||||
#define prev_HB Yap_heap_regs->wl[worker_id].wl_prev_HB
|
||||
#define new_TR Yap_heap_regs->wl[worker_id].new_tr
|
||||
#define HGEN Yap_heap_regs->wl[worker_id].hgen
|
||||
#define iptop Yap_heap_regs->wl[worker_id].ip_top
|
||||
#define discard_trail_entries Yap_heap_regs->wl[worker_id].disc_trail_entries
|
||||
#if GC_NO_TAGS
|
||||
#define Yap_bp Yap_heap_regs->wl[worker_id].b_p
|
||||
#endif /* GC_NO_TAGS */
|
||||
#define gc_ma_hash_table Yap_heap_regs->wl[worker_id].Gc_ma_hash_table
|
||||
#define gc_ma_h_top Yap_heap_regs->wl[worker_id].Gc_ma_h_top
|
||||
#define gc_ma_h_list Yap_heap_regs->wl[worker_id].Gc_ma_h_list
|
||||
#define gc_timestamp Yap_heap_regs->wl[worker_id].Gc_timestamp
|
||||
#define cont_top0 Yap_heap_regs->wl[worker_id].conttop0
|
||||
#define db_vec Yap_heap_regs->wl[worker_id].DB_vec
|
||||
#define db_vec0 Yap_heap_regs->wl[worker_id].DB_vec0
|
||||
#define db_root Yap_heap_regs->wl[worker_id].DB_root
|
||||
#define db_nil Yap_heap_regs->wl[worker_id].DB_nil
|
||||
#define cont_top Yap_heap_regs->wl[worker_id].conttop
|
||||
#endif
|
||||
#define OldASP RINFO.old_ASP
|
||||
#define OldLCL0 RINFO.old_LCL0
|
||||
#define OldTR RINFO.old_TR
|
||||
#define OldGlobalBase RINFO.old_GlobalBase
|
||||
#define OldH RINFO.old_H
|
||||
#define OldH0 RINFO.old_H0
|
||||
#define OldTrailBase RINFO.old_TrailBase
|
||||
#define OldTrailTop RINFO.old_TrailTop
|
||||
#define OldHeapBase RINFO.old_HeapBase
|
||||
#define OldHeapTop RINFO.old_HeapTop
|
||||
#define ClDiff RINFO.cl_diff
|
||||
#define GDiff RINFO.g_diff
|
||||
#define GDiff0 RINFO.g_diff0
|
||||
#define GSplit RINFO.g_split
|
||||
#define HDiff RINFO.h_diff
|
||||
#define LDiff RINFO.l_diff
|
||||
#define TrDiff RINFO.tr_diff
|
||||
#define XDiff RINFO.x_diff
|
||||
#define DelayDiff RINFO.delay_diff
|
||||
#define BaseDiff RINFO.base_diff
|
||||
|
||||
#define ReductionsCounter Yap_heap_regs->WL.call_counters.reductions
|
||||
#define PredEntriesCounter Yap_heap_regs->WL.call_counters.reductions_retries
|
||||
#define RetriesCounter Yap_heap_regs->WL.call_counters.retries
|
||||
#define ReductionsCounterOn Yap_heap_regs->WL.call_counters.reductions_on
|
||||
#define PredEntriesCounterOn Yap_heap_regs->WL.call_counters.reductions_retries_on
|
||||
#define RetriesCounterOn Yap_heap_regs->WL.call_counters.retries_on
|
||||
|
||||
#define Yap_InterruptsDisabled Yap_heap_regs->WL.interrupts_disabled
|
||||
/* current consult stack */
|
||||
#define ConsultSp Yap_heap_regs->WL.consultsp
|
||||
/* top of consult stack */
|
||||
#define ConsultBase Yap_heap_regs->WL.consultbase
|
||||
/* low-water mark for consult */
|
||||
#define ConsultLow Yap_heap_regs->WL.consultlow
|
||||
#define ArithError Yap_heap_regs->WL.arith_error
|
||||
#define LastAssertedPred Yap_heap_regs->WL.last_asserted_pred
|
||||
/* current maximum number of cells in consult stack */
|
||||
#define ConsultCapacity Yap_heap_regs->WL.consultcapacity
|
||||
#define DebugOn Yap_heap_regs->WL.debug_on
|
||||
#define FormatInfo Yap_heap_regs->WL.f_info
|
||||
#define DelayArenaOverflows Yap_heap_regs->WL.delay_arena_overflows
|
||||
#define ArenaOverflows Yap_heap_regs->WL.arena_overflows
|
||||
#define DepthArenas Yap_heap_regs->WL.depth_arenas
|
||||
#define ScannerStack Yap_heap_regs->WL.scanner_stack
|
||||
#define ScannerExtraBlocks Yap_heap_regs->WL.scanner_extra_blocks
|
||||
#define BallTerm Yap_heap_regs->WL.ball_term
|
||||
#define Yap_BigTmp Yap_heap_regs->WL.big_tmp
|
||||
#define ActiveSignals Yap_heap_regs->WL.active_signals
|
||||
#define IPredArity Yap_heap_regs->WL.i_pred_arity
|
||||
#define ProfEnd Yap_heap_regs->WL.prof_end
|
||||
#define UncaughtThrow Yap_heap_regs->WL.uncaught_throw
|
||||
#define DoingUndefp Yap_heap_regs->WL.doing_undefp
|
||||
#define StartLine Yap_heap_regs->WL.start_line
|
||||
#define ScratchPad Yap_heap_regs->WL.scratchpad
|
||||
#ifdef COROUTINING
|
||||
#define WokenGoals Yap_heap_regs->WL.woken_goals
|
||||
#define AttsMutableList Yap_heap_regs->WL.atts_mutable_list
|
||||
#endif
|
||||
#define GcGeneration Yap_heap_regs->WL.gc_generation
|
||||
#define GcPhase Yap_heap_regs->WL.gc_phase
|
||||
#define GcCurrentPhase Yap_heap_regs->WL.gc_current_phase
|
||||
#define GcCalls Yap_heap_regs->WL.gc_calls
|
||||
#define TotGcTime Yap_heap_regs->WL.tot_gc_time
|
||||
#define TotGcRecovered Yap_heap_regs->WL.tot_gc_recovered
|
||||
#define LastGcTime Yap_heap_regs->WL.last_gc_time
|
||||
#define LastSSTime Yap_heap_regs->WL.last_ss_time
|
||||
#define Yap_gc_restore Yap_heap_regs->WL.gc_restore
|
||||
#define TrustLUCode Yap_heap_regs->WL.trust_lu_code
|
||||
#define DynamicArrays Yap_heap_regs->WL.dynamic_arrays
|
||||
#define StaticArrays Yap_heap_regs->WL.static_arrays
|
||||
#define GlobalVariables Yap_heap_regs->WL.global_variables
|
||||
#define GlobalArena Yap_heap_regs->WL.global_arena
|
||||
#define GlobalArenaOverflows Yap_heap_regs->WL.global_arena_overflows
|
||||
#define Yap_AllowRestart Yap_heap_regs->WL.allow_restart
|
||||
|
||||
#define PredHashInitialSize 1039L
|
||||
#define PredHashIncrement 7919L
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
#define GLOBAL Yap_heap_regs->global
|
||||
#define REMOTE Yap_heap_regs->remote
|
||||
#ifdef THREADS
|
||||
#define WORKER Yap_heap_regs->WL.worker
|
||||
#endif
|
||||
#endif /* YAPOR || TABLING */
|
||||
/*******************
|
||||
these are the global variables: they need not be restored...
|
||||
********************/
|
||||
|
||||
#define UPDATE_MODE_IMMEDIATE 0
|
||||
#define UPDATE_MODE_LOGICAL 1
|
||||
#define UPDATE_MODE_LOGICAL_ASSERT 2
|
||||
|
||||
|
||||
|
||||
|
||||
/* initially allow for files with up to 1024 predicates. This number
|
||||
is extended whenever needed */
|
||||
#define InitialConsultCapacity 1024
|
||||
|
@ -138,6 +138,7 @@ void STD_PROTO(Yap_end_consult,(void));
|
||||
void STD_PROTO(Yap_Abolish,(struct pred_entry *));
|
||||
void STD_PROTO(Yap_BuildMegaClause,(struct pred_entry *));
|
||||
void STD_PROTO(Yap_EraseMegaClause,(yamop *,struct pred_entry *));
|
||||
void STD_PROTO(Yap_ResetConsultStack,(void));
|
||||
|
||||
|
||||
/* cmppreds.c */
|
||||
@ -243,6 +244,7 @@ void STD_PROTO(Yap_KillStacks,(void));
|
||||
void STD_PROTO(Yap_InitYaamRegs,(void));
|
||||
void STD_PROTO(Yap_ReInitWallTime, (void));
|
||||
int STD_PROTO(Yap_OpDec,(int,char *,Atom,Term));
|
||||
void STD_PROTO(Yap_CloseScratchPad,(void));
|
||||
|
||||
/* inlines.c */
|
||||
void STD_PROTO(Yap_InitInlines,(void));
|
||||
|
@ -414,8 +414,6 @@ IsModProperty (int flags)
|
||||
return (PropFlags) ((flags == ModProperty));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* operator property entry structure */
|
||||
typedef struct operator_entry
|
||||
{
|
||||
@ -1396,6 +1394,9 @@ typedef enum
|
||||
|
||||
#include "YapHeap.h"
|
||||
|
||||
#define PredHashInitialSize 1039L
|
||||
#define PredHashIncrement 7919L
|
||||
|
||||
EXTERN inline UInt STD_PROTO(PRED_HASH, (FunctorEntry *, Term, UInt));
|
||||
|
||||
EXTERN inline UInt
|
||||
@ -1417,7 +1418,7 @@ Yap_GetThreadPred(struct pred_entry *ap)
|
||||
{
|
||||
Functor f = ap->FunctorOfPred;
|
||||
Term mod = ap->ModuleOfPred;
|
||||
Prop p0 = AbsPredProp(Yap_heap_regs->thread_handle[worker_id].local_preds);
|
||||
Prop p0 = AbsPredProp(MY_ThreadHandle.local_preds);
|
||||
|
||||
while(p0) {
|
||||
PredEntry *ap = RepPredProp(p0);
|
||||
|
@ -189,7 +189,7 @@ restore_absmi_regs(REGSTORE * old_regs)
|
||||
memcpy(old_regs, Yap_regp, sizeof(REGSTORE));
|
||||
#ifdef THREADS
|
||||
pthread_setspecific(Yap_yaamregs_key, (void *)old_regs);
|
||||
ThreadHandle[worker_id].current_yaam_regs = old_regs;
|
||||
MY_ThreadHandle.current_yaam_regs = old_regs;
|
||||
#else
|
||||
Yap_regp = old_regs;
|
||||
#endif
|
||||
|
184
H/dglobals.h
Normal file
184
H/dglobals.h
Normal file
@ -0,0 +1,184 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define OldASP WL->rinfo.old_ASP
|
||||
#define OldLCL0 WL->rinfo.old_LCL0
|
||||
#define OldTR WL->rinfo.old_TR
|
||||
#define OldGlobalBase WL->rinfo.old_GlobalBase
|
||||
#define OldH WL->rinfo.old_H
|
||||
#define OldH0 WL->rinfo.old_H0
|
||||
#define OldTrailBase WL->rinfo.old_TrailBase
|
||||
#define OldTrailTop WL->rinfo.old_TrailTop
|
||||
#define OldHeapBase WL->rinfo.old_HeapBase
|
||||
#define OldHeapTop WL->rinfo.old_HeapTop
|
||||
#define ClDiff WL->rinfo.cl_diff
|
||||
#define GDiff WL->rinfo.g_diff
|
||||
#define HDiff WL->rinfo.h_diff
|
||||
#define GDiff0 WL->rinfo.g_diff0
|
||||
#define GSplit WL->rinfo.g_split
|
||||
#define LDiff WL->rinfo.l_diff
|
||||
#define TrDiff WL->rinfo.tr_diff
|
||||
#define XDiff WL->rinfo.x_diff
|
||||
#define DelayDiff WL->rinfo.delay_diff
|
||||
#define BaseDiff WL->rinfo.base_diff
|
||||
#define ReductionsCounter WL->call_counters.reductions
|
||||
#define PredEntriesCounter WL->call_counters.reductions_retries
|
||||
#define RetriesCounter WL->call_counters.retries
|
||||
#define ReductionsCounterOn WL->call_counters.reductions_on
|
||||
#define PredEntriesCounterOn WL->call_counters.reductions_retries_on
|
||||
#define RetriesCounterOn WL->call_counters.retries_on
|
||||
#define Yap_InterruptsDisabled WL->interrupts_disabled
|
||||
|
||||
|
||||
#define ConsultSp WL->consultsp
|
||||
|
||||
#define ConsultCapacity WL->consultcapacity
|
||||
|
||||
#define ConsultBase WL->consultbase
|
||||
|
||||
#define ConsultLow WL->consultlow
|
||||
|
||||
#define GlobalArena WL->global_arena
|
||||
#define GlobalArenaOverflows WL->global_arena_overflows
|
||||
#define DelayArenaOverflows WL->delay_arena_overflows
|
||||
#define ArenaOverflows WL->arena_overflows
|
||||
#define DepthArenas WL->depth_arenas
|
||||
#define ArithError WL->arith_error
|
||||
#define LastAssertedPred WL->last_asserted_pred
|
||||
#define DebugOn WL->debug_on
|
||||
#define FormatInfo WL->f_info
|
||||
#define ScannerStack WL->scanner_stack
|
||||
#define ScannerExtraBlocks WL->scanner_extra_blocks
|
||||
#define BallTerm WL->ball_term
|
||||
#define ActiveSignals WL->active_signals
|
||||
#define IPredArity WL->i_pred_arity
|
||||
#define ProfEnd WL->prof_end
|
||||
#define UncaughtThrow WL->uncaught_throw
|
||||
#define DoingUndefp WL->doing_undefp
|
||||
#define StartLine WL->start_line
|
||||
#define ScratchPad WL->scratchpad
|
||||
#ifdef COROUTINING
|
||||
#define WokenGoals WL->woken_goals
|
||||
#define AttsMutableList WL->atts_mutable_list
|
||||
#endif
|
||||
|
||||
#define GcGeneration WL->gc_generation
|
||||
#define GcPhase WL->gc_phase
|
||||
#define GcCurrentPhase WL->gc_current_phase
|
||||
#define GcCalls WL->gc_calls
|
||||
#define TotGcTime WL->tot_gc_time
|
||||
#define TotGcRecovered WL->tot_gc_recovered
|
||||
#define LastGcTime WL->last_gc_time
|
||||
#define LastSSTime WL->last_ss_time
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
#define SignalLock WL->signal_lock
|
||||
#define WPP WL->wpp
|
||||
|
||||
#define total_marked WL->tot_marked
|
||||
#define total_oldies WL->tot_oldies
|
||||
#if DEBUG && COROUTINING
|
||||
#define total_smarked WL->tot_smarked
|
||||
#endif
|
||||
#define current_B WL->wl_current_B
|
||||
#define prev_HB WL->wl_prev_HB
|
||||
#define HGEN WL->hgen
|
||||
#define iptop WL->ip_top
|
||||
#if GC_NO_TAGS
|
||||
#define Yap_bp WL->b_p
|
||||
#endif
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
#define sTR WL->wl_sTR
|
||||
#define sTR0 WL->wl_sTR0
|
||||
#define new_TR WL->new_tr
|
||||
#else
|
||||
#define sTR WL->wl_sTR
|
||||
#define sTR0 WL->wl_sTR0
|
||||
#define new_TR WL->new_tr
|
||||
#endif
|
||||
#define cont_top0 WL->conttop0
|
||||
#define cont_top WL->conttop
|
||||
#define discard_trail_entries WL->disc_trail_entries
|
||||
#define gc_ma_hash_table WL->Gc_ma_hash_table
|
||||
#define gc_ma_h_top WL->Gc_ma_h_top
|
||||
#define gc_ma_h_list WL->Gc_ma_h_list
|
||||
#define gc_timestamp WL->Gc_timestamp
|
||||
#define db_vec WL->DB_vec
|
||||
#define db_vec0 WL->DB_vec0
|
||||
#define db_root WL->DB_root
|
||||
#define db_nil WL->DB_nil
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
#define Yap_gc_restore WL->gc_restore
|
||||
#define DynamicArrays WL->dynamic_arrays
|
||||
#define StaticArrays WL->static_arrays
|
||||
#define GlobalVariables WL->global_variables
|
||||
#define Yap_AllowRestart WL->allow_restart
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
#define WORKER WL->worker
|
||||
#endif
|
||||
#ifdef THREADS
|
||||
#define ThreadHandle WL->thread_handle
|
||||
#define FOREIGN_ThreadHandle(wid) (Yap_WLocal[(wid)].thread_handle)
|
||||
#define MY_ThreadHandle (Yap_WLocal[worker_id].thread_handle)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if THREADS
|
||||
|
||||
#define NOfThreads Yap_global->n_of_threads
|
||||
|
||||
#define NOfThreadsCreated Yap_global->n_of_threads_created
|
||||
|
||||
#define ThreadsTotalTime Yap_global->threads_total_time
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
#define BGL Yap_global->bgl
|
||||
#endif
|
||||
|
||||
#define Yap_AllowLocalExpansion Yap_global->allow_local_expansion
|
||||
#define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion
|
||||
#define Yap_AllowTrailExpansion Yap_global->allow_trail_expansion
|
||||
#define SizeOfOverflow Yap_global->size_of_overflow
|
||||
|
||||
#define AGcLastCall Yap_global->agc_last_call
|
||||
|
||||
#define AGcThreshold Yap_global->agc_threshold
|
||||
#define AGCHook Yap_global->agc_hook
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
#define ReadlineBuf Yap_global->readline_buf
|
||||
#define ReadlinePos Yap_global->readline_pos
|
||||
#endif
|
||||
|
||||
#ifdef THREADS
|
||||
#define ThreadHandlesLock Yap_global->thread_handles_lock
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
#define GLOBAL Yap_global->global
|
||||
#define REMOTE Yap_global->remote
|
||||
#endif
|
||||
|
41
H/dhstruct.h
41
H/dhstruct.h
@ -24,27 +24,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
#define NOfThreads Yap_heap_regs->n_of_threads
|
||||
|
||||
#define NOfThreadsCreated Yap_heap_regs->n_of_threads_created
|
||||
|
||||
#define ThreadsTotalTime Yap_heap_regs->threads_total_time
|
||||
|
||||
#define BGL Yap_heap_regs->bgl
|
||||
|
||||
#define WorkerLocal Yap_heap_regs->wl
|
||||
#ifndef WL
|
||||
#define WL wl[worker_id]
|
||||
#endif
|
||||
#else
|
||||
#define WorkerLocak Yap_heap_regs->wl
|
||||
#ifndef WL
|
||||
#define WL wl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define Yap_HoleSize Yap_heap_regs->hole_size
|
||||
#define Yap_av Yap_heap_regs->av_
|
||||
@ -272,16 +251,6 @@
|
||||
#define Yap_AttsSize Yap_heap_regs->atts_size
|
||||
#endif
|
||||
|
||||
#define Yap_AllowLocalExpansion Yap_heap_regs->allow_local_expansion
|
||||
#define Yap_AllowGlobalExpansion Yap_heap_regs->allow_global_expansion
|
||||
#define Yap_AllowTrailExpansion Yap_heap_regs->allow_trail_expansion
|
||||
#define SizeOfOverflow Yap_heap_regs->size_of_overflow
|
||||
|
||||
#define AGcLastCall Yap_heap_regs->agc_last_call
|
||||
|
||||
#define AGcThreshold Yap_heap_regs->agc_threshold
|
||||
#define AGCHook Yap_heap_regs->agc_hook
|
||||
|
||||
#define yap_flags Yap_heap_regs->yap_flags_field
|
||||
|
||||
#define OpList Yap_heap_regs->op_list
|
||||
@ -296,11 +265,6 @@
|
||||
#define AtPrompt Yap_heap_regs->atprompt
|
||||
#define Prompt Yap_heap_regs->prompt
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
#define ReadlineBuf Yap_heap_regs->readline_buf
|
||||
#define ReadlinePos Yap_heap_regs->readline_pos
|
||||
#endif
|
||||
|
||||
#define CharConversionTable Yap_heap_regs->char_conversion_table
|
||||
#define CharConversionTable2 Yap_heap_regs->char_conversion_table2
|
||||
|
||||
@ -327,8 +291,3 @@
|
||||
#define ForeignCodeBase Yap_heap_regs->foreign_code_base
|
||||
#define ForeignCodeTop Yap_heap_regs->foreign_code_top
|
||||
#define ForeignCodeMax Yap_heap_regs->foreign_code_max
|
||||
|
||||
#ifdef THREADS
|
||||
#define ThreadHandlesLock Yap_heap_regs->thread_handles_lock
|
||||
#define ThreadHandle Yap_heap_regs->thread_handle
|
||||
#endif
|
||||
|
186
H/hglobals.h
Normal file
186
H/hglobals.h
Normal file
@ -0,0 +1,186 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct worker_local {
|
||||
|
||||
restoreinfo rinfo;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct reduction_counters call_counters;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int interrupts_disabled;
|
||||
|
||||
|
||||
union CONSULT_OBJ* consultsp;
|
||||
|
||||
UInt consultcapacity;
|
||||
|
||||
union CONSULT_OBJ* consultbase;
|
||||
|
||||
union CONSULT_OBJ* consultlow;
|
||||
|
||||
Term global_arena;
|
||||
UInt global_arena_overflows;
|
||||
Int delay_arena_overflows;
|
||||
Int arena_overflows;
|
||||
Int depth_arenas;
|
||||
int arith_error;
|
||||
struct pred_entry* last_asserted_pred;
|
||||
int debug_on;
|
||||
struct format_status* f_info;
|
||||
char* scanner_stack;
|
||||
struct scanner_extra_alloc* scanner_extra_blocks;
|
||||
struct DB_TERM *ball_term;
|
||||
UInt active_signals;
|
||||
UInt i_pred_arity;
|
||||
yamop* prof_end;
|
||||
int uncaught_throw;
|
||||
int doing_undefp;
|
||||
Int start_line;
|
||||
scratch_block scratchpad;
|
||||
#ifdef COROUTINING
|
||||
Term woken_goals;
|
||||
Term atts_mutable_list;
|
||||
#endif
|
||||
|
||||
Term gc_generation;
|
||||
Term gc_phase;
|
||||
UInt gc_current_phase;
|
||||
UInt gc_calls;
|
||||
Int tot_gc_time;
|
||||
YAP_ULONG_LONG tot_gc_recovered;
|
||||
Int last_gc_time;
|
||||
Int last_ss_time;
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar signal_lock;
|
||||
struct pred_entry* wpp;
|
||||
|
||||
Int tot_marked;
|
||||
Int tot_oldies;
|
||||
#if DEBUG && COROUTINING
|
||||
UInt tot_smarked;
|
||||
#endif
|
||||
struct choicept *wl_current_B;
|
||||
CELL* wl_prev_HB;
|
||||
CELL* hgen;
|
||||
CELL** ip_top;
|
||||
#if GC_NO_TAGS
|
||||
char* b_p;
|
||||
#endif
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
struct trail_frame* wl_sTR;
|
||||
struct trail_frame* wl_sTR0;
|
||||
struct trail_frame* new_tr;
|
||||
#else
|
||||
Term *wl_sTR;
|
||||
Term *wl_sTR0;
|
||||
Term *new_tr;
|
||||
#endif
|
||||
struct gc_mark_continuation* conttop0;
|
||||
struct gc_mark_continuation* conttop;
|
||||
int disc_trail_entries;
|
||||
gc_ma_hash_entry Gc_ma_hash_table[GC_MAVARS_HASH_SIZE];
|
||||
gc_ma_hash_entry* Gc_ma_h_top;
|
||||
gc_ma_hash_entry* Gc_ma_h_list;
|
||||
UInt Gc_timestamp;
|
||||
ADDR DB_vec;
|
||||
ADDR DB_vec0;
|
||||
struct RB_red_blk_node* DB_root;
|
||||
struct RB_red_blk_node* DB_nil;
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
jmp_buf gc_restore;
|
||||
struct array_entry* dynamic_arrays;
|
||||
struct static_array_entry* static_arrays;
|
||||
struct global_entry* global_variables;
|
||||
int allow_restart;
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
struct worker worker;
|
||||
#endif
|
||||
#ifdef THREADS
|
||||
struct thandle thread_handle;
|
||||
#define FOREIGN_ThreadHandle(wid) (Yap_WLocal[(wid)].thread_handle)
|
||||
#define MY_ThreadHandle (Yap_WLocal[worker_id].thread_handle)
|
||||
#endif
|
||||
|
||||
} w_local;
|
||||
|
||||
typedef struct worker_shared {
|
||||
|
||||
#if THREADS
|
||||
|
||||
UInt n_of_threads;
|
||||
|
||||
UInt n_of_threads_created;
|
||||
|
||||
UInt threads_total_time;
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
lockvar bgl;
|
||||
#endif
|
||||
|
||||
int allow_local_expansion;
|
||||
int allow_global_expansion;
|
||||
int allow_trail_expansion;
|
||||
UInt size_of_overflow;
|
||||
|
||||
UInt agc_last_call;
|
||||
|
||||
UInt agc_threshold;
|
||||
Agc_hook agc_hook;
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
char *readline_buf;
|
||||
char *readline_pos;
|
||||
#endif
|
||||
|
||||
#ifdef THREADS
|
||||
lockvar thread_handles_lock;
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
struct global_data global;
|
||||
struct local_data remote[MAX_WORKERS];
|
||||
#endif
|
||||
} w_shared;
|
41
H/hstruct.h
41
H/hstruct.h
@ -24,27 +24,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
UInt n_of_threads;
|
||||
|
||||
UInt n_of_threads_created;
|
||||
|
||||
UInt threads_total_time;
|
||||
|
||||
lockvar bgl;
|
||||
|
||||
worker_local wl[MAX_AGENTS];
|
||||
#ifndef WL
|
||||
#define WL wl[worker_id]
|
||||
#endif
|
||||
#else
|
||||
worker_local wl;
|
||||
#ifndef WL
|
||||
#define WL wl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UInt hole_size;
|
||||
struct malloc_state *av_;
|
||||
@ -272,16 +251,6 @@
|
||||
UInt atts_size;
|
||||
#endif
|
||||
|
||||
int allow_local_expansion;
|
||||
int allow_global_expansion;
|
||||
int allow_trail_expansion;
|
||||
UInt size_of_overflow;
|
||||
|
||||
UInt agc_last_call;
|
||||
|
||||
UInt agc_threshold;
|
||||
Agc_hook agc_hook;
|
||||
|
||||
Int yap_flags_field[NUMBER_OF_YAP_FLAGS];
|
||||
|
||||
struct operator_entry *op_list;
|
||||
@ -296,11 +265,6 @@
|
||||
Atom atprompt;
|
||||
char prompt[MAX_PROMPT];
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
char *readline_buf;
|
||||
char *readline_pos;
|
||||
#endif
|
||||
|
||||
char *char_conversion_table;
|
||||
char *char_conversion_table2;
|
||||
|
||||
@ -327,8 +291,3 @@
|
||||
ADDR foreign_code_base;
|
||||
ADDR foreign_code_top;
|
||||
ADDR foreign_code_max;
|
||||
|
||||
#ifdef THREADS
|
||||
lockvar thread_handles_lock;
|
||||
struct thandle thread_handle[MAX_THREADS];
|
||||
#endif
|
||||
|
184
H/iglobals.h
Normal file
184
H/iglobals.h
Normal file
@ -0,0 +1,184 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void InitWorker(int wid) {
|
||||
|
||||
FOREIGN_WL(wid)->rinfo.old_ASP = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_LCL0 = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_TR = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_GlobalBase = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_H = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_H0 = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_TrailBase = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_TrailTop = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_HeapBase = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_HeapTop = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.cl_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.g_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.h_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.g_diff0 = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.g_split = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.l_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.tr_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.x_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.delay_diff = 0L;
|
||||
FOREIGN_WL(wid)->rinfo.base_diff = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.reductions = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.reductions_retries = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.retries = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.reductions_on = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.reductions_retries_on = 0L;
|
||||
FOREIGN_WL(wid)->call_counters.retries_on = 0L;
|
||||
FOREIGN_WL(wid)->interrupts_disabled = FALSE;
|
||||
|
||||
|
||||
FOREIGN_WL(wid)->consultsp = NULL;
|
||||
|
||||
|
||||
|
||||
FOREIGN_WL(wid)->consultbase = NULL;
|
||||
|
||||
FOREIGN_WL(wid)->consultlow = NULL;
|
||||
|
||||
FOREIGN_WL(wid)->global_arena = 0L;
|
||||
FOREIGN_WL(wid)->global_arena_overflows = 0L;
|
||||
FOREIGN_WL(wid)->delay_arena_overflows = 0L;
|
||||
FOREIGN_WL(wid)->arena_overflows = 0L;
|
||||
FOREIGN_WL(wid)->depth_arenas = 0;
|
||||
FOREIGN_WL(wid)->arith_error = FALSE;
|
||||
FOREIGN_WL(wid)->last_asserted_pred = NULL;
|
||||
FOREIGN_WL(wid)->debug_on = FALSE;
|
||||
FOREIGN_WL(wid)->f_info = NULL;
|
||||
FOREIGN_WL(wid)->scanner_stack = NULL;
|
||||
FOREIGN_WL(wid)->scanner_extra_blocks = NULL;
|
||||
FOREIGN_WL(wid)->ball_term = NULL;
|
||||
FOREIGN_WL(wid)->active_signals = 0L;
|
||||
FOREIGN_WL(wid)->i_pred_arity = 0L;
|
||||
FOREIGN_WL(wid)->prof_end = NULL;
|
||||
FOREIGN_WL(wid)->uncaught_throw = FALSE;
|
||||
FOREIGN_WL(wid)->doing_undefp = FALSE;
|
||||
FOREIGN_WL(wid)->start_line = 0L;
|
||||
InitScratchPad(wid);
|
||||
#ifdef COROUTINING
|
||||
FOREIGN_WL(wid)->woken_goals = 0L;
|
||||
FOREIGN_WL(wid)->atts_mutable_list = 0L;
|
||||
#endif
|
||||
|
||||
FOREIGN_WL(wid)->gc_generation = 0L;
|
||||
FOREIGN_WL(wid)->gc_phase = 0L;
|
||||
FOREIGN_WL(wid)->gc_current_phase = 0L;
|
||||
FOREIGN_WL(wid)->gc_calls = 0L;
|
||||
FOREIGN_WL(wid)->tot_gc_time = 0L;
|
||||
FOREIGN_WL(wid)->tot_gc_recovered = 0L;
|
||||
FOREIGN_WL(wid)->last_gc_time = 0L;
|
||||
FOREIGN_WL(wid)->last_ss_time = 0L;
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
INIT_LOCK(FOREIGN_WL(wid)->signal_lock);
|
||||
FOREIGN_WL(wid)->wpp = NULL;
|
||||
|
||||
FOREIGN_WL(wid)->tot_marked = 0L;
|
||||
FOREIGN_WL(wid)->tot_oldies = 0L;
|
||||
#if DEBUG && COROUTINING
|
||||
FOREIGN_WL(wid)->tot_smarked = 0L;
|
||||
#endif
|
||||
FOREIGN_WL(wid)->wl_current_B = NULL;
|
||||
FOREIGN_WL(wid)->wl_prev_HB = NULL;
|
||||
FOREIGN_WL(wid)->hgen = NULL;
|
||||
FOREIGN_WL(wid)->ip_top = NULL;
|
||||
#if GC_NO_TAGS
|
||||
FOREIGN_WL(wid)->b_p = NULL;
|
||||
#endif
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
FOREIGN_WL(wid)->wl_sTR = NULL;
|
||||
FOREIGN_WL(wid)->wl_sTR0 = NULL;
|
||||
FOREIGN_WL(wid)->new_tr = NULL;
|
||||
#else
|
||||
FOREIGN_WL(wid)->wl_sTR = NULL;
|
||||
FOREIGN_WL(wid)->wl_sTR0 = NULL;
|
||||
FOREIGN_WL(wid)->new_tr = NULL;
|
||||
#endif
|
||||
FOREIGN_WL(wid)->conttop0 = NULL;
|
||||
FOREIGN_WL(wid)->conttop = NULL;
|
||||
FOREIGN_WL(wid)->disc_trail_entries = NULL;
|
||||
|
||||
FOREIGN_WL(wid)->Gc_ma_h_top = NULL;
|
||||
FOREIGN_WL(wid)->Gc_ma_h_list = NULL;
|
||||
FOREIGN_WL(wid)->Gc_timestamp = 0L;
|
||||
FOREIGN_WL(wid)->DB_vec = NULL;
|
||||
FOREIGN_WL(wid)->DB_vec0 = NULL;
|
||||
FOREIGN_WL(wid)->DB_root = NULL;
|
||||
FOREIGN_WL(wid)->DB_nil = NULL;
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
|
||||
FOREIGN_WL(wid)->dynamic_arrays = NULL;
|
||||
FOREIGN_WL(wid)->static_arrays = NULL;
|
||||
FOREIGN_WL(wid)->global_variables = NULL;
|
||||
FOREIGN_WL(wid)->allow_restart = FALSE;
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
||||
#endif
|
||||
#ifdef THREADS
|
||||
InitThreadHandle;
|
||||
#define FOREIGN_ThreadHandle(wid) (Yap_WLocal[(wid)].thread_handle)
|
||||
#define MY_ThreadHandle (Yap_WLocal[worker_id].thread_handle)
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void InitGlobal(void) {
|
||||
|
||||
#if THREADS
|
||||
|
||||
Yap_global->n_of_threads = 1;
|
||||
|
||||
Yap_global->n_of_threads_created = 1;
|
||||
|
||||
Yap_global->threads_total_time = 0L;
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
INIT_LOCK(Yap_global->bgl);
|
||||
#endif
|
||||
|
||||
Yap_global->allow_local_expansion = TRUE;
|
||||
Yap_global->allow_global_expansion = TRUE;
|
||||
Yap_global->allow_trail_expansion = TRUE;
|
||||
Yap_global->size_of_overflow = 0;
|
||||
|
||||
Yap_global->agc_last_call = 0;
|
||||
|
||||
Yap_global->agc_threshold = 10000;
|
||||
Yap_global->agc_hook = NULL;
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
Yap_global->readline_buf = NULL;
|
||||
Yap_global->readline_pos = 0L;
|
||||
#endif
|
||||
|
||||
#ifdef THREADS
|
||||
INIT_LOCK(Yap_global->thread_handles_lock);
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
|
||||
|
||||
#endif
|
||||
}
|
41
H/ihstruct.h
41
H/ihstruct.h
@ -24,27 +24,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
Yap_heap_regs->n_of_threads = 1;
|
||||
|
||||
Yap_heap_regs->n_of_threads_created = 1;
|
||||
|
||||
Yap_heap_regs->threads_total_time = 0L;
|
||||
|
||||
INIT_LOCK(Yap_heap_regs->bgl);
|
||||
|
||||
|
||||
#ifndef WL
|
||||
#define WL wl[worker_id]
|
||||
#endif
|
||||
#else
|
||||
|
||||
#ifndef WL
|
||||
#define WL wl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -272,16 +251,6 @@
|
||||
|
||||
#endif
|
||||
|
||||
Yap_heap_regs->allow_local_expansion = TRUE;
|
||||
Yap_heap_regs->allow_global_expansion = TRUE;
|
||||
Yap_heap_regs->allow_trail_expansion = TRUE;
|
||||
Yap_heap_regs->size_of_overflow = 0;
|
||||
|
||||
Yap_heap_regs->agc_last_call = 0;
|
||||
|
||||
Yap_heap_regs->agc_threshold = 10000;
|
||||
Yap_heap_regs->agc_hook = NULL;
|
||||
|
||||
InitFlags();
|
||||
|
||||
Yap_heap_regs->op_list = NULL;
|
||||
@ -296,11 +265,6 @@
|
||||
Yap_heap_regs->atprompt = AtomNil;
|
||||
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
Yap_heap_regs->readline_buf = NULL;
|
||||
Yap_heap_regs->readline_pos = 0L;
|
||||
#endif
|
||||
|
||||
Yap_heap_regs->char_conversion_table = NULL;
|
||||
Yap_heap_regs->char_conversion_table2 = NULL;
|
||||
|
||||
@ -327,8 +291,3 @@
|
||||
Yap_heap_regs->foreign_code_base = NULL;
|
||||
Yap_heap_regs->foreign_code_top = NULL;
|
||||
Yap_heap_regs->foreign_code_max = NULL;
|
||||
|
||||
#ifdef THREADS
|
||||
INIT_LOCK(Yap_heap_regs->thread_handles_lock);
|
||||
InitThreadHandles();
|
||||
#endif
|
||||
|
184
H/rglobals.h
Normal file
184
H/rglobals.h
Normal file
@ -0,0 +1,184 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void RestoreWorker(int wid) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FOREIGN_WL(wid)->global_arena = TermToGlobalOrAtomAdjust(FOREIGN_WL(wid)->global_arena);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RestoreBallTerm(wid);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef COROUTINING
|
||||
FOREIGN_WL(wid)->woken_goals = TermToGlobalAdjust(FOREIGN_WL(wid)->woken_goals);
|
||||
FOREIGN_WL(wid)->atts_mutable_list = TermToGlobalAdjust(FOREIGN_WL(wid)->atts_mutable_list);
|
||||
#endif
|
||||
|
||||
FOREIGN_WL(wid)->gc_generation = TermToGlobalAdjust(FOREIGN_WL(wid)->gc_generation);
|
||||
FOREIGN_WL(wid)->gc_phase = TermToGlobalAdjust(FOREIGN_WL(wid)->gc_phase);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
REINIT_LOCK(FOREIGN_WL(wid)->signal_lock);
|
||||
|
||||
|
||||
|
||||
|
||||
#if DEBUG && COROUTINING
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if GC_NO_TAGS
|
||||
|
||||
#endif
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
|
||||
FOREIGN_WL(wid)->dynamic_arrays = PtoArrayEAdjust(FOREIGN_WL(wid)->dynamic_arrays);
|
||||
FOREIGN_WL(wid)->static_arrays = PtoArraySAdjust(FOREIGN_WL(wid)->static_arrays);
|
||||
FOREIGN_WL(wid)->global_variables = PtoGlobalEAdjust(FOREIGN_WL(wid)->global_variables);
|
||||
|
||||
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
|
||||
#endif
|
||||
#ifdef THREADS
|
||||
|
||||
#define FOREIGN_ThreadHandle(wid) (Yap_WLocal[(wid)].thread_handle)
|
||||
#define MY_ThreadHandle (Yap_WLocal[worker_id].thread_handle)
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void RestoreGlobal(void) {
|
||||
|
||||
#if THREADS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
REINIT_LOCK(Yap_global->bgl);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef THREADS
|
||||
REINIT_LOCK(Yap_global->thread_handles_lock);
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
|
||||
|
||||
#endif
|
||||
}
|
86
H/rheap.h
86
H/rheap.h
@ -957,76 +957,36 @@ RestoreForeignCode(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RestoreBallTerm(int wid)
|
||||
{
|
||||
if (BallTerm) {
|
||||
BallTerm = DBTermAdjust(BallTerm);
|
||||
RestoreDBTerm(BallTerm, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RestoreScratchPad(int wid)
|
||||
{
|
||||
if (ScratchPad.ptr) {
|
||||
ScratchPad.ptr = AddrAdjust(ScratchPad.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#include "rglobals.h"
|
||||
|
||||
/* restore the failcodes */
|
||||
static void
|
||||
restore_codes(void)
|
||||
{
|
||||
Yap_heap_regs->heap_top = AddrAdjust(OldHeapTop);
|
||||
#include "rhstruct.h"
|
||||
#if !defined(THREADS) && !defined(YAPOR)
|
||||
/* restore consult stack. It consists of heap pointers, so it
|
||||
is easy to fix.
|
||||
*/
|
||||
if (Yap_heap_regs->wl.ball_term) {
|
||||
Yap_heap_regs->wl.ball_term =
|
||||
DBTermAdjust(Yap_heap_regs->wl.ball_term);
|
||||
RestoreDBTerm(Yap_heap_regs->wl.ball_term, TRUE);
|
||||
}
|
||||
Yap_heap_regs->wl.consultlow =
|
||||
ConsultObjAdjust(Yap_heap_regs->wl.consultlow);
|
||||
Yap_heap_regs->wl.consultbase =
|
||||
ConsultObjAdjust(Yap_heap_regs->wl.consultbase);
|
||||
Yap_heap_regs->wl.consultsp =
|
||||
ConsultObjAdjust(Yap_heap_regs->wl.consultsp);
|
||||
{
|
||||
/* we assume all pointers have the same size */
|
||||
register consult_obj *pt = Yap_heap_regs->wl.consultsp;
|
||||
while (pt <
|
||||
Yap_heap_regs->wl.consultlow+Yap_heap_regs->wl.consultcapacity) {
|
||||
pt->p = PropAdjust(pt->p);
|
||||
pt ++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if !defined(THREADS) && !defined(YAPOR)
|
||||
if (Yap_heap_regs->wl.scratchpad.ptr) {
|
||||
Yap_heap_regs->wl.scratchpad.ptr =
|
||||
(char *)AddrAdjust((ADDR)Yap_heap_regs->wl.scratchpad.ptr);
|
||||
}
|
||||
Yap_heap_regs->wl.gc_generation =
|
||||
AbsAppl(PtoGloAdjust(RepAppl(Yap_heap_regs->wl.gc_generation)));
|
||||
Yap_heap_regs->wl.gc_phase =
|
||||
AbsAppl(PtoGloAdjust(RepAppl(Yap_heap_regs->wl.gc_phase)));
|
||||
/* current phase is an integer */
|
||||
#endif
|
||||
#ifdef COROUTINING
|
||||
#if !defined(THREADS) && !defined(YAPOR)
|
||||
Yap_heap_regs->wl.atts_mutable_list =
|
||||
AbsAppl(PtoGloAdjust(RepAppl(Yap_heap_regs->wl.atts_mutable_list)));
|
||||
if (Yap_heap_regs->wl.dynamic_arrays) {
|
||||
Yap_heap_regs->wl.dynamic_arrays =
|
||||
PtoArrayEAdjust(Yap_heap_regs->wl.dynamic_arrays);
|
||||
}
|
||||
if (Yap_heap_regs->wl.static_arrays) {
|
||||
Yap_heap_regs->wl.static_arrays =
|
||||
PtoArraySAdjust(Yap_heap_regs->wl.static_arrays);
|
||||
}
|
||||
if (Yap_heap_regs->wl.global_variables) {
|
||||
Yap_heap_regs->wl.global_variables =
|
||||
PtoGlobalEAdjust(Yap_heap_regs->wl.global_variables);
|
||||
}
|
||||
if (Yap_heap_regs->wl.global_arena) {
|
||||
if (IsAtomTerm(Yap_heap_regs->wl.global_arena)) {
|
||||
Yap_heap_regs->wl.global_arena =
|
||||
AtomTermAdjust(Yap_heap_regs->wl.global_arena);
|
||||
} else {
|
||||
Yap_heap_regs->wl.global_arena =
|
||||
AbsAppl(PtoGloAdjust(RepAppl(Yap_heap_regs->wl.global_arena)));
|
||||
}
|
||||
}
|
||||
Yap_heap_regs->wl.allow_restart = FALSE;
|
||||
#endif
|
||||
RestoreGlobal();
|
||||
#ifndef worker_id
|
||||
#define worker_id 0
|
||||
#endif
|
||||
RestoreWorker(worker_id);
|
||||
}
|
||||
|
||||
|
||||
|
41
H/rhstruct.h
41
H/rhstruct.h
@ -24,27 +24,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
REINIT_LOCK(Yap_heap_regs->bgl);
|
||||
|
||||
|
||||
#ifndef WL
|
||||
#define WL wl[worker_id]
|
||||
#endif
|
||||
#else
|
||||
|
||||
#ifndef WL
|
||||
#define WL wl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -274,16 +253,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Yap_heap_regs->op_list = OpListAdjust(Yap_heap_regs->op_list);
|
||||
|
||||
|
||||
@ -296,11 +265,6 @@
|
||||
Yap_heap_regs->atprompt = AtomAdjust(Yap_heap_regs->atprompt);
|
||||
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Yap_heap_regs->char_conversion_table = CodeCharPAdjust(Yap_heap_regs->char_conversion_table);
|
||||
Yap_heap_regs->char_conversion_table2 = CodeCharPAdjust(Yap_heap_regs->char_conversion_table2);
|
||||
|
||||
@ -327,8 +291,3 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef THREADS
|
||||
REINIT_LOCK(Yap_heap_regs->thread_handles_lock);
|
||||
|
||||
#endif
|
||||
|
33
H/sshift.h
33
H/sshift.h
@ -675,7 +675,31 @@ PtoAtomHashEntryAdjust (AtomHashEntry * ptr)
|
||||
return (AtomHashEntry *) (((AtomHashEntry *) (CharP (ptr) + HDiff)));
|
||||
}
|
||||
|
||||
inline EXTERN Term TermToGlobalAdjust (Term);
|
||||
|
||||
inline EXTERN Term
|
||||
TermToGlobalAdjust (Term t)
|
||||
{
|
||||
if (t == 0L)
|
||||
return t;
|
||||
return AbsAppl(PtoGloAdjust(RepAppl(t)));
|
||||
}
|
||||
|
||||
inline EXTERN Term TermToGlobalOrAtomAdjust (Term);
|
||||
|
||||
inline EXTERN Term
|
||||
TermToGlobalOrAtomAdjust (Term t)
|
||||
{
|
||||
if (t == 0L)
|
||||
return t;
|
||||
if (IsAtomTerm(t))
|
||||
return AtomTermAdjust(t);
|
||||
if (IsApplTerm(t))
|
||||
return AbsAppl(PtoGloAdjust(RepAppl(t)));
|
||||
if (IsPairTerm(t))
|
||||
return AbsPair(PtoGloAdjust(RepPair(t)));
|
||||
return t;
|
||||
}
|
||||
|
||||
inline EXTERN opentry *OpRTableAdjust (opentry *);
|
||||
|
||||
@ -718,6 +742,8 @@ inline EXTERN ArrayEntry *PtoArrayEAdjust (ArrayEntry *);
|
||||
inline EXTERN ArrayEntry *
|
||||
PtoArrayEAdjust (ArrayEntry * ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
return (ArrayEntry *) (((ArrayEntry *) (CharP (ptr) + HDiff)));
|
||||
}
|
||||
|
||||
@ -727,6 +753,8 @@ inline EXTERN GlobalEntry *PtoGlobalEAdjust (GlobalEntry *);
|
||||
inline EXTERN GlobalEntry *
|
||||
PtoGlobalEAdjust (GlobalEntry * ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
return (GlobalEntry *) (((GlobalEntry *) (CharP (ptr) + HDiff)));
|
||||
}
|
||||
|
||||
@ -736,13 +764,14 @@ inline EXTERN StaticArrayEntry *PtoArraySAdjust (StaticArrayEntry *);
|
||||
inline EXTERN StaticArrayEntry *
|
||||
PtoArraySAdjust (StaticArrayEntry * ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
return (StaticArrayEntry *) (((StaticArrayEntry *) (CharP (ptr) + HDiff)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline EXTERN struct logic_upd_clause *PtoLUCAdjust (struct logic_upd_clause
|
||||
*);
|
||||
inline EXTERN struct logic_upd_clause *PtoLUCAdjust (struct logic_upd_clause*);
|
||||
|
||||
inline EXTERN struct logic_upd_clause *
|
||||
PtoLUCAdjust (struct logic_upd_clause *ptr)
|
||||
|
12
Makefile.in
12
Makefile.in
@ -126,10 +126,18 @@ HEADERS = \
|
||||
$(srcdir)/H/arith2.h $(srcdir)/H/attvar.h \
|
||||
$(srcdir)/H/clause.h $(srcdir)/H/compile.h \
|
||||
$(srcdir)/H/corout.h $(srcdir)/H/dlmalloc.h \
|
||||
$(srcdir)/H/dglobals.h \
|
||||
$(srcdir)/H/dhstruct.h \
|
||||
$(srcdir)/H/eval.h $(srcdir)/H/heapgc.h \
|
||||
$(srcdir)/H/hglobals.h \
|
||||
$(srcdir)/H/hstruct.h \
|
||||
$(srcdir)/H/iglobals.h \
|
||||
$(srcdir)/H/ihstruct.h \
|
||||
$(srcdir)/H/index.h $(srcdir)/H/iopreds.h \
|
||||
$(srcdir)/H/rclause.h \
|
||||
$(srcdir)/H/rglobals.h \
|
||||
$(srcdir)/H/rheap.h \
|
||||
$(srcdir)/H/rhstruct.h \
|
||||
$(srcdir)/H/threads.h \
|
||||
$(srcdir)/H/tracer.h \
|
||||
$(srcdir)/H/trim_trail.h \
|
||||
@ -593,13 +601,11 @@ install_data:
|
||||
@ENABLE_JPL@ (cd packages/jpl ; $(MAKE) install)
|
||||
$(INSTALL_DATA) $(srcdir)/LGPL/pillow/icon_address.pl $(DESTDIR)$(SHAREDIR)/Yap/
|
||||
$(INSTALL_DATA) $(srcdir)/LGPL/pillow/pillow.pl $(DESTDIR)$(SHAREDIR)/Yap/
|
||||
# (cd CLPQR ; $(MAKE) install)
|
||||
@INSTALLCLP@(cd LGPL/clp ; $(MAKE) install)
|
||||
# (cd CHR ; $(MAKE) install)
|
||||
@ENABLE_CLPQR@(cd packages/clpqr ; $(MAKE) install)
|
||||
(cd packages/CLPBN ; $(MAKE) install)
|
||||
(cd packages/ProbLog ; $(MAKE) install)
|
||||
@ENABLE_CHR@ (cd packages/chr ; $(MAKE) install)
|
||||
@ENABLE_CHR@ (cd packages/clpqr ; $(MAKE) install)
|
||||
|
||||
|
||||
##########
|
||||
|
209
misc/GLOBALS
Normal file
209
misc/GLOBALS
Normal file
@ -0,0 +1,209 @@
|
||||
//
|
||||
// File defining fields in the Yap_GLOBAL global structure
|
||||
//
|
||||
// these fields used to spread all over the place, because they must be used in 3 ways:
|
||||
// - they must be defined somewhere
|
||||
// - they have an #ifdef to get a shorter name
|
||||
// - they must be initialised somewhere
|
||||
// - they may be of interest to restore
|
||||
//
|
||||
// The defs include 4+ components:
|
||||
// Type
|
||||
// name in structured
|
||||
// global name
|
||||
// init code (optional)
|
||||
// restore code (optional)
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
// Stuff that must be considered local to a thread or worker
|
||||
START_WORKER_LOCAL
|
||||
|
||||
/* shifts and restore: per local data-structure */
|
||||
restoreinfo rinfo
|
||||
. rinfo.old_ASP OldASP =NULL
|
||||
. rinfo.old_LCL0 OldLCL0 =NULL
|
||||
. rinfo.old_TR OldTR =NULL
|
||||
. rinfo.old_GlobalBase OldGlobalBase =NULL
|
||||
. rinfo.old_H OldH =NULL
|
||||
. rinfo.old_H0 OldH0 =NULL
|
||||
. rinfo.old_TrailBase OldTrailBase =NULL
|
||||
. rinfo.old_TrailTop OldTrailTop =NULL
|
||||
. rinfo.old_HeapBase OldHeapBase =NULL
|
||||
. rinfo.old_HeapTop OldHeapTop =NULL
|
||||
. rinfo.cl_diff ClDiff =0L
|
||||
. rinfo.g_diff GDiff =0L
|
||||
. rinfo.h_diff HDiff =0L
|
||||
. rinfo.g_diff0 GDiff0 =0L
|
||||
. rinfo.g_split GSplit =NULL
|
||||
. rinfo.l_diff LDiff =0L
|
||||
. rinfo.tr_diff TrDiff =0L
|
||||
. rinfo.x_diff XDiff =0L
|
||||
. rinfo.delay_diff DelayDiff =0L
|
||||
. rinfo.base_diff BaseDiff =0L
|
||||
|
||||
struct reduction_counters call_counters
|
||||
. call_counters.reductions ReductionsCounter =0L
|
||||
. call_counters.reductions_retries PredEntriesCounter =0L
|
||||
. call_counters.retries RetriesCounter =0L
|
||||
. call_counters.reductions_on ReductionsCounterOn =0L
|
||||
. call_counters.reductions_retries_on PredEntriesCounterOn =0L
|
||||
. call_counters.retries_on RetriesCounterOn =0L
|
||||
|
||||
int interrupts_disabled Yap_InterruptsDisabled =FALSE
|
||||
|
||||
// support for consulting files
|
||||
/* current consult stack */
|
||||
union CONSULT_OBJ* consultsp ConsultSp =NULL
|
||||
/* current maximum number of cells in consult stack */
|
||||
UInt consultcapacity ConsultCapacity void
|
||||
/* top of consult stack */
|
||||
union CONSULT_OBJ* consultbase ConsultBase =NULL
|
||||
/* low-water mark for consult */
|
||||
union CONSULT_OBJ* consultlow ConsultLow =NULL
|
||||
|
||||
//global variables
|
||||
Term global_arena GlobalArena =0L TermToGlobalOrAtomAdjust
|
||||
UInt global_arena_overflows GlobalArenaOverflows =0L
|
||||
Int delay_arena_overflows DelayArenaOverflows =0L
|
||||
Int arena_overflows ArenaOverflows =0L
|
||||
Int depth_arenas DepthArenas =0
|
||||
|
||||
int arith_error ArithError =FALSE
|
||||
struct pred_entry* last_asserted_pred LastAssertedPred =NULL
|
||||
int debug_on DebugOn =FALSE
|
||||
struct format_status* f_info FormatInfo =NULL
|
||||
char* scanner_stack ScannerStack =NULL
|
||||
struct scanner_extra_alloc* scanner_extra_blocks ScannerExtraBlocks =NULL
|
||||
struct DB_TERM *ball_term BallTerm =NULL RestoreBallTerm(wid)
|
||||
UInt active_signals ActiveSignals =0L
|
||||
UInt i_pred_arity IPredArity =0L
|
||||
yamop* prof_end ProfEnd =NULL
|
||||
int uncaught_throw UncaughtThrow =FALSE
|
||||
int doing_undefp DoingUndefp =FALSE
|
||||
Int start_line StartLine =0L
|
||||
scratch_block scratchpad ScratchPad InitScratchPad(wid)
|
||||
#ifdef COROUTINING
|
||||
Term woken_goals WokenGoals =0L TermToGlobalAdjust
|
||||
Term atts_mutable_list AttsMutableList =0L TermToGlobalAdjust
|
||||
#endif
|
||||
|
||||
// gc_stuff
|
||||
Term gc_generation GcGeneration =0L TermToGlobalAdjust
|
||||
Term gc_phase GcPhase =0L TermToGlobalAdjust
|
||||
UInt gc_current_phase GcCurrentPhase =0L
|
||||
UInt gc_calls GcCalls =0L
|
||||
Int tot_gc_time TotGcTime =0L
|
||||
YAP_ULONG_LONG tot_gc_recovered TotGcRecovered =0L
|
||||
Int last_gc_time LastGcTime =0L
|
||||
Int last_ss_time LastSSTime =0L
|
||||
|
||||
// global variables that cannot be global in a thread/or-p implementation
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
lockvar signal_lock SignalLock MkLock
|
||||
struct pred_entry* wpp WPP =NULL
|
||||
/* in a single gc */
|
||||
Int tot_marked total_marked =0L
|
||||
Int tot_oldies total_oldies =0L
|
||||
#if DEBUG && COROUTINING
|
||||
UInt tot_smarked total_smarked =0L
|
||||
#endif
|
||||
struct choicept *wl_current_B current_B =NULL
|
||||
CELL* wl_prev_HB prev_HB =NULL
|
||||
CELL* hgen HGEN =NULL
|
||||
CELL** ip_top iptop =NULL
|
||||
#if GC_NO_TAGS
|
||||
char* b_p Yap_bp =NULL
|
||||
#endif
|
||||
#if defined(TABLING) || defined(SBA)
|
||||
struct trail_frame* wl_sTR sTR =NULL
|
||||
struct trail_frame* wl_sTR0 sTR0 =NULL
|
||||
struct trail_frame* new_tr new_TR =NULL
|
||||
#else
|
||||
Term *wl_sTR sTR =NULL
|
||||
Term *wl_sTR0 sTR0 =NULL
|
||||
Term *new_tr new_TR =NULL
|
||||
#endif
|
||||
struct gc_mark_continuation* conttop0 cont_top0 =NULL
|
||||
struct gc_mark_continuation* conttop cont_top =NULL
|
||||
int disc_trail_entries discard_trail_entries =NULL
|
||||
gc_ma_hash_entry Gc_ma_hash_table[GC_MAVARS_HASH_SIZE] gc_ma_hash_table void
|
||||
gc_ma_hash_entry* Gc_ma_h_top gc_ma_h_top =NULL
|
||||
gc_ma_hash_entry* Gc_ma_h_list gc_ma_h_list =NULL
|
||||
UInt Gc_timestamp gc_timestamp =0L
|
||||
ADDR DB_vec db_vec =NULL
|
||||
ADDR DB_vec0 db_vec0 =NULL
|
||||
struct RB_red_blk_node* DB_root db_root =NULL
|
||||
struct RB_red_blk_node* DB_nil db_nil =NULL
|
||||
#endif /* defined(YAPOR) || defined(THREADS) */
|
||||
|
||||
|
||||
jmp_buf gc_restore Yap_gc_restore void
|
||||
struct array_entry* dynamic_arrays DynamicArrays =NULL PtoArrayEAdjust
|
||||
struct static_array_entry* static_arrays StaticArrays =NULL PtoArraySAdjust
|
||||
struct global_entry* global_variables GlobalVariables =NULL PtoGlobalEAdjust
|
||||
int allow_restart Yap_AllowRestart =FALSE
|
||||
|
||||
// Ricardo's stuff
|
||||
#if (defined(YAPOR) || defined(TABLING)) && defined(THREADS)
|
||||
struct worker worker WORKER void
|
||||
#endif
|
||||
|
||||
#ifdef THREADS
|
||||
struct thandle thread_handle ThreadHandle InitThreadHandle
|
||||
#define FOREIGN_ThreadHandle(wid) (Yap_WLocal[(wid)].thread_handle)
|
||||
#define MY_ThreadHandle (Yap_WLocal[worker_id].thread_handle)
|
||||
#endif
|
||||
// END WORKER LOCAL STUFF
|
||||
END_WORKER_LOCAL
|
||||
|
||||
// Stuff that must be shared by all threads or workers
|
||||
START_WORKER_SHARED
|
||||
|
||||
/* multi-thread support */
|
||||
#if THREADS
|
||||
/* number of threads and processes in system */
|
||||
UInt n_of_threads NOfThreads =1
|
||||
/* number of threads created since start */
|
||||
UInt n_of_threads_created NOfThreadsCreated =1
|
||||
/* total run time for dead threads */
|
||||
UInt threads_total_time ThreadsTotalTime =0L
|
||||
#endif
|
||||
|
||||
// multi-thread/ORP support
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
// protect long critical regions
|
||||
lockvar bgl BGL MkLock
|
||||
#endif
|
||||
|
||||
// stack overflow expansion/gc control
|
||||
int allow_local_expansion Yap_AllowLocalExpansion =TRUE
|
||||
int allow_global_expansion Yap_AllowGlobalExpansion =TRUE
|
||||
int allow_trail_expansion Yap_AllowTrailExpansion =TRUE
|
||||
UInt size_of_overflow SizeOfOverflow =0
|
||||
// amount of space recovered in all garbage collections
|
||||
UInt agc_last_call AGcLastCall =0
|
||||
// amount of space recovered in all garbage collections
|
||||
UInt agc_threshold AGcThreshold =10000
|
||||
Agc_hook agc_hook AGCHook =NULL
|
||||
|
||||
// readline
|
||||
#if HAVE_LIBREADLINE
|
||||
char *readline_buf ReadlineBuf =NULL
|
||||
char *readline_pos ReadlinePos =0L
|
||||
#endif
|
||||
|
||||
// Threads Array
|
||||
#ifdef THREADS
|
||||
lockvar thread_handles_lock ThreadHandlesLock MkLock
|
||||
#endif
|
||||
|
||||
// Ricardo's stuff
|
||||
#if defined(YAPOR) || defined(TABLING)
|
||||
struct global_data global GLOBAL void
|
||||
struct local_data remote[MAX_WORKERS] REMOTE void
|
||||
#endif
|
||||
|
||||
END_WORKER_SHARED
|
||||
|
@ -25,28 +25,6 @@
|
||||
// Restore... sets up call to RestoreFunc
|
||||
//
|
||||
|
||||
/* multi-thread/ORP support */
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
/* number of threads and processes in system */
|
||||
UInt n_of_threads NOfThreads =1 void
|
||||
/* number of threads created since start */
|
||||
UInt n_of_threads_created NOfThreadsCreated =1 void
|
||||
/* total run time for dead threads */
|
||||
UInt threads_total_time ThreadsTotalTime =0L void
|
||||
/* protect long critical regions */
|
||||
lockvar bgl BGL MkLock
|
||||
/* worker local data */
|
||||
worker_local wl[MAX_AGENTS] WorkerLocal void void
|
||||
#ifndef WL
|
||||
#define WL wl[worker_id]
|
||||
#endif
|
||||
#else
|
||||
worker_local wl WorkerLocak void void
|
||||
#ifndef WL
|
||||
#define WL wl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* memory management */
|
||||
UInt hole_size Yap_HoleSize void void
|
||||
struct malloc_state *av_ Yap_av void void
|
||||
@ -305,17 +283,6 @@ int num_of_atts NUM_OF_ATTS =1 void
|
||||
UInt atts_size Yap_AttsSize void void
|
||||
#endif
|
||||
|
||||
/* stack overflow expansion/gc control */
|
||||
int allow_local_expansion Yap_AllowLocalExpansion =TRUE void
|
||||
int allow_global_expansion Yap_AllowGlobalExpansion =TRUE void
|
||||
int allow_trail_expansion Yap_AllowTrailExpansion =TRUE void
|
||||
UInt size_of_overflow SizeOfOverflow =0 void
|
||||
/* amount of space recovered in all garbage collections */
|
||||
UInt agc_last_call AGcLastCall =0 void
|
||||
/* amount of space recovered in all garbage collections */
|
||||
UInt agc_threshold AGcThreshold =10000 void
|
||||
Agc_hook agc_hook AGCHook =NULL void
|
||||
|
||||
/* YAP control flags */
|
||||
Int yap_flags_field[NUMBER_OF_YAP_FLAGS] yap_flags InitFlags() void
|
||||
|
||||
@ -336,12 +303,6 @@ struct AliasDescS *file_aliases FileAliases =NULL RestoreAliases()
|
||||
Atom atprompt AtPrompt =AtomNil AtomAdjust
|
||||
char prompt[MAX_PROMPT] Prompt void void
|
||||
|
||||
/* readline */
|
||||
#if HAVE_LIBREADLINE
|
||||
char *readline_buf ReadlineBuf =NULL void
|
||||
char *readline_pos ReadlinePos =0L void
|
||||
#endif
|
||||
|
||||
/* ISO char conversion: I will make no comments */
|
||||
char *char_conversion_table CharConversionTable =NULL CodeCharPAdjust
|
||||
char *char_conversion_table2 CharConversionTable2 =NULL CodeCharPAdjust
|
||||
@ -376,8 +337,3 @@ ADDR foreign_code_base ForeignCodeBase =NULL void
|
||||
ADDR foreign_code_top ForeignCodeTop =NULL void
|
||||
ADDR foreign_code_max ForeignCodeMax =NULL void
|
||||
|
||||
/* Threads Array */
|
||||
#ifdef THREADS
|
||||
lockvar thread_handles_lock ThreadHandlesLock MkLock
|
||||
struct thandle thread_handle[MAX_THREADS] ThreadHandle InitThreadHandles() void
|
||||
#endif
|
||||
|
150
misc/buildheap
150
misc/buildheap
@ -10,6 +10,8 @@
|
||||
|
||||
:- initialization(main).
|
||||
|
||||
:- dynamic globals/1.
|
||||
|
||||
:- yap_flag(write_strings,on).
|
||||
|
||||
:- style_check(all).
|
||||
@ -18,7 +20,12 @@ main :-
|
||||
file_filter('misc/HEAPFIELDS','H/hstruct.h',gen_struct),
|
||||
file_filter('misc/HEAPFIELDS','H/dhstruct.h',gen_dstruct),
|
||||
file_filter('misc/HEAPFIELDS','H/rhstruct.h',gen_hstruct),
|
||||
file_filter('misc/HEAPFIELDS','H/ihstruct.h',gen_init).
|
||||
file_filter('misc/HEAPFIELDS','H/ihstruct.h',gen_init),
|
||||
file_filter('misc/GLOBALS','H/hglobals.h',gen_struct),
|
||||
file_filter('misc/GLOBALS','H/dglobals.h',gen_dstruct),
|
||||
file_filter('misc/GLOBALS','H/rglobals.h',gen_hstruct),
|
||||
file_filter('misc/GLOBALS','H/iglobals.h',gen_init).
|
||||
|
||||
|
||||
|
||||
/* define the field */
|
||||
@ -28,12 +35,29 @@ gen_struct(Inp,"") :-
|
||||
Inp = [0'/,0'*|_], !.
|
||||
gen_struct(Inp, Out) :-
|
||||
Inp = [0'#|_], !, Out = Inp. % '
|
||||
gen_struct(Inp,"") :-
|
||||
Inp = [0'.|_], !. %'
|
||||
gen_struct(Inp,Out) :-
|
||||
Inp = "START_WORKER_LOCAL", !,
|
||||
Out = "typedef struct worker_local {".
|
||||
gen_struct(Inp,Out) :-
|
||||
Inp = "END_WORKER_LOCAL", !,
|
||||
Out = "} w_local;".
|
||||
gen_struct(Inp,Out) :-
|
||||
Inp = "START_WORKER_SHARED", !,
|
||||
Out = "typedef struct worker_shared {".
|
||||
gen_struct(Inp,Out) :-
|
||||
Inp = "END_WORKER_SHARED", !,
|
||||
Out = "} w_shared;".
|
||||
gen_struct(Inp,Out) :-
|
||||
Inp = "ATOMS", !,
|
||||
Out = "#include \"tatoms.h\"".
|
||||
gen_struct(Inp,Out) :-
|
||||
split(Inp," ",["struct",Type, Field|_]), !,
|
||||
append([" struct ",Type," ",Field,";"], Out).
|
||||
gen_struct(Inp,Out) :-
|
||||
split(Inp," ",["union",Type, Field|_]), !,
|
||||
append([" union ",Type," ",Field,";"], Out).
|
||||
gen_struct(Inp,"") :-
|
||||
split(Inp," ",["void","void"|_]), !.
|
||||
gen_struct(Inp,Out) :-
|
||||
@ -49,6 +73,18 @@ gen_dstruct(Inp,"") :-
|
||||
Inp = [0'/,0'*|_], !.
|
||||
gen_dstruct(Inp, Out) :-
|
||||
Inp = [0'#|_], !, Out = Inp. % '
|
||||
gen_dstruct(Inp,"") :-
|
||||
Inp = "START_WORKER_LOCAL", !,
|
||||
assert(globals(worker)).
|
||||
gen_dstruct(Inp,"") :-
|
||||
Inp = "END_WORKER_LOCAL", !,
|
||||
retract(globals(worker)).
|
||||
gen_dstruct(Inp,"") :-
|
||||
Inp = "START_WORKER_SHARED", !,
|
||||
assert(globals(all)).
|
||||
gen_dstruct(Inp,"") :-
|
||||
Inp = "END_WORKER_SHARED", !,
|
||||
retract(globals(all)).
|
||||
gen_dstruct(Inp,Out) :-
|
||||
Inp = "ATOMS", !,
|
||||
Out = "".
|
||||
@ -58,14 +94,32 @@ gen_dstruct(Inp,Out) :-
|
||||
split(Inp," ",["struct"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_dstruct(Inp3, Out).
|
||||
gen_dstruct(Inp,Out) :-
|
||||
split(Inp," ",["union"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_dstruct(Inp3, Out).
|
||||
gen_dstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, Name|_]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append(["#define ",Name," Yap_heap_regs->",RField], Out).
|
||||
fetch_name(Global),
|
||||
append(["#define ",Name," ",Global,RField], Out).
|
||||
gen_dstruct(Inp,_) :-
|
||||
split(Inp," ",[_, _, _| _]),
|
||||
format(user_error,"OOPS: could not gen_dstruct for ~s~n",[Inp]).
|
||||
|
||||
fetch_name(Global) :-
|
||||
globals(all), !,
|
||||
Global = "Yap_global->".
|
||||
fetch_name(Global) :-
|
||||
globals(worker), !,
|
||||
Global = "WL->".
|
||||
fetch_name(Global) :-
|
||||
globals(worker_init), !,
|
||||
Global = "FOREIGN_WL(wid)->".
|
||||
fetch_name(Global) :-
|
||||
Global = "Yap_heap_regs->".
|
||||
|
||||
|
||||
% handle *field[4]
|
||||
cut_c_stuff([0'*|Name], RName) :- !, % 'cut *
|
||||
cut_c_stuff(Name, RName).
|
||||
@ -79,39 +133,67 @@ cut_mat(H.Name, H.RName) :-
|
||||
|
||||
gen_hstruct(Inp,"") :-
|
||||
Inp = [0'/,0'/|_], !.
|
||||
gen_hstruct(Inp,"") :-
|
||||
Inp = [0'.|_], !. %'
|
||||
gen_hstruct(Inp,"") :-
|
||||
Inp = [0'/,0'*|_], !.
|
||||
gen_hstruct(Inp,Out) :-
|
||||
Inp = "ATOMS", !,
|
||||
Out = "#include \"ratoms.h\"".
|
||||
gen_hstruct(Inp,Out) :-
|
||||
Inp = "START_WORKER_LOCAL", !,
|
||||
Out = "static void RestoreWorker(int wid) {",
|
||||
assert(globals(worker_init)).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
Inp = "END_WORKER_LOCAL", !,
|
||||
Out = "}",
|
||||
retract(globals(worker_init)).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
Inp = "START_WORKER_SHARED", !,
|
||||
Out = "static void RestoreGlobal(void) {",
|
||||
assert(globals(all)).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
Inp = "END_WORKER_SHARED", !,
|
||||
Out = "}",
|
||||
retract(globals(all)).
|
||||
gen_hstruct(Inp, Out) :-
|
||||
Inp = [0'#|_], !, Out = Inp. % '
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",["struct"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_hstruct(Inp3,Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",["union"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_hstruct(Inp3,Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkAT", _]), !,
|
||||
append([" Yap_heap_regs->",Field," = AtomTermAdjust(Yap_heap_regs->",Field,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,Field," = AtomTermAdjust(Yap_heap_regs->",Field,");"], Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkPred"| _]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = PtoPredAdjust(Yap_heap_regs->",RField,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = PtoPredAdjust(Yap_heap_regs->",RField,");"], Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkOp", Name]), !,
|
||||
append([" Yap_heap_regs->",Field," = Yap_opcode(",Name,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,Field," = Yap_opcode(",Name,");"], Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkLock"]), !,
|
||||
append([" REINIT_LOCK(Yap_heap_regs->",Field,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" REINIT_LOCK(",Global,Field,");"], Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkRWLock"]), !,
|
||||
append([" REINIT_RWLOCK(Yap_heap_regs->",Field,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" REINIT_RWLOCK(",Global,Field,");"], Out).
|
||||
gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkInstE",OP]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField,"->opc = Yap_opcode(",OP,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField,"->opc = Yap_opcode(",OP,");"], Out).
|
||||
gen_hstruct(Inp,"") :-
|
||||
split(Inp," ",[_, _, _, "void"]), !.
|
||||
split(Inp," ",[_, _, _, _]), !.
|
||||
gen_hstruct(Inp,"") :-
|
||||
split(Inp," ",[_, _, _, _, "void"]), !.
|
||||
gen_hstruct(Inp,Restore) :-
|
||||
@ -122,7 +204,8 @@ gen_hstruct(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, _, Adjust]),
|
||||
append(Adjust,"Adjust",_), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = ",Adjust,"(Yap_heap_regs->",RField,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = ",Adjust,"(",Global,RField,");"], Out).
|
||||
gen_hstruct(Inp,_) :-
|
||||
split(Inp," ",[_, _, _| _]),
|
||||
format(user_error,"OOPS: could not gen_hstruct for ~s~n",[Inp]).
|
||||
@ -136,10 +219,30 @@ gen_init(Inp, Out) :-
|
||||
gen_init(Inp,Out) :-
|
||||
Inp = "ATOMS", !,
|
||||
Out = "#include \"iatoms.h\"".
|
||||
gen_init(Inp,Out) :-
|
||||
Inp = "START_WORKER_LOCAL", !,
|
||||
Out = "static void InitWorker(int wid) {",
|
||||
assert(globals(worker_init)).
|
||||
gen_init(Inp,Out) :-
|
||||
Inp = "END_WORKER_LOCAL", !,
|
||||
Out = "}",
|
||||
retract(globals(worker_init)).
|
||||
gen_init(Inp,Out) :-
|
||||
Inp = "START_WORKER_SHARED", !,
|
||||
Out = "static void InitGlobal(void) {",
|
||||
assert(globals(all)).
|
||||
gen_init(Inp,Out) :-
|
||||
Inp = "END_WORKER_SHARED", !,
|
||||
Out = "}",
|
||||
retract(globals(all)).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",["struct"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_init(Inp3, Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",["union"|Inp2]), !,
|
||||
glue(Inp2, " ", Inp3),
|
||||
gen_init(Inp3, Out).
|
||||
gen_init(Inp,"") :-
|
||||
split(Inp," ",[_, _, _, "void"|_]), !.
|
||||
gen_init(Inp,Init) :-
|
||||
@ -153,37 +256,46 @@ gen_init(Inp,Init) :-
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkAT", AtomName]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = MkAtomTerm(",AtomName,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = MkAtomTerm(",AtomName,");"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkOp", Name]), !,
|
||||
append([" Yap_heap_regs->",Field," = Yap_opcode(",Name,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,Field," = Yap_opcode(",Name,");"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkLock"]), !,
|
||||
append([" INIT_LOCK(Yap_heap_regs->",Field,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" INIT_LOCK(",Global,Field,");"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkRWLock"]), !,
|
||||
append([" INIT_RWLOCK(Yap_heap_regs->",Field,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" INIT_RWLOCK(",Global,Field,");"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkInstE",OP]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField,"->opc = Yap_opcode(",OP,");"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField,"->opc = Yap_opcode(",OP,");"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkPred", Atom, "0", Module]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = RepPredProp(PredPropByAtom(",Atom,",",Module,"));"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = RepPredProp(PredPropByAtom(",Atom,",",Module,"));"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkPred", Atom, Arity, Module]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = RepPredProp(PredPropByFunc(Yap_MkFunctor(",Atom,",",Arity,"),",Module,"));"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = RepPredProp(PredPropByFunc(Yap_MkFunctor(",Atom,",",Arity,"),",Module,"));"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, "MkPred", Fun, Module]), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = RepPredProp(PredPropByFunc(",Fun,",",Module,"));"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = RepPredProp(PredPropByFunc(",Fun,",",Module,"));"], Out).
|
||||
gen_init(Inp,Out) :-
|
||||
split(Inp," ",[_, Field, _, F0|_]),
|
||||
append("=",F,F0), !,
|
||||
cut_c_stuff(Field, RField),
|
||||
append([" Yap_heap_regs->",RField," = ",F,";"], Out).
|
||||
fetch_name(Global),
|
||||
append([" ",Global,RField," = ",F,";"], Out).
|
||||
gen_init(Inp,_) :-
|
||||
split(Inp," ",[_, _, _| _]),
|
||||
format(user_error,"OOPS: could not gen_init for ~s~n",[Inp]).
|
||||
|
Reference in New Issue
Block a user