remove FOREIGN_ macros and use REMOTE_ instead

This commit is contained in:
Ricardo Rocha 2011-05-09 20:19:49 +01:00
parent f22994edf9
commit 026616963c
13 changed files with 177 additions and 144 deletions

View File

@ -398,10 +398,10 @@ Yap_InitExStacks(int Trail, int Stack)
void
Yap_KillStacks(int wid)
{
ADDR gb = FOREIGN_ThreadHandle(wid).stack_address;
ADDR gb = REMOTE_ThreadHandle(wid).stack_address;
if (gb) {
free(gb);
FOREIGN_ThreadHandle(wid).stack_address = NULL;
REMOTE_ThreadHandle(wid).stack_address = NULL;
}
}
#else

View File

@ -1608,8 +1608,8 @@ Yap_InitYaamRegs(void)
machine registers */
#ifdef THREADS
int myworker_id = worker_id;
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;
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(myworker_id).default_yaam_regs);
REMOTE_ThreadHandle(myworker_id).current_yaam_regs = REMOTE_ThreadHandle(myworker_id).default_yaam_regs;
worker_id = myworker_id; /* ricroc: for what I understand, this shouldn't be necessary */
#else
Yap_regp = &Yap_standard_regs;

View File

@ -245,11 +245,11 @@ worker_p_binding(int worker_p, CELL *aux_ptr)
{
CACHE_REGS
if (aux_ptr > H) {
CELL reg = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->LCL0_[aux_ptr-LCL0];
CELL reg = REMOTE_ThreadHandle(worker_p).current_yaam_regs->LCL0_[aux_ptr-LCL0];
reg = AdjustGlobTerm(reg PASS_REGS);
return reg;
} else {
CELL reg = FOREIGN_ThreadHandle(worker_p).current_yaam_regs-> H0_[aux_ptr-H0];
CELL reg = REMOTE_ThreadHandle(worker_p).current_yaam_regs-> H0_[aux_ptr-H0];
reg = AdjustGlobTerm(reg PASS_REGS);
return reg;
}
@ -1845,36 +1845,36 @@ Yap_CopyThreadStacks(int worker_q, int worker_p, int incremental)
Int size;
/* make sure both stacks have same size */
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;
Int p_size = REMOTE_ThreadHandle(worker_p).ssize+REMOTE_ThreadHandle(worker_p).tsize;
Int q_size = REMOTE_ThreadHandle(worker_q).ssize+REMOTE_ThreadHandle(worker_q).tsize;
if (p_size != q_size) {
if (!(FOREIGN_ThreadHandle(worker_q).stack_address = realloc(FOREIGN_ThreadHandle(worker_q).stack_address,p_size*K1))) {
if (!(REMOTE_ThreadHandle(worker_q).stack_address = realloc(REMOTE_ThreadHandle(worker_q).stack_address,p_size*K1))) {
exit(1);
}
}
FOREIGN_ThreadHandle(worker_q).ssize = FOREIGN_ThreadHandle(worker_p).ssize;
FOREIGN_ThreadHandle(worker_q).tsize = FOREIGN_ThreadHandle(worker_p).tsize;
REMOTE_ThreadHandle(worker_q).ssize = REMOTE_ThreadHandle(worker_p).ssize;
REMOTE_ThreadHandle(worker_q).tsize = REMOTE_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 = FOREIGN_ThreadHandle(worker_q).stack_address-FOREIGN_ThreadHandle(worker_p).stack_address;
size = REMOTE_ThreadHandle(worker_q).stack_address-REMOTE_ThreadHandle(worker_p).stack_address;
LOCAL_TrDiff = LOCAL_LDiff = LOCAL_GDiff = LOCAL_GDiff0 = LOCAL_DelayDiff = LOCAL_BaseDiff = size;
LOCAL_XDiff = LOCAL_HDiff = 0;
LOCAL_GSplit = NULL;
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_;
H = REMOTE_ThreadHandle(worker_p).current_yaam_regs->H_;
H0 = REMOTE_ThreadHandle(worker_p).current_yaam_regs->H0_;
B = REMOTE_ThreadHandle(worker_p).current_yaam_regs->B_;
ENV = REMOTE_ThreadHandle(worker_p).current_yaam_regs->ENV_;
YENV = REMOTE_ThreadHandle(worker_p).current_yaam_regs->YENV_;
ASP = REMOTE_ThreadHandle(worker_p).current_yaam_regs->ASP_;
TR = REMOTE_ThreadHandle(worker_p).current_yaam_regs->TR_;
if (ASP > CellPtr(B))
ASP = CellPtr(B);
LCL0 = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->LCL0_;
LCL0 = REMOTE_ThreadHandle(worker_p).current_yaam_regs->LCL0_;
#ifdef CUT_C
Yap_REGS.CUT_C_TOP = FOREIGN_ThreadHandle(worker_p).current_yaam_regs->CUT_C_TOP;
Yap_REGS.CUT_C_TOP = REMOTE_ThreadHandle(worker_p).current_yaam_regs->CUT_C_TOP;
#endif
LOCAL_DynamicArrays = NULL;
LOCAL_StaticArrays = NULL;

View File

@ -1219,16 +1219,16 @@ void init_yapor_workers(void) {
static void
InitThreadHandle(int wid)
{
FOREIGN_ThreadHandle(wid).in_use = FALSE;
FOREIGN_ThreadHandle(wid).zombie = FALSE;
FOREIGN_ThreadHandle(wid).local_preds = NULL;
REMOTE_ThreadHandle(wid).in_use = FALSE;
REMOTE_ThreadHandle(wid).zombie = FALSE;
REMOTE_ThreadHandle(wid).local_preds = NULL;
#ifdef LOW_LEVEL_TRACER
FOREIGN_ThreadHandle(wid).thread_inst_count = 0LL;
REMOTE_ThreadHandle(wid).thread_inst_count = 0LL;
#endif
pthread_mutex_init(&(FOREIGN_ThreadHandle(wid).tlock), NULL);
pthread_mutex_init(&(FOREIGN_ThreadHandle(wid).tlock_status), NULL);
FOREIGN_ThreadHandle(wid).tdetach = (CELL)0;
FOREIGN_ThreadHandle(wid).cmod = (CELL)0;
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock), NULL);
pthread_mutex_init(&(REMOTE_ThreadHandle(wid).tlock_status), NULL);
REMOTE_ThreadHandle(wid).tdetach = (CELL)0;
REMOTE_ThreadHandle(wid).cmod = (CELL)0;
}
int
@ -1255,8 +1255,8 @@ InitFirstWorkerThreadHandle(void)
LOCAL_ThreadHandle.default_yaam_regs =
&Yap_standard_regs;
LOCAL_ThreadHandle.pthread_handle = pthread_self();
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock, NULL);
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock_status, NULL);
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
#endif
}
@ -1264,9 +1264,9 @@ InitFirstWorkerThreadHandle(void)
static void
InitScratchPad(int wid)
{
FOREIGN(wid)->scratchpad.ptr = NULL;
FOREIGN(wid)->scratchpad.sz = SCRATCH_START_SIZE;
FOREIGN(wid)->scratchpad.msz = SCRATCH_START_SIZE;
REMOTE_ScratchPad(wid).ptr = NULL;
REMOTE_ScratchPad(wid).sz = SCRATCH_START_SIZE;
REMOTE_ScratchPad(wid).msz = SCRATCH_START_SIZE;
}
void

