mostly reindenting.

This commit is contained in:
Vítor Santos Costa 2016-01-03 01:34:09 +00:00
parent 811808fc34
commit 5ca49ae202

350
C/init.c
View File

@ -23,6 +23,8 @@ static char SccsId[] = "%W% %G%";
*
*/
#define __INIT_C__ 1
#include <stdlib.h>
#include "Yap.h"
#include "clause.h"
@ -74,15 +76,13 @@ static void InitVersion(void);
void exit(int);
static void InitWorker(int wid);
/************** YAP PROLOG GLOBAL VARIABLES *************************/
/************* variables related to memory allocation ***************/
ADDR Yap_HeapBase;
/************** declarations local to init.c ************************/
static char *optypes[] =
{"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
static char *optypes[] = {"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
/* OS page size for memory allocation */
size_t Yap_page_size;
@ -93,7 +93,6 @@ int Yap_Portray_delays = FALSE;
#endif
#endif
/**
@defgroup Operators Summary of YAP Predefined Operators
@ -188,9 +187,7 @@ The following is the list of the declarations of the predefined operators:
#define fx 6
#define fy 7
int
Yap_IsOpType(char *type)
{
int Yap_IsOpType(char *type) {
int i;
for (i = 1; i <= 7; ++i)
@ -199,9 +196,7 @@ Yap_IsOpType(char *type)
return (i <= 7);
}
static int
OpDec(int p, const char *type, Atom a, Term m)
{
static int OpDec(int p, const char *type, Atom a, Term m) {
int i;
AtomEntry *ae = RepAtom(a);
OpEntry *info;
@ -214,7 +209,8 @@ OpDec(int p, const char *type, Atom a, Term m)
if (strcmp(type, optypes[i]) == 0)
break;
if (i > 7) {
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,MkAtomTerm(Yap_LookupAtom(type)),"op/3");
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER, MkAtomTerm(Yap_LookupAtom(type)),
"op/3");
return (FALSE);
}
if (p) {
@ -269,15 +265,11 @@ OpDec(int p, const char *type, Atom a, Term m)
return (TRUE);
}
int
Yap_OpDec(int p, char *type, Atom a, Term m)
{
int Yap_OpDec(int p, char *type, Atom a, Term m) {
return (OpDec(p, type, a, m));
}
static void
SetOp(int p, int type, char *at, Term m)
{
static void SetOp(int p, int type, char *at, Term m) {
#if DEBUG
if (GLOBAL_Option[5])
fprintf(stderr, "[setop %d %s %s]\n", p, optypes[type], at);
@ -286,9 +278,7 @@ SetOp(int p, int type, char *at, Term m)
}
/* Gets the info about an operator in a prop */
Atom
Yap_GetOp(OpEntry *pp, int *prio, int fix)
{
Atom Yap_GetOp(OpEntry *pp, int *prio, int fix) {
int n;
SMALLUNSGN p;
@ -323,8 +313,7 @@ typedef struct OPSTRUCT {
short int opType, opPrio;
} Opdef;
static Opdef Ops[] = {
{":-", xfx, 1200},
static Opdef Ops[] = {{":-", xfx, 1200},
{"-->", xfx, 1200},
{"?-", fx, 1200},
{":-", fx, 1200},
@ -397,12 +386,9 @@ static Opdef Ops[] = {
{"\\", fy, 200},
{"//", yfx, 400},
{"**", xfx, 200},
{"^", xfy, 200}
};
{"^", xfy, 200}};
static void
InitOps(void)
{
static void InitOps(void) {
unsigned int i;
for (i = 0; i < sizeof(Ops) / sizeof(*Ops); ++i)
SetOp(Ops[i].opPrio, Ops[i].opType, Ops[i].opName, PROLOG_MODULE);
@ -416,9 +402,7 @@ InitOps(void)
#endif
#endif
static void
InitDebug(void)
{
static void InitDebug(void) {
Atom At;
#if DEBUG
int i;
@ -462,9 +446,7 @@ InitDebug(void)
Yap_PutValue(At, MkIntTerm(15));
}
static UInt
update_flags_from_prolog(UInt flags, PredEntry *pe)
{
static UInt update_flags_from_prolog(UInt flags, PredEntry *pe) {
if (pe->PredFlags & MetaPredFlag)
flags |= MetaPredFlag;
if (pe->PredFlags & SourcePredFlag)
@ -480,9 +462,8 @@ update_flags_from_prolog(UInt flags, PredEntry *pe)
return flags;
}
void
Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
{
void Yap_InitCPred(const char *Name, UInt Arity, CPredicate code,
pred_flags_t flags) {
CACHE_REGS
Atom atom = NIL;
PredEntry *pe = NULL;
@ -536,7 +517,8 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
if (flags & SafePredFlag) {
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(p_code, Osbpp), p), l);
} else {
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code,e),p),Osbpp),p),l);
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code, e), p), Osbpp), p),
l);
}
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
if (!cl) {
@ -567,9 +549,7 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
p_code->opc = Yap_opcode(_call_cpred);
p_code->y_u.Osbpp.bmap = NULL;
p_code->y_u.Osbpp.s = -Signed(RealEnvSize);
p_code->y_u.Osbpp.p =
p_code->y_u.Osbpp.p0 =
pe;
p_code->y_u.Osbpp.p = p_code->y_u.Osbpp.p0 = pe;
p_code = NEXTOP(p_code, Osbpp);
if (!(flags & SafePredFlag)) {
p_code->opc = Yap_opcode(_deallocate);
@ -584,9 +564,7 @@ Yap_InitCPred(const char *Name, UInt Arity, CPredicate code, pred_flags_t flags)
pe->OpcodeOfPred = pe->CodeOfPred->opc;
}
bool
Yap_AddCallToFli( PredEntry *pe, CPredicate call )
{
bool Yap_AddCallToFli(PredEntry *pe, CPredicate call) {
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
@ -601,9 +579,7 @@ Yap_AddCallToFli( PredEntry *pe, CPredicate call )
}
}
bool
Yap_AddRetryToFli( PredEntry *pe, CPredicate re )
{
bool Yap_AddRetryToFli(PredEntry *pe, CPredicate re) {
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
@ -616,9 +592,7 @@ Yap_AddRetryToFli( PredEntry *pe, CPredicate re )
}
}
bool
Yap_AddCutToFli( PredEntry *pe, CPredicate CUT )
{
bool Yap_AddCutToFli(PredEntry *pe, CPredicate CUT) {
yamop *p_code;
if (pe->PredFlags & BackCPredFlag) {
@ -632,9 +606,8 @@ Yap_AddCutToFli( PredEntry *pe, CPredicate CUT )
}
}
void
Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_t flags)
{
void Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code,
pred_flags_t flags) {
CACHE_REGS
Atom atom = NIL;
PredEntry *pe = NULL;
@ -674,11 +647,13 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
/* already exists */
} else {
while (!cl) {
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),plxxs),p),l);
UInt sz = sizeof(StaticClause) +
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL), plxxs), p), l);
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
if (!cl) {
if (!Yap_growheap(FALSE, sz, NULL)) {
Yap_Error(RESOURCE_ERROR_HEAP,TermNil,"while initializing %s", Name);
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "while initializing %s",
Name);
return;
}
} else {
@ -710,9 +685,8 @@ Yap_InitCmpPred(const char *Name, UInt Arity, CmpPredicate cmp_code, pred_flags_
p_code->y_u.l.l = cl->ClCode;
}
void
Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_flags_t flags)
{
void Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def,
pred_flags_t flags) {
CACHE_REGS
Atom atom = NIL;
PredEntry *pe = NULL;
@ -758,15 +732,19 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
if (pe->CodeOfPred == (yamop *)(&(pe->OpcodeOfPred))) {
if (flags & SafePredFlag) {
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l));
cl = (StaticClause *)Yap_AllocCodeSpace(
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), p), l));
} else {
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),p),l));
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(
NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), e), Osbpp), p), p),
l));
}
if (!cl) {
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "No Heap Space in InitAsmPred");
return;
}
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l);
Yap_ClauseSpace +=
(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), p), l);
} else {
cl = ClauseCodeToStaticClause(pe->CodeOfPred);
}
@ -775,7 +753,8 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
if (flags & SafePredFlag) {
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), Osbpp), e), e);
} else {
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),e),e);
cl->ClSize = (CELL)NEXTOP(
NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code), e), Osbpp), p), e), e);
}
cl->usc.ClLine = Yap_source_line_no();
p_code = cl->ClCode;
@ -806,10 +785,8 @@ Yap_InitAsmPred(const char *Name, UInt Arity, int code, CPredicate def, pred_fl
}
}
static void
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
{
static void CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont,
CPredicate Cut) {
yamop *code;
if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause ||
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause ||
@ -848,25 +825,20 @@ CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
code->y_u.OtapFs.f = Cut;
}
void
Yap_InitCPredBack(const char *Name, UInt Arity,
unsigned int Extra, CPredicate Start,
CPredicate Cont, pred_flags_t flags){
void Yap_InitCPredBack(const char *Name, UInt Arity, unsigned int Extra,
CPredicate Start, CPredicate Cont, pred_flags_t flags) {
Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, NULL, flags);
}
void
Yap_InitCPredBackCut(const char *Name, UInt Arity,
unsigned int Extra, CPredicate Start,
CPredicate Cont,CPredicate Cut, pred_flags_t flags){
void Yap_InitCPredBackCut(const char *Name, UInt Arity, unsigned int Extra,
CPredicate Start, CPredicate Cont, CPredicate Cut,
pred_flags_t flags) {
Yap_InitCPredBack_(Name, Arity, Extra, Start, Cont, Cut, flags);
}
void
Yap_InitCPredBack_(const char *Name, UInt Arity,
unsigned int Extra, CPredicate Start,
CPredicate Cont, CPredicate Cut, pred_flags_t flags)
{
void Yap_InitCPredBack_(const char *Name, UInt Arity, unsigned int Extra,
CPredicate Start, CPredicate Cont, CPredicate Cut,
pred_flags_t flags) {
CACHE_REGS
PredEntry *pe = NULL;
Atom atom = NIL;
@ -898,15 +870,14 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
return;
}
}
if (pe->cs.p_code.FirstClause != NIL)
{
if (pe->cs.p_code.FirstClause != NIL) {
flags = update_flags_from_prolog(flags, pe);
CleanBack(pe, Start, Cont, Cut);
}
else {
} else {
StaticClause *cl;
yamop *code = ((StaticClause *)NULL)->ClCode;
UInt sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l);
UInt sz =
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code, OtapFs), OtapFs), OtapFs), l);
if (flags & UserCPredFlag)
pe->PredFlags = UserCPredFlag | BackCPredFlag | CompiledPredFlag | flags;
else
@ -930,8 +901,8 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
cl->usc.ClLine = Yap_source_line_no();
code = cl->ClCode;
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred =
pe->cs.p_code.FirstClause = pe->cs.p_code.LastClause = code;
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = pe->cs.p_code.FirstClause =
pe->cs.p_code.LastClause = code;
if (flags & UserCPredFlag)
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_userc);
else
@ -972,10 +943,7 @@ Yap_InitCPredBack_(const char *Name, UInt Arity,
}
}
static void
InitStdPreds(void)
{
static void InitStdPreds(void) {
Yap_InitCPreds();
Yap_InitBackCPreds();
BACKUP_MACHINE_REGS();
@ -986,16 +954,15 @@ InitStdPreds(void)
#endif
}
static void
InitPredHash(void)
{
static void InitPredHash(void) {
UInt i;
PredHash = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry **) * PredHashInitialSize);
PredHash = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry **) *
PredHashInitialSize);
PredHashTableSize = PredHashInitialSize;
if (PredHash == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL,MkIntTerm(0),"allocating initial predicate hash table");
Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0),
"allocating initial predicate hash table");
}
for (i = 0; i < PredHashTableSize; ++i) {
PredHash[i] = NULL;
@ -1003,9 +970,8 @@ InitPredHash(void)
INIT_RWLOCK(PredHashRWLock);
}
static void
InitEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred)
{
static void InitEnvInst(yamop start[2], yamop **instp, op_numbers opc,
PredEntry *pred) {
yamop *ipc = start;
/* make it look like the instruction is preceeded by a call instruction */
@ -1019,9 +985,7 @@ InitEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred)
*instp = ipc;
}
static void
InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
{
static void InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe) {
yamop *ipc = start;
/* this is a place holder, it should not really be used */
@ -1037,59 +1001,50 @@ InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
#endif /* TABLING */
}
static void
InitDBErasedMarker(void)
{
Yap_heap_regs->db_erased_marker =
(DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
static void InitDBErasedMarker(void) {
DBErasedMarker = (DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
Yap_LUClauseSpace += sizeof(DBStruct);
Yap_heap_regs->db_erased_marker->id = FunctorDBRef;
Yap_heap_regs->db_erased_marker->Flags = ErasedMask;
Yap_heap_regs->db_erased_marker->Code = NULL;
Yap_heap_regs->db_erased_marker->DBT.DBRefs = NULL;
Yap_heap_regs->db_erased_marker->Parent = NULL;
DBErasedMarker->id = FunctorDBRef;
DBErasedMarker->Flags = ErasedMask;
DBErasedMarker->Code = NULL;
DBErasedMarker->DBT.DBRefs = NULL;
DBErasedMarker->Parent = NULL;
}
static void
InitLogDBErasedMarker(void)
{
Yap_heap_regs->logdb_erased_marker =
(LogUpdClause *)Yap_AllocCodeSpace(sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e));
static void InitLogDBErasedMarker(void) {
LogDBErasedMarker = (LogUpdClause *)Yap_AllocCodeSpace(
sizeof(LogUpdClause) + (UInt)NEXTOP((yamop *)NULL, e));
Yap_LUClauseSpace += sizeof(LogUpdClause) + (UInt)NEXTOP((yamop *)NULL, e);
Yap_heap_regs->logdb_erased_marker->Id = FunctorDBRef;
Yap_heap_regs->logdb_erased_marker->ClFlags = ErasedMask|LogUpdMask;
Yap_heap_regs->logdb_erased_marker->lusl.ClSource = NULL;
Yap_heap_regs->logdb_erased_marker->ClRefCount = 0;
Yap_heap_regs->logdb_erased_marker->ClExt = NULL;
Yap_heap_regs->logdb_erased_marker->ClPrev = NULL;
Yap_heap_regs->logdb_erased_marker->ClNext = NULL;
Yap_heap_regs->logdb_erased_marker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode,e);
Yap_heap_regs->logdb_erased_marker->ClCode->opc = Yap_opcode(_op_fail);
LogDBErasedMarker->Id = FunctorDBRef;
LogDBErasedMarker->ClFlags = ErasedMask | LogUpdMask;
LogDBErasedMarker->lusl.ClSource = NULL;
LogDBErasedMarker->ClRefCount = 0;
LogDBErasedMarker->ClExt = NULL;
LogDBErasedMarker->ClPrev = NULL;
LogDBErasedMarker->ClNext = NULL;
LogDBErasedMarker->ClSize =
(UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode, e);
LogDBErasedMarker->ClCode->opc = Yap_opcode(_op_fail);
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
}
static void
InitSWIAtoms(void)
{
static void InitSWIAtoms(void) {
MaxAtomTranslations = N_SWI_ATOMS;
MaxFunctorTranslations = N_SWI_FUNCTORS;
SWI_Atoms = (Atom *)malloc(sizeof(Atom) * MaxAtomTranslations);
SWI_Functors = (Functor *)malloc(sizeof(Functor) * 2 * N_SWI_ATOMS);
}
static void
InitEmptyWakeups(void)
{
}
static void InitEmptyWakeups(void) {}
static void
InitAtoms(void)
{
static void InitAtoms(void) {
int i;
AtomHashTableSize = MaxHash;
HashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
HashChain =
(AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
if (HashChain == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL,MkIntTerm(0),"allocating initial atom table");
Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0),
"allocating initial atom table");
}
for (i = 0; i < MaxHash; ++i) {
INIT_RWLOCK(HashChain[i].AERWLock);
@ -1113,13 +1068,12 @@ InitAtoms(void)
#endif
}
static void
InitWideAtoms(void)
{
static void InitWideAtoms(void) {
int i;
WideAtomHashTableSize = MaxWideHash;
WideHashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash);
WideHashChain =
(AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash);
if (WideHashChain == NULL) {
Yap_Error(SYSTEM_ERROR_FATAL, MkIntTerm(0), "allocating wide atom table");
}
@ -1130,15 +1084,12 @@ InitWideAtoms(void)
NOfWideAtoms = 0;
}
static void
InitInvisibleAtoms(void)
{
static void InitInvisibleAtoms(void) {
/* initialize invisible chain */
Yap_heap_regs->invisiblechain.Entry = NIL;
INIT_RWLOCK(Yap_heap_regs->invisiblechain.AERWLock);
INVISIBLECHAIN.Entry = NIL;
INIT_RWLOCK(Yap_heap_regs->INVISIBLECHAIN.AERWLock);
}
#ifdef YAPOR
void Yap_init_yapor_workers(void) {
CACHE_REGS
@ -1152,9 +1103,11 @@ void Yap_init_yapor_workers(void) {
int son;
son = fork();
if (son == -1)
Yap_Error(SYSTEM_ERROR_FATAL, TermNil, "fork error (Yap_init_yapor_workers)");
Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
"fork error (Yap_init_yapor_workers)");
if (son > 0) {
/* I am the father, I must stay here and wait for my children to all die */
/* I am the father, I must stay here and wait for my children to all die
*/
struct sigaction sigact;
sigact.sa_handler = SIG_DFL;
sigemptyset(&sigact.sa_mask);
@ -1170,7 +1123,8 @@ void Yap_init_yapor_workers(void) {
int son;
son = fork();
if (son == -1)
Yap_Error(SYSTEM_ERROR_FATAL, TermNil, "fork error (Yap_init_yapor_workers)");
Yap_Error(SYSTEM_ERROR_FATAL, TermNil,
"fork error (Yap_init_yapor_workers)");
if (son == 0) {
/* new worker */
worker_id = proc;
@ -1185,11 +1139,8 @@ void Yap_init_yapor_workers(void) {
}
#endif /* YAPOR */
#ifdef THREADS
static void
InitThreadHandle(int wid)
{
static void InitThreadHandle(int wid) {
REMOTE_ThreadHandle(wid).in_use = FALSE;
REMOTE_ThreadHandle(wid).zombie = FALSE;
REMOTE_ThreadHandle(wid).local_preds = NULL;
@ -1217,15 +1168,13 @@ InitThreadHandle(int wid)
mboxp->open = true;
Yap_init_tqueue(msgsp);
}
}
int
Yap_InitThread(int new_id)
{
int Yap_InitThread(int new_id) {
struct worker_local *new_s;
if (new_id) {
if (!(new_s = (struct worker_local *)calloc(sizeof(struct worker_local), 1)))
if (!(new_s =
(struct worker_local *)calloc(sizeof(struct worker_local), 1)))
return FALSE;
Yap_local[new_id] = new_s;
if (!((REGSTORE *)pthread_getspecific(Yap_yaamregs_key))) {
@ -1242,16 +1191,13 @@ Yap_InitThread(int new_id)
}
#endif
static void
InitScratchPad(int wid)
{
static void InitScratchPad(int wid) {
REMOTE_ScratchPad(wid).ptr = NULL;
REMOTE_ScratchPad(wid).sz = SCRATCH_START_SIZE;
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
}
static CELL *
InitHandles(int wid) {
static CELL *InitHandles(int wid) {
size_t initial_slots = 1024;
CELL *handles;
@ -1260,31 +1206,29 @@ InitHandles(int wid) {
handles = calloc(initial_slots, sizeof(CELL));
if (handles == NULL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, 0 /* TermNil */, "No space for handles at " __FILE__ " : %d", __LINE__);
Yap_Error(SYSTEM_ERROR_INTERNAL, 0 /* TermNil */,
"No space for handles at " __FILE__ " : %d", __LINE__);
}
RESET_VARIABLE(handles);
return handles;
}
void
Yap_CloseScratchPad(void)
{
void Yap_CloseScratchPad(void) {
CACHE_REGS
Yap_FreeCodeSpace(LOCAL_ScratchPad.ptr);
LOCAL_ScratchPad.sz = SCRATCH_START_SIZE;
LOCAL_ScratchPad.msz = SCRATCH_START_SIZE;
}
#include "iglobals.h"
#include "ilocals.h"
#include "heap/iglobals.h"
#include "heap/ilocals.h"
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
struct global_data *Yap_global;
long Yap_worker_area_size;
#else
struct global_data Yap_Global;
#endif
#if defined(THREADS)
@ -1295,9 +1239,7 @@ struct worker_local *Yap_local;
struct worker_local Yap_local;
#endif
static void
InitCodes(void)
{
static void InitCodes(void) {
CACHE_REGS
#if THREADS
int wid;
@ -1305,7 +1247,7 @@ InitCodes(void)
Yap_local[wid] = NULL;
}
#endif
#include "ihstruct.h"
#include "heap/ihstruct.h"
#if THREADS
Yap_InitThread(0);
#endif /* THREADS */
@ -1328,30 +1270,27 @@ InitCodes(void)
modp->PredFlags |= MetaPredFlag;
}
#ifdef YAPOR
Yap_heap_regs->getwork_code->y_u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetwork, PROLOG_MODULE));
Yap_heap_regs->getwork_seq_code->y_u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetworkSeq, PROLOG_MODULE));
Yap_heap_regs->getwork_code->y_u.Otapl.p =
RepPredProp(PredPropByAtom(AtomGetwork, PROLOG_MODULE));
Yap_heap_regs->getwork_seq_code->y_u.Otapl.p =
RepPredProp(PredPropByAtom(AtomGetworkSeq, PROLOG_MODULE));
#endif /* YAPOR */
}
static void
InitVersion(void)
{
Yap_PutValue(AtomVersionNumber,
MkAtomTerm(Yap_LookupAtom(YAP_FULL_VERSION)));
static void InitVersion(void) {
Yap_PutValue(AtomVersionNumber, MkAtomTerm(Yap_LookupAtom(YAP_FULL_VERSION)));
}
void
Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_size,
int n_workers, int sch_loop, int delay_load)
{
void Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts,
UInt max_table_size, int n_workers, int sch_loop,
int delay_load) {
CACHE_REGS
/* initialize system stuff */
#if PUSH_REGS
#ifdef THREADS
if (!(Yap_local[0] = (struct worker_local *)calloc(sizeof(struct worker_local), 1)))
if (!(Yap_local[0] =
(struct worker_local *)calloc(sizeof(struct worker_local), 1)))
return;
pthread_key_create(&Yap_yaamregs_key, NULL);
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
@ -1396,13 +1335,17 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
if (n_workers > MAX_WORKERS)
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "excessive number of workers");
#ifdef YAPOR_COPY
INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_COW
INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_SBA
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#elif YAPOR_THREADS
INFORMATION_MESSAGE("YapOr: threads model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
INFORMATION_MESSAGE("YapOr: threads model with %d worker%s", n_workers,
n_workers == 1 ? "" : "s");
#endif /* YAPOR_COPY - YAPOR_COW - YAPOR_SBA - YAPOR_THREADS */
#endif /* YAPOR */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
@ -1437,7 +1380,8 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
if (Stack < MinStackSpace)
Stack = MinStackSpace;
if (!(LOCAL_GlobalBase = (ADDR)malloc((Trail + Stack) * 1024))) {
Yap_Error(RESOURCE_ERROR_HEAP, 0, "could not allocate stack space for main thread");
Yap_Error(RESOURCE_ERROR_HEAP, 0,
"could not allocate stack space for main thread");
Yap_exit(1);
}
#if THREADS
@ -1454,14 +1398,10 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
Yap_InitYaamRegs(0);
InitStdPreds();
/* make sure tmp area is available */
{
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
}
{ Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace()); }
}
int
Yap_HaltRegisterHook (HaltHookFunc f, void * env)
{
int Yap_HaltRegisterHook(HaltHookFunc f, void *env) {
struct halt_hook *h;
if (!(h = (struct halt_hook *)Yap_AllocCodeSpace(sizeof(struct halt_hook))))
@ -1475,9 +1415,7 @@ Yap_HaltRegisterHook (HaltHookFunc f, void * env)
return TRUE;
}
static void
run_halt_hooks(int code)
{
static void run_halt_hooks(int code) {
struct halt_hook *hooke = GLOBAL_HaltHooks;
while (hooke) {
@ -1486,9 +1424,7 @@ run_halt_hooks(int code)
}
}
void
Yap_exit (int value)
{
void Yap_exit(int value) {
CACHE_REGS
void closeFiles(int all);
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)