integration work:
- use SWI flags whenever possible - support by module unknown, escapes, strings - accesss thread info fom SWI - allow strings to be input as strings. - remove some unused flags.
This commit is contained in:
71
C/threads.c
71
C/threads.c
@@ -23,6 +23,7 @@ static char SccsId[] = "%W% %G%";
|
||||
#include "YapHeap.h"
|
||||
#include "eval.h"
|
||||
#include "yapio.h"
|
||||
#include "pl-shared.h"
|
||||
#include <stdio.h>
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
@@ -51,6 +52,27 @@ static Int p_nodebug_locks( USES_REGS1 ) { debug_locks = 0; return TRUE; }
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
set_system_thread_id(int wid, PL_thread_info_t *info)
|
||||
{
|
||||
if (!info)
|
||||
info = (PL_thread_info_t *)malloc(sizeof(PL_thread_info_t));
|
||||
info = SWI_thread_info(wid, info);
|
||||
info->tid = pthread_self();
|
||||
info->has_tid = TRUE;
|
||||
#ifdef HAVE_GETTID_SYSCALL
|
||||
info->pid = syscall(__NR_gettid);
|
||||
#else
|
||||
#ifdef HAVE_GETTID_MACRO
|
||||
info->pid = gettid();
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
info->w32id = GetCurrentThreadId();
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
allocate_new_tid(void)
|
||||
{
|
||||
@@ -237,6 +259,7 @@ setup_engine(int myworker_id, int init_thread)
|
||||
CACHE_REGS
|
||||
REGSTORE *standard_regs;
|
||||
|
||||
set_system_thread_id( myworker_id, NULL );
|
||||
standard_regs = (REGSTORE *)calloc(1,sizeof(REGSTORE));
|
||||
if (!standard_regs)
|
||||
return FALSE;
|
||||
@@ -244,7 +267,7 @@ setup_engine(int myworker_id, int init_thread)
|
||||
/* create the YAAM descriptor */
|
||||
REMOTE_ThreadHandle(myworker_id).default_yaam_regs = standard_regs;
|
||||
Yap_InitExStacks(myworker_id, REMOTE_ThreadHandle(myworker_id).tsize, REMOTE_ThreadHandle(myworker_id).ssize);
|
||||
CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
||||
LOCAL_SourceModule = CurrentModule = REMOTE_ThreadHandle(myworker_id).cmod;
|
||||
Yap_InitTime( myworker_id );
|
||||
Yap_InitYaamRegs( myworker_id );
|
||||
REFRESH_CACHE_REGS
|
||||
@@ -509,7 +532,6 @@ Yap_thread_create_engine(thread_attr *ops)
|
||||
Int
|
||||
Yap_thread_attach_engine(int wid)
|
||||
{
|
||||
CACHE_REGS
|
||||
/*
|
||||
already locked
|
||||
MUTEX_LOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
@@ -517,13 +539,14 @@ Yap_thread_attach_engine(int wid)
|
||||
if (REMOTE_ThreadHandle(wid).ref_count ) {
|
||||
REMOTE_ThreadHandle(wid).ref_count++;
|
||||
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||
set_system_thread_id(wid, SWI_thread_info(wid, NULL));
|
||||
MUTEX_UNLOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
REMOTE_ThreadHandle(wid).pthread_handle = pthread_self();
|
||||
set_system_thread_id(wid, SWI_thread_info(wid, NULL));
|
||||
REMOTE_ThreadHandle(wid).ref_count++;
|
||||
pthread_setspecific(Yap_yaamregs_key, (const void *)REMOTE_ThreadHandle(wid).current_yaam_regs);
|
||||
REFRESH_CACHE_REGS;
|
||||
MUTEX_UNLOCK(&(REMOTE_ThreadHandle(wid).tlock));
|
||||
return TRUE;
|
||||
}
|
||||
@@ -955,6 +978,43 @@ p_thread_unlock( USES_REGS1 )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
intptr_t
|
||||
system_thread_id(PL_thread_info_t *info)
|
||||
{ if ( !info )
|
||||
{ CACHE_REGS
|
||||
if ( LOCAL )
|
||||
info = SWI_thread_info(worker_id, NULL);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
#ifdef __linux__
|
||||
return info->pid;
|
||||
#else
|
||||
#ifdef __WINDOWS__
|
||||
return info->w32id;
|
||||
#else
|
||||
return (intptr_t)info->tid;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
CACHE_REGS
|
||||
LOCAL_ThreadHandle.id = 0;
|
||||
LOCAL_ThreadHandle.in_use = TRUE;
|
||||
LOCAL_ThreadHandle.default_yaam_regs =
|
||||
&Yap_standard_regs;
|
||||
LOCAL_ThreadHandle.pthread_handle = pthread_self();
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock, NULL);
|
||||
pthread_mutex_init(&REMOTE_ThreadHandle(0).tlock_status, NULL);
|
||||
LOCAL_ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
||||
LOCAL_ThreadHandle.ref_count = 1;
|
||||
set_system_thread_id(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$no_threads", 0, p_no_threads, 0);
|
||||
@@ -1057,6 +1117,11 @@ p_max_workers(void)
|
||||
return Yap_unify(ARG1,MkIntTerm(1));
|
||||
}
|
||||
|
||||
void
|
||||
Yap_InitFirstWorkerThreadHandle(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Yap_InitThreadPreds(void)
|
||||
{
|
||||
Yap_InitCPred("$max_workers", 1, p_max_workers, 0);
|
||||
|
Reference in New Issue
Block a user