View File

@ -1,4 +1,3 @@
/*************************************************************************
* *
* YAP Prolog *
@ -54,8 +53,8 @@ allocate_new_tid(void)
LOCK(Yap_ThreadHandlesLock);
while(new_worker_id < MAX_THREADS &&
Yap_local[new_worker_id] &&
(FOREIGN_ThreadHandle(new_worker_id).in_use == TRUE ||
FOREIGN_ThreadHandle(new_worker_id).zombie == TRUE) )
(REMOTE_ThreadHandle(new_worker_id).in_use == TRUE ||
REMOTE_ThreadHandle(new_worker_id).zombie == TRUE) )
new_worker_id++;
if (new_worker_id >= MAX_THREADS) {
new_worker_id = -1;
@ -64,12 +63,12 @@ allocate_new_tid(void)
if (!Yap_InitThread(new_worker_id)) {
return -1;
}
pthread_mutex_lock(&(FOREIGN_ThreadHandle(new_worker_id).tlock));
FOREIGN_ThreadHandle(new_worker_id).in_use = TRUE;
pthread_mutex_lock(&(REMOTE_ThreadHandle(new_worker_id).tlock));
REMOTE_ThreadHandle(new_worker_id).in_use = TRUE;
} else if (new_worker_id < MAX_THREADS) {
DEBUG_TLOCK_ACCESS(new_worker_id, 0);
pthread_mutex_lock(&(FOREIGN_ThreadHandle(new_worker_id).tlock));
FOREIGN_ThreadHandle(new_worker_id).in_use = TRUE;
pthread_mutex_lock(&(REMOTE_ThreadHandle(new_worker_id).tlock));
REMOTE_ThreadHandle(new_worker_id).in_use = TRUE;
} else {
new_worker_id = -1;
}
@ -89,31 +88,31 @@ store_specs(int new_worker_id, UInt ssize, UInt tsize, UInt sysize, Term *tpgoal
tsize = MinTrailSpace;
if (ssize < MinStackSpace)
ssize = MinStackSpace;
FOREIGN_ThreadHandle(new_worker_id).ssize = ssize;
FOREIGN_ThreadHandle(new_worker_id).tsize = tsize;
FOREIGN_ThreadHandle(new_worker_id).sysize = sysize;
FOREIGN(new_worker_id)->c_input_stream = LOCAL_c_input_stream;
FOREIGN(new_worker_id)->c_output_stream = LOCAL_c_output_stream;
FOREIGN(new_worker_id)->c_error_stream = LOCAL_c_error_stream;
REMOTE_ThreadHandle(new_worker_id).ssize = ssize;
REMOTE_ThreadHandle(new_worker_id).tsize = tsize;
REMOTE_ThreadHandle(new_worker_id).sysize = sysize;
REMOTE_c_input_stream(new_worker_id) = LOCAL_c_input_stream;
REMOTE_c_output_stream(new_worker_id) = LOCAL_c_output_stream;
REMOTE_c_error_stream(new_worker_id) = LOCAL_c_error_stream;
pm = (ssize + tsize)*1024;
if (!(FOREIGN_ThreadHandle(new_worker_id).stack_address = malloc(pm))) {
if (!(REMOTE_ThreadHandle(new_worker_id).stack_address = malloc(pm))) {
return FALSE;
}
FOREIGN_ThreadHandle(new_worker_id).tgoal =
REMOTE_ThreadHandle(new_worker_id).tgoal =
Yap_StoreTermInDB(Deref(*tpgoal),7);
FOREIGN_ThreadHandle(new_worker_id).cmod =
REMOTE_ThreadHandle(new_worker_id).cmod =
CurrentModule;
tdetach = Deref(*tpdetach);
if (IsVarTerm(tdetach)){
FOREIGN_ThreadHandle(new_worker_id).tdetach =
REMOTE_ThreadHandle(new_worker_id).tdetach =
MkAtomTerm(AtomFalse);
} else {
FOREIGN_ThreadHandle(new_worker_id).tdetach =
REMOTE_ThreadHandle(new_worker_id).tdetach =
tdetach;
}
tgoal = Yap_StripModule(Deref(*tpexit), &tmod);
FOREIGN_ThreadHandle(new_worker_id).texit_mod = tmod;
FOREIGN_ThreadHandle(new_worker_id).texit =
REMOTE_ThreadHandle(new_worker_id).texit_mod = tmod;
REMOTE_ThreadHandle(new_worker_id).texit =
Yap_StoreTermInDB(tgoal,7);
return TRUE;
}
@ -123,10 +122,10 @@ static void
kill_thread_engine (int wid, int always_die)
{
CACHE_REGS
Prop p0 = AbsPredProp(FOREIGN_ThreadHandle(wid).local_preds);
Prop p0 = AbsPredProp(REMOTE_ThreadHandle(wid).local_preds);
GlobalEntry *gl = LOCAL_GlobalVariables;
FOREIGN_ThreadHandle(wid).local_preds = NIL;
REMOTE_ThreadHandle(wid).local_preds = NIL;
LOCAL_GlobalVariables = NULL;
/* kill all thread local preds */
while(p0) {
@ -140,20 +139,20 @@ kill_thread_engine (int wid, int always_die)
gl = gl->NextGE;
}
Yap_KillStacks(wid);
FOREIGN(wid)->active_signals = 0L;
free(FOREIGN(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);
REMOTE_ActiveSignals(wid) = 0L;
free(REMOTE_ScratchPad(wid).ptr);
free(REMOTE_ThreadHandle(wid).default_yaam_regs);
REMOTE_ThreadHandle(wid).current_yaam_regs = NULL;
free(REMOTE_ThreadHandle(wid).start_of_timesp);
free(REMOTE_ThreadHandle(wid).last_timep);
Yap_FreeCodeSpace((ADDR)REMOTE_ThreadHandle(wid).texit);
LOCK(Yap_ThreadHandlesLock);
if (FOREIGN_ThreadHandle(wid).tdetach == MkAtomTerm(AtomTrue) ||
if (REMOTE_ThreadHandle(wid).tdetach == MkAtomTerm(AtomTrue) ||
always_die) {
FOREIGN_ThreadHandle(wid).zombie = FALSE;
FOREIGN_ThreadHandle(wid).in_use = FALSE;
REMOTE_ThreadHandle(wid).zombie = FALSE;
REMOTE_ThreadHandle(wid).in_use = FALSE;
DEBUG_TLOCK_ACCESS(1, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
}
UNLOCK(Yap_ThreadHandlesLock);
}
@ -177,21 +176,21 @@ setup_engine(int myworker_id, int init_thread)
standard_regs = (REGSTORE *)calloc(1,sizeof(REGSTORE));
regcache = standard_regs;
/* create the YAAM descriptor */
FOREIGN_ThreadHandle(myworker_id).default_yaam_regs = standard_regs;
REMOTE_ThreadHandle(myworker_id).default_yaam_regs = standard_regs;
if (init_thread) {
pthread_setspecific(Yap_yaamregs_key, (void *)FOREIGN_ThreadHandle(myworker_id).default_yaam_regs);
pthread_setspecific(Yap_yaamregs_key, (void *)REMOTE_ThreadHandle(myworker_id).default_yaam_regs);
}
worker_id = myworker_id;
LOCAL = REMOTE(worker_id);
Yap_InitExStacks(FOREIGN_ThreadHandle(myworker_id).tsize, FOREIGN_ThreadHandle(myworker_id).ssize);
CurrentModule = FOREIGN_ThreadHandle(myworker_id).cmod;
Yap_InitExStacks(REMOTE_ThreadHandle(myworker_id).tsize, REMOTE_ThreadHandle(myworker_id).ssize);
CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
Yap_InitTime();
Yap_InitYaamRegs();
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
/* I exist */
Yap_NOfThreadsCreated++;
DEBUG_TLOCK_ACCESS(2, myworker_id);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(myworker_id).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(myworker_id).tlock));
}
static void
@ -230,7 +229,7 @@ thread_run(void *widp)
}
}
} while (t == 0);
FOREIGN_ThreadHandle(myworker_id).tgoal = NULL;
REMOTE_ThreadHandle(myworker_id).tgoal = NULL;
tgs[1] = LOCAL_ThreadHandle.tdetach;
tgoal = Yap_MkApplTerm(FunctorThreadRun, 2, tgs);
Yap_RunTopGoal(tgoal);
@ -282,10 +281,10 @@ p_create_thread( USES_REGS1 )
/* make sure we can proceed */
if (!init_thread_engine(new_worker_id, ssize, tsize, sysize, &ARG1, &ARG5, &ARG6))
return FALSE;
FOREIGN_ThreadHandle(new_worker_id).pthread_handle = 0L;
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) {
REMOTE_ThreadHandle(new_worker_id).pthread_handle = 0L;
REMOTE_ThreadHandle(new_worker_id).id = new_worker_id;
REMOTE_ThreadHandle(new_worker_id).ref_count = 1;
if ((REMOTE_ThreadHandle(new_worker_id).ret = pthread_create(&REMOTE_ThreadHandle(new_worker_id).pthread_handle, NULL, thread_run, (void *)(&(REMOTE_ThreadHandle(new_worker_id).id)))) == 0) {
/* wait until the client is initialised */
return TRUE;
}
@ -409,17 +408,17 @@ Yap_thread_create_engine(thread_attr *ops)
if (pthread_self() != Yap_master_thread) {
/* we are worker_id 0 for now, lock master thread so that no one messes with us */
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
pthread_mutex_lock(&(FOREIGN_ThreadHandle(0).tlock));
pthread_mutex_lock(&(REMOTE_ThreadHandle(0).tlock));
}
if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
return -1;
FOREIGN_ThreadHandle(new_id).pthread_handle = 0L;
FOREIGN_ThreadHandle(new_id).id = new_id;
FOREIGN_ThreadHandle(new_id).ref_count = 0;
REMOTE_ThreadHandle(new_id).pthread_handle = 0L;
REMOTE_ThreadHandle(new_id).id = new_id;
REMOTE_ThreadHandle(new_id).ref_count = 0;
setup_engine(new_id, FALSE);
if (pthread_self() != Yap_master_thread) {
pthread_setspecific(Yap_yaamregs_key, NULL);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(0).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(0).tlock));
}
return new_id;
}
@ -430,21 +429,21 @@ Yap_thread_attach_engine(int wid)
CACHE_REGS
/*
already locked
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
*/
if (FOREIGN_ThreadHandle(wid).ref_count ) {
if (REMOTE_ThreadHandle(wid).ref_count ) {
DEBUG_TLOCK_ACCESS(8, wid);
FOREIGN_ThreadHandle(wid).ref_count++;
FOREIGN_ThreadHandle(wid).pthread_handle = pthread_self();
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
REMOTE_ThreadHandle(wid).ref_count++;
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}
FOREIGN_ThreadHandle(wid).pthread_handle = pthread_self();
FOREIGN_ThreadHandle(wid).ref_count++;
pthread_setspecific(Yap_yaamregs_key, (const void *)FOREIGN_ThreadHandle(wid).default_yaam_regs);
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
REMOTE_ThreadHandle(wid).ref_count++;
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(wid).default_yaam_regs);
worker_id = wid; /* ricroc: for what I understand, this shouldn't be necessary */
DEBUG_TLOCK_ACCESS(9, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}
@ -452,12 +451,12 @@ Int
Yap_thread_detach_engine(int wid)
{
DEBUG_TLOCK_ACCESS(10, wid);
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
FOREIGN_ThreadHandle(wid).pthread_handle = 0;
FOREIGN_ThreadHandle(wid).ref_count--;
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
REMOTE_ThreadHandle(wid).pthread_handle = 0;
REMOTE_ThreadHandle(wid).ref_count--;
pthread_setspecific(Yap_yaamregs_key, NULL);
DEBUG_TLOCK_ACCESS(11, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}
@ -465,13 +464,13 @@ Int
Yap_thread_destroy_engine(int wid)
{
DEBUG_TLOCK_ACCESS(10, wid);
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
if (FOREIGN_ThreadHandle(wid).ref_count == 0) {
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
if (REMOTE_ThreadHandle(wid).ref_count == 0) {
kill_thread_engine(wid, TRUE);
return TRUE;
} else {
DEBUG_TLOCK_ACCESS(12, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return FALSE;
}
}
@ -483,18 +482,18 @@ p_thread_join( USES_REGS1 )
Int tid = IntegerOfTerm(Deref(ARG1));
LOCK(Yap_ThreadHandlesLock);
if (!FOREIGN_ThreadHandle(tid).in_use &&
!FOREIGN_ThreadHandle(tid).zombie) {
if (!REMOTE_ThreadHandle(tid).in_use &&
!REMOTE_ThreadHandle(tid).zombie) {
UNLOCK(Yap_ThreadHandlesLock);
return FALSE;
}
if (!FOREIGN_ThreadHandle(tid).tdetach == MkAtomTerm(AtomTrue)) {
if (!REMOTE_ThreadHandle(tid).tdetach == MkAtomTerm(AtomTrue)) {
UNLOCK(Yap_ThreadHandlesLock);
return FALSE;
}
UNLOCK(Yap_ThreadHandlesLock);
/* make sure this lock is accessible */
if (pthread_join(FOREIGN_ThreadHandle(tid).pthread_handle, NULL) < 0) {
if (pthread_join(REMOTE_ThreadHandle(tid).pthread_handle, NULL) < 0) {
/* ERROR */
return FALSE;
}
@ -508,10 +507,10 @@ p_thread_destroy( USES_REGS1 )
Int tid = IntegerOfTerm(Deref(ARG1));
LOCK(Yap_ThreadHandlesLock);
FOREIGN_ThreadHandle(tid).zombie = FALSE;
FOREIGN_ThreadHandle(tid).in_use = FALSE;
REMOTE_ThreadHandle(tid).zombie = FALSE;
REMOTE_ThreadHandle(tid).in_use = FALSE;
DEBUG_TLOCK_ACCESS(32, tid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(tid).tlock));
UNLOCK(Yap_ThreadHandlesLock);
return TRUE;
}
@ -520,18 +519,18 @@ static Int
p_thread_detach( USES_REGS1 )
{
Int tid = IntegerOfTerm(Deref(ARG1));
pthread_mutex_lock(&(FOREIGN_ThreadHandle(tid).tlock));
pthread_mutex_lock(&(REMOTE_ThreadHandle(tid).tlock));
DEBUG_TLOCK_ACCESS(14, tid);
if (pthread_detach(FOREIGN_ThreadHandle(tid).pthread_handle) < 0) {
if (pthread_detach(REMOTE_ThreadHandle(tid).pthread_handle) < 0) {
/* ERROR */
DEBUG_TLOCK_ACCESS(15, tid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(tid).tlock));
return FALSE;
}
FOREIGN_ThreadHandle(tid).tdetach =
REMOTE_ThreadHandle(tid).tdetach =
MkAtomTerm(AtomTrue);
DEBUG_TLOCK_ACCESS(30, tid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(tid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(tid).tlock));
return TRUE;
}
@ -548,8 +547,8 @@ static Int
p_thread_detached2( USES_REGS1 )
{
Int tid = IntegerOfTerm(Deref(ARG1));
if (FOREIGN_ThreadHandle(tid).tdetach)
return Yap_unify(ARG2,FOREIGN_ThreadHandle(tid).tdetach);
if (REMOTE_ThreadHandle(tid).tdetach)
return Yap_unify(ARG2,REMOTE_ThreadHandle(tid).tdetach);
else
return FALSE;
}
@ -597,7 +596,7 @@ static Int
p_valid_thread( USES_REGS1 )
{
Int i = IntegerOfTerm(Deref(ARG1));
return FOREIGN_ThreadHandle(i).in_use || FOREIGN_ThreadHandle(i).zombie;
return REMOTE_ThreadHandle(i).in_use || REMOTE_ThreadHandle(i).zombie;
}
/* Mutex Support */
@ -749,14 +748,14 @@ p_thread_stacks( USES_REGS1 )
Int status= TRUE;
LOCK(Yap_ThreadHandlesLock);
if (!FOREIGN_ThreadHandle(tid).in_use &&
!FOREIGN_ThreadHandle(tid).zombie) {
if (!REMOTE_ThreadHandle(tid).in_use &&
!REMOTE_ThreadHandle(tid).zombie) {
UNLOCK(Yap_ThreadHandlesLock);
return FALSE;
}
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));
status &= Yap_unify(ARG2,MkIntegerTerm(REMOTE_ThreadHandle(tid).ssize));
status &= Yap_unify(ARG3,MkIntegerTerm(REMOTE_ThreadHandle(tid).tsize));
status &= Yap_unify(ARG4,MkIntegerTerm(REMOTE_ThreadHandle(tid).sysize));
UNLOCK(Yap_ThreadHandlesLock);
return status;
}
@ -801,21 +800,21 @@ p_thread_signal( USES_REGS1 )
{ /* '$thread_signal'(+P) */
Int wid = IntegerOfTerm(Deref(ARG1));
/* make sure the lock is available */
pthread_mutex_lock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_lock(&(REMOTE_ThreadHandle(wid).tlock));
DEBUG_TLOCK_ACCESS(16, wid);
if (!FOREIGN_ThreadHandle(wid).in_use ||
!FOREIGN_ThreadHandle(wid).current_yaam_regs) {
if (!REMOTE_ThreadHandle(wid).in_use ||
!REMOTE_ThreadHandle(wid).current_yaam_regs) {
DEBUG_TLOCK_ACCESS(17, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}
LOCK(FOREIGN(wid)->signal_lock);
FOREIGN_ThreadHandle(wid).current_yaam_regs->CreepFlag_ =
Unsigned(FOREIGN_ThreadHandle(wid).current_yaam_regs->LCL0_);
FOREIGN(wid)->active_signals |= YAP_ITI_SIGNAL;
UNLOCK(FOREIGN(wid)->signal_lock);
LOCK(REMOTE_SignalLock(wid));
REMOTE_ThreadHandle(wid).current_yaam_regs->CreepFlag_ =
Unsigned(REMOTE_ThreadHandle(wid).current_yaam_regs->LCL0_);
REMOTE_ActiveSignals(wid) |= YAP_ITI_SIGNAL;
UNLOCK(REMOTE_SignalLock(wid));
DEBUG_TLOCK_ACCESS(18, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}
@ -832,7 +831,7 @@ p_nof_threads( USES_REGS1 )
LOCK(Yap_ThreadHandlesLock);
for (wid = 0; wid < MAX_THREADS; wid++) {
if (!Yap_local[wid]) break;
if (FOREIGN_ThreadHandle(wid).in_use)
if (REMOTE_ThreadHandle(wid).in_use)
i++;
}
UNLOCK(Yap_ThreadHandlesLock);
@ -875,7 +874,7 @@ p_thread_unlock( USES_REGS1 )
{ /* '$thread_unlock' */
Int wid = IntegerOfTerm(Deref(ARG1));
DEBUG_TLOCK_ACCESS(19, wid);
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(wid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(wid).tlock));
return TRUE;
}

View File

@ -190,15 +190,12 @@ extern struct global_data Yap_Global;
#if defined(THREADS)
extern struct worker_local *Yap_local[MAX_THREADS];
#define FOREIGN(wid) (Yap_local[wid])
#define REMOTE(wid) (Yap_local[wid])
#elif defined(YAPOR)
extern struct worker_local *Yap_local;
#define FOREIGN(wid) (Yap_local + wid)
#define REMOTE(wid) (Yap_local + wid)
#else /* !THREADS && !YAPOR */
extern struct worker_local Yap_local;
#define FOREIGN(wid) (&Yap_local)
#define REMOTE(wid) (&Yap_local)
#endif

View File

@ -124,10 +124,17 @@
#define LOCAL_execution LOCAL->_execution
#ifdef THREADS
#define LOCAL_ThreadHandle LOCAL->thread_handle
#define FOREIGN_ThreadHandle(wid) (Yap_local[(wid)]->thread_handle)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
#define LOCAL_optyap_data LOCAL->optyap_data
#endif /* YAPOR || TABLING */
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)

View File

@ -126,10 +126,17 @@ typedef struct worker_local {
struct open_query_struct* _execution;
#ifdef THREADS
struct thandle thread_handle;
#define FOREIGN_ThreadHandle(wid) (Yap_local[(wid)]->thread_handle)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
struct local_optyap_data optyap_data;
#endif /* YAPOR || TABLING */
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)
} w_local;

View File

@ -124,10 +124,17 @@ static void InitWorker(int wid) {
REMOTE(wid)->_execution = NULL;
#ifdef THREADS
InitThreadHandle(wid);
#define FOREIGN_ThreadHandle(wid) (Yap_local[(wid)]->thread_handle)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
Yap_init_local_optyap_data(wid);
#endif /* YAPOR || TABLING */
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)
}

View File

@ -124,10 +124,17 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef THREADS
#define FOREIGN_ThreadHandle(wid) (Yap_local[(wid)]->thread_handle)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
#endif /* YAPOR || TABLING */
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)
}

