From: Artur Bergman Date: Fri, 26 Oct 2001 13:34:33 +0000 (+0000) Subject: And then finally cond_wait cond_signal and cond_broadcast are now implmented. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6f942b98720ba1a1943b0ad83963ea2d8c233143;p=p5sagit%2Fp5-mst-13.2.git And then finally cond_wait cond_signal and cond_broadcast are now implmented. p4raw-id: //depot/perl@12684 --- diff --git a/ext/threads/shared/shared.pm b/ext/threads/shared/shared.pm index d0d6cce..6868312 100644 --- a/ext/threads/shared/shared.pm +++ b/ext/threads/shared/shared.pm @@ -16,6 +16,11 @@ BEGIN { *lock = \&lock_disabled; } else { *share = \&share_enabled; + *cond_wait = \&cond_wait_enabled; + *cond_signal = \&cond_signal_enabled; + *cond_broadcast = \&cond_broadcast_enabled; + *unlock = \&unlock_enabled; + *lock = \&lock_enabled; } } diff --git a/ext/threads/shared/shared.xs b/ext/threads/shared/shared.xs index b297098..34ed30c 100644 --- a/ext/threads/shared/shared.xs +++ b/ext/threads/shared/shared.xs @@ -191,6 +191,75 @@ _thrcnt_dec(ref) croak("thrcnt can only be used on shared values"); Perl_sharedsv_thrcnt_dec(aTHX_ shared); +void +unlock_enabled(ref) + SV* ref + PROTOTYPE: \$ + CODE: + shared_sv* shared; + if(SvROK(ref)) + ref = SvRV(ref); + shared = Perl_sharedsv_find(aTHX, ref); + if(!shared) + croak("unlock can only be used on shared values"); + SHAREDSvUNLOCK(shared); + +void +lock_enabled(ref) + SV* ref + PROTOTYPE: \$ + CODE: + shared_sv* shared; + if(SvROK(ref)) + ref = SvRV(ref); + shared = Perl_sharedsv_find(aTHX, ref); + if(!shared) + croak("lock can only be used on shared values"); + SHAREDSvLOCK(shared); + + +void +cond_wait_enabled(ref) + SV* ref + CODE: + shared_sv* shared; + int locks; + if(SvROK(ref)) + ref = SvRV(ref); + shared = Perl_sharedsv_find(aTHX_ ref); + if(!shared) + croak("cond_wait can only be used on shared values"); + if(shared->owner != PERL_GET_CONTEXT) + croak("You need a lock before you can cond_wait"); + MUTEX_LOCK(&shared->mutex); + shared->owner = NULL; + locks = shared->locks = 0; + COND_WAIT(&shared->user_cond, &shared->mutex); + shared->owner = PERL_GET_CONTEXT; + shared->locks = locks; + +void cond_signal_enabled(ref) + SV* ref + CODE: + shared_sv* shared; + if(SvROK(ref)) + ref = SvRV(ref); + shared = Perl_sharedsv_find(aTHX_ ref); + if(!shared) + croak("cond_signal can only be used on shared values"); + COND_SIGNAL(&shared->user_cond); + + +void cond_broadcast_enabled(ref) + SV* ref + CODE: + shared_sv* shared; + if(SvROK(ref)) + ref = SvRV(ref); + shared = Perl_sharedsv_find(aTHX_ ref); + if(!shared) + croak("cond_broadcast can only be used on shared values"); + COND_BROADCAST(&shared->user_cond); MODULE = threads::shared PACKAGE = threads::shared::sv