static perl_mutex create_destruct_mutex; /* protects the creation and destruction of threads*/
static UV tid_counter = 0;
-static IV known_threads = 0;
static IV active_threads = 0;
static void
-Perl_ithread_set (pTHX_ ithread* thread)
+S_ithread_set (pTHX_ ithread* thread)
{
dMY_CXT;
MY_CXT.thread = thread;
}
static ithread*
-Perl_ithread_get (pTHX) {
+S_ithread_get (pTHX) {
dMY_CXT;
return MY_CXT.thread;
}
void *ptr;
#endif
PERL_SET_CONTEXT(interp);
- current_thread = Perl_ithread_get(aTHX);
- Perl_ithread_set(aTHX_ thread);
+ current_thread = S_ithread_get(aTHX);
+ S_ithread_set(aTHX_ thread);
SvREFCNT_dec(thread->params);
/*
* free an ithread structure and any attached data if its count == 0
*/
-void
-Perl_ithread_destruct (pTHX_ ithread* thread, const char *why)
+static void
+S_ithread_destruct (pTHX_ ithread* thread, const char *why)
{
MUTEX_LOCK(&thread->mutex);
if (!thread->next) {
thread->next = NULL;
thread->prev = NULL;
}
- known_threads--;
- assert( known_threads >= 0 );
-#if 0
- Perl_warn(aTHX_ "destruct %d @ %p by %p now %d",
- thread->tid,thread->interp,aTHX, known_threads);
-#endif
+
MUTEX_UNLOCK(&create_destruct_mutex);
/* Thread is now disowned */
return veto_cleanup;
}
-void
-Perl_ithread_detach(pTHX_ ithread *thread)
+static void
+S_ithread_detach(pTHX_ ithread *thread)
{
MUTEX_LOCK(&thread->mutex);
if (!(thread->state & (PERL_ITHR_DETACHED|PERL_ITHR_JOINED))) {
if ((thread->state & PERL_ITHR_FINISHED) &&
(thread->state & PERL_ITHR_DETACHED)) {
MUTEX_UNLOCK(&thread->mutex);
- Perl_ithread_destruct(aTHX_ thread, "detach");
+ S_ithread_destruct(aTHX_ thread, "detach");
}
else {
MUTEX_UNLOCK(&thread->mutex);
thread->state & PERL_ITHR_JOINED))
{
MUTEX_UNLOCK(&thread->mutex);
- Perl_ithread_destruct(aTHX_ thread, "no reference");
+ S_ithread_destruct(aTHX_ thread, "no reference");
}
else {
MUTEX_UNLOCK(&thread->mutex);
#ifdef WIN32
static THREAD_RET_TYPE
-Perl_ithread_run(LPVOID arg) {
+S_ithread_run(LPVOID arg) {
#else
static void*
-Perl_ithread_run(void * arg) {
+S_ithread_run(void * arg) {
#endif
ithread* thread = (ithread*) arg;
dTHXa(thread->interp);
PERL_SET_CONTEXT(thread->interp);
- Perl_ithread_set(aTHX_ thread);
+ S_ithread_set(aTHX_ thread);
#if 0
/* Far from clear messing with ->thr child-side is a good idea */
if (thread->state & PERL_ITHR_DETACHED) {
MUTEX_UNLOCK(&thread->mutex);
- Perl_ithread_destruct(aTHX_ thread, "detached finish");
+ S_ithread_destruct(aTHX_ thread, "detached finish");
} else {
MUTEX_UNLOCK(&thread->mutex);
}
}
else
{
- return Perl_ithread_get(aTHX);
+ return S_ithread_get(aTHX);
}
}
*/
static SV *
-Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* params)
+S_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* params)
{
ithread* thread;
CLONE_PARAMS clone_param;
- ithread* current_thread = Perl_ithread_get(aTHX);
+ ithread* current_thread = S_ithread_get(aTHX);
SV** tmps_tmp = PL_tmps_stack;
IV tmps_ix = PL_tmps_ix;
*/
PerlIO_flush((PerlIO*)NULL);
- Perl_ithread_set(aTHX_ thread);
+ S_ithread_set(aTHX_ thread);
SAVEBOOL(PL_srand_called); /* Save this so it becomes the correct
value */
PL_ptr_table = NULL;
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
}
- Perl_ithread_set(aTHX_ current_thread);
+ S_ithread_set(aTHX_ current_thread);
PERL_SET_CONTEXT(aTHX);
/* Start the thread */
#ifdef WIN32
- thread->handle = CreateThread(NULL, 0, Perl_ithread_run,
+ thread->handle = CreateThread(NULL, 0, S_ithread_run,
(LPVOID)thread, 0, &thread->thr);
#else
{
#ifdef OLD_PTHREADS_API
failure
= panic ? 1 : pthread_create( &thread->thr, attr,
- Perl_ithread_run, (void *)thread);
+ S_ithread_run, (void *)thread);
#else
# if defined(HAS_PTHREAD_ATTR_SETSCOPE) && defined(PTHREAD_SCOPE_SYSTEM)
pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
# endif
failure
= panic ? 1 : pthread_create( &thread->thr, &attr,
- Perl_ithread_run, (void *)thread);
+ S_ithread_run, (void *)thread);
#endif
}
#endif
- known_threads++;
+
if (
#ifdef WIN32
thread->handle == NULL
) {
MUTEX_UNLOCK(&create_destruct_mutex);
sv_2mortal(params);
- Perl_ithread_destruct(aTHX_ thread, "create failed");
+ S_ithread_destruct(aTHX_ thread, "create failed");
#ifndef WIN32
if (panic)
Perl_croak(aTHX_ panic);
}
static SV*
-Perl_ithread_self (pTHX_ SV *obj, char* Class)
+S_ithread_self (pTHX_ SV *obj, char* Class)
{
- ithread *thread = Perl_ithread_get(aTHX);
+ ithread *thread = S_ithread_get(aTHX);
if (thread)
return ithread_to_SV(aTHX_ obj, thread, Class, TRUE);
else
* This code takes the return value from the call_sv and sends it back.
*/
static AV*
-Perl_ithread_join(pTHX_ SV *obj)
+S_ithread_join(pTHX_ SV *obj)
{
ithread *thread = SV_to_ithread(aTHX_ obj);
MUTEX_LOCK(&thread->mutex);
clone_params.stashes = newAV();
clone_params.flags = CLONEf_JOIN_IN;
PL_ptr_table = ptr_table_new();
- current_thread = Perl_ithread_get(aTHX);
- Perl_ithread_set(aTHX_ thread);
+ current_thread = S_ithread_get(aTHX);
+ S_ithread_set(aTHX_ thread);
/* ensure 'meaningful' addresses retain their meaning */
ptr_table_store(PL_ptr_table, &other_perl->Isv_undef, &PL_sv_undef);
ptr_table_store(PL_ptr_table, &other_perl->Isv_no, &PL_sv_no);
}
}
#endif
- Perl_ithread_set(aTHX_ current_thread);
+ S_ithread_set(aTHX_ current_thread);
SvREFCNT_dec(clone_params.stashes);
SvREFCNT_inc(retparam);
ptr_table_free(PL_ptr_table);
}
static void
-Perl_ithread_DESTROY(pTHX_ SV *sv)
+S_ithread_DESTROY(pTHX_ SV *sv)
{
ithread *thread = SV_to_ithread(aTHX_ sv);
sv_unmagic(SvRV(sv),PERL_MAGIC_shared_scalar);
}
/* Create thread */
- ST(0) = sv_2mortal(Perl_ithread_create(aTHX_ Nullsv,
+ ST(0) = sv_2mortal(S_ithread_create(aTHX_ Nullsv,
classname,
function_to_call,
newRV_noinc((SV*)params)));
Perl_croak(aTHX_ "Usage: threads->self()");
classname = (char *)SvPV_nolen(ST(0));
- ST(0) = sv_2mortal(Perl_ithread_self(aTHX_ Nullsv, classname));
+ ST(0) = sv_2mortal(S_ithread_self(aTHX_ Nullsv, classname));
/* XSRETURN(1); - implied */
Perl_croak(aTHX_ "Usage: $thr->join()");
/* Join thread and get return values */
- params = Perl_ithread_join(aTHX_ ST(0));
+ params = S_ithread_join(aTHX_ ST(0));
if (! params) {
XSRETURN_UNDEF;
}
ithread *thread;
CODE:
thread = SV_to_ithread(aTHX_ ST(0));
- Perl_ithread_detach(aTHX_ thread);
+ S_ithread_detach(aTHX_ thread);
void
ithread_DESTROY(...)
CODE:
- Perl_ithread_DESTROY(aTHX_ ST(0));
+ S_ithread_DESTROY(aTHX_ ST(0));
void
thread->interp = aTHX;
thread->count = 1; /* Immortal. */
thread->tid = tid_counter++;
- known_threads++;
active_threads++;
thread->state = PERL_ITHR_DETACHED;
#ifdef WIN32
thread->thr = pthread_self();
#endif
- Perl_ithread_set(aTHX_ thread);
+ S_ithread_set(aTHX_ thread);
MUTEX_UNLOCK(&create_destruct_mutex);
#endif /* USE_ITHREADS */
}