View File

@ -66,7 +66,7 @@ void make_root_choice_point(void) {
and convert back to our own stack;
*/
LOCAL_OldLCL0 = LCL0;
LCL0 = FOREIGN_ThreadHandle(0).current_yaam_regs->LCL0_;
LCL0 = REMOTE_ThreadHandle(0).current_yaam_regs->LCL0_;
imageB = Get_Yap_root_cp();
/* we know B */
B->cp_tr = TR =

View File

@ -2541,9 +2541,9 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
nwid = ((struct worker_local *)engine)->thread_handle.current_yaam_regs->worker_id_;
}
pthread_mutex_lock(&(FOREIGN_ThreadHandle(nwid).tlock));
if (FOREIGN_ThreadHandle(nwid).pthread_handle) {
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(nwid).tlock));
pthread_mutex_lock(&(REMOTE_ThreadHandle(nwid).tlock));
if (REMOTE_ThreadHandle(nwid).pthread_handle) {
pthread_mutex_unlock(&(REMOTE_ThreadHandle(nwid).tlock));
if (cwid != nwid) {
return PL_ENGINE_INUSE;
}
@ -2552,7 +2552,7 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
if (cwid >= 0) {
if (!YAP_ThreadDetachEngine(cwid)) {
*old = NULL;
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(nwid).tlock));
pthread_mutex_unlock(&(REMOTE_ThreadHandle(nwid).tlock));
return PL_ENGINE_INVAL;
}
}

