New(2555,ssv,1,shared_sv);
MUTEX_INIT(&ssv->mutex);
COND_INIT(&ssv->cond);
+ COND_INIT(&ssv->user_cond);
+ ssv->owner = 0;
ssv->locks = 0;
return ssv;
}
{
if(!ssv)
return;
+ MUTEX_LOCK(&ssv->mutex);
if(ssv->owner && ssv->owner == my_perl) {
ssv->locks++;
+ MUTEX_UNLOCK(&ssv->mutex);
return;
}
- MUTEX_LOCK(&ssv->mutex);
+ while(ssv->owner)
+ COND_WAIT(&ssv->cond,&ssv->mutex);
ssv->locks++;
ssv->owner = my_perl;
if(ssv->locks == 1)
SAVEDESTRUCTOR_X(Perl_sharedsv_unlock_scope,ssv);
+ MUTEX_UNLOCK(&ssv->mutex);
}
/*
void
Perl_sharedsv_unlock(pTHX_ shared_sv* ssv)
{
- if(ssv->owner != my_perl)
+ MUTEX_LOCK(&ssv->mutex);
+ if(ssv->owner != my_perl) {
+ Perl_croak(aTHX_ "panic: Perl_sharedsv_unlock unlocking mutex that we don't own");
+ MUTEX_UNLOCK(&ssv->mutex);
return;
+ }
if(--ssv->locks == 0) {
ssv->owner = NULL;
- MUTEX_UNLOCK(&ssv->mutex);
+ COND_SIGNAL(&ssv->cond);
}
+ MUTEX_UNLOCK(&ssv->mutex);
}
void
Perl_sharedsv_unlock_scope(pTHX_ shared_sv* ssv)
{
- if(ssv->owner != my_perl)
+ MUTEX_LOCK(&ssv->mutex);
+ if(ssv->owner != my_perl) {
+ MUTEX_UNLOCK(&ssv->mutex);
return;
+ }
ssv->locks = 0;
ssv->owner = NULL;
+ COND_SIGNAL(&ssv->cond);
MUTEX_UNLOCK(&ssv->mutex);
}
}
#endif /* USE_ITHREADS */
+
SV* sv; /* The actual data */
perl_mutex mutex; /* Our mutex */
perl_cond cond; /* Our condition variable */
+ perl_cond user_cond; /* For user level conditions */
IV locks; /* Number of locks held */
PerlInterpreter* owner; /* who owns the lock */
} shared_sv;