fixes to YAP C-thread interface.

This commit is contained in:
Vitor Santos Costa 2010-07-23 12:07:33 +01:00
parent b1dd038eb5
commit eebff5df6a
5 changed files with 26 additions and 6 deletions

View File

@ -88,6 +88,8 @@ struct restore_info rinfo[MAX_THREADS];
struct thread_globs Yap_thread_gl[MAX_THREADS];
pthread_t Yap_master_thread;
#else
struct restore_info rinfo;
@ -1246,6 +1248,7 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s
#ifdef THREADS
pthread_key_create(&Yap_yaamregs_key, NULL);
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
Yap_master_thread = pthread_self();
#else
/* In this case we need to initialise the abstract registers */
Yap_regp = &Yap_standard_regs;

View File

@ -368,8 +368,13 @@ CELL
Yap_thread_create_engine(thread_attr *ops)
{
thread_attr opsv;
Term t = TermNil;
int new_id = allocate_new_tid();
Term t = TermNil;
/*
ok, this creates a problem, because we are initializing an engine from some "empty" thread.
We need first to foool the thread into believing it is the main thread
*/
if (new_id == -1) {
/* YAP ERROR */
return FALSE;
@ -381,13 +386,21 @@ Yap_thread_create_engine(thread_attr *ops)
ops->sysize = 0;
ops->egoal = t;
}
if (pthread_self() != Yap_master_thread) {
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
/* we are worker_id 0 for now, lock master thread so that no one messes with us */
pthread_mutex_lock(&(FOREIGN_ThreadHandle(0).tlock));
}
if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
return FALSE;
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;
if (pthread_self() != Yap_master_thread) {
pthread_mutex_unlock(&(FOREIGN_ThreadHandle(0).tlock));
}
return new_id;
}
Int

View File

@ -773,7 +773,6 @@ typedef struct thread_globs
extern struct thread_globs Yap_thread_gl[MAX_THREADS];
#define Yap_LocalBase Yap_thread_gl[worker_id].local_base
#define Yap_GlobalBase Yap_thread_gl[worker_id].global_base
#define Yap_TrailBase Yap_thread_gl[worker_id].trail_base
@ -784,6 +783,10 @@ extern struct thread_globs Yap_thread_gl[MAX_THREADS];
#define Yap_Error_Size Yap_thread_gl[worker_id].error_size
#define Yap_ErrorSay Yap_thread_gl[worker_id].error_say
#define Yap_RestartEnv Yap_thread_gl[worker_id].restart_env
/* This is the guy who actually started the system, and who has the correct registers */
extern pthread_t Yap_master_thread;
#else
extern ADDR Yap_HeapBase,
Yap_LocalBase, Yap_GlobalBase, Yap_TrailBase, Yap_TrailTop;

View File

@ -2784,7 +2784,6 @@ X_API int PL_thread_self(void)
X_API int PL_thread_attach_engine(const PL_thread_attr_t *attr)
{
int wid = YAP_ThreadSelf();
fprintf(stderr,"attaching new engine %p\n", attr);
if (wid < 0) {
/* we do not have an engine */
@ -2861,7 +2860,9 @@ X_API int
PL_set_engine(PL_engine_t engine, PL_engine_t *old)
{
YAP_Int cwid = YAP_ThreadSelf();
if (*old) *old = (PL_engine_t)cwid;
if (old) {
if (*old) *old = (PL_engine_t)cwid;
}
if (engine == PL_ENGINE_CURRENT)
return PL_ENGINE_SET;
if (engine < 0) /* should really check if engine does not exist */

@ -1 +1 @@
Subproject commit daedb37386cd9cdebd1473eed60d9bf240379d81
Subproject commit 7c9456b5c9c60ab227674f7653dc226e13973484