View File

@ -90,7 +90,7 @@ Int total_cps LOCAL_total_choicepoints =0
int consult_level_ LOCAL_consult_level =0
#if defined(YAPOR) || defined(THREADS)
lockvar signal_lock LOCAL_SignalLock MkLock
lockvar signal_lock LOCAL_SignalLock MkLock
#endif
/* in a single gc */
Int tot_marked LOCAL_total_marked =0L
@ -139,13 +139,22 @@ struct open_query_struct* _execution LOCAL_execution =NULL
#ifdef THREADS
struct thandle thread_handle LOCAL_ThreadHandle InitThreadHandle(wid)
#define FOREIGN_ThreadHandle(wid) (Yap_local[(wid)]->thread_handle)
#endif /* THREADS */
#if defined(YAPOR) || defined(TABLING)
struct local_optyap_data optyap_data LOCAL_optyap_data Yap_init_local_optyap_data(wid)
#endif /* YAPOR || TABLING */
// defines
#define REMOTE_ThreadHandle(wid) (REMOTE(wid)->thread_handle)
#define REMOTE_c_input_stream(wid) (REMOTE(wid)->c_input_stream)
#define REMOTE_c_output_stream(wid) (REMOTE(wid)->c_output_stream)
#define REMOTE_c_error_stream(wid) (REMOTE(wid)->c_error_stream)
#define REMOTE_ActiveSignals(wid) (REMOTE(wid)->active_signals)
#define REMOTE_SignalLock(wid) (REMOTE(wid)->signal_lock)
#define REMOTE_ScratchPad(wid) (REMOTE(wid)->scratchpad)
// END WORKER LOCAL STUFF
END_WORKER_LOCAL