diff options
author | Artur Bergman <sky@nanisky.com> | 2001-09-18 10:24:31 +0000 |
---|---|---|
committer | Artur Bergman <sky@nanisky.com> | 2001-09-18 10:24:31 +0000 |
commit | 39696b0cdb512c61354df443d2f0b56bef0d4d8b (patch) | |
tree | 1d91a85d58531f9e4231cdfebcb8af8ce4244bd6 /sharedsv.c | |
parent | 6275698708d25f5dab8a4495910263deacde43b5 (diff) | |
download | perl-39696b0cdb512c61354df443d2f0b56bef0d4d8b.tar.gz |
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
Diffstat (limited to 'sharedsv.c')
-rw-r--r-- | sharedsv.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/sharedsv.c b/sharedsv.c index db9b112ed9..070a956413 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 */ + |