From: Artur Bergman Date: Tue, 18 Sep 2001 10:24:31 +0000 (+0000) Subject: Changed how ownership of mutexes are held. We never hold a mutex only a slot indicati... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39696b0cdb512c61354df443d2f0b56bef0d4d8b;p=p5sagit%2Fp5-mst-13.2.git Changed how ownership of mutexes are held. We never hold a mutex only a slot indicating that we own the lock. p4raw-id: //depot/perl@12066 --- diff --git a/sharedsv.c b/sharedsv.c index db9b112..070a956 100644 --- a/sharedsv.c +++ b/sharedsv.c @@ -63,6 +63,8 @@ Perl_sharedsv_new(pTHX) 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; } @@ -97,15 +99,19 @@ Perl_sharedsv_lock(pTHX_ shared_sv* 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); } /* @@ -119,22 +125,31 @@ Recursively unlocks a shared sv. 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); } @@ -199,3 +214,4 @@ Perl_sharedsv_thrcnt_dec(pTHX_ shared_sv* ssv) } #endif /* USE_ITHREADS */ + diff --git a/sharedsv.h b/sharedsv.h index 1dec854..f92a94a 100644 --- a/sharedsv.h +++ b/sharedsv.h @@ -5,6 +5,7 @@ typedef struct { 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;