diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-09-09 15:04:26 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-09-09 15:04:26 +0000 |
commit | 8f4f90ac2e80f3df09986d20b8ca1f122fa8aa75 (patch) | |
tree | 9dd2337ca9e33d346db06741b03689e576d58a6e | |
parent | 783070dab1caea458f767a4ef34229d89c6102a2 (diff) | |
download | perl-8f4f90ac2e80f3df09986d20b8ca1f122fa8aa75.tar.gz |
Rewrite synchronisation of subs/methods and add attrs
extension for specifying 'locked' and 'method' attributes.
p4raw-id: //depot/perlext/Thread@56
-rw-r--r-- | Thread.pm | 11 | ||||
-rw-r--r-- | Thread.xs | 41 | ||||
-rw-r--r-- | sync.t | 2 | ||||
-rw-r--r-- | sync2.t | 2 |
4 files changed, 11 insertions, 45 deletions
@@ -2,8 +2,7 @@ package Thread; require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); -@EXPORT_OK = qw(sync fast yield cond_signal cond_broadcast cond_wait - async); +@EXPORT_OK = qw(yield cond_signal cond_broadcast cond_wait async); # # Methods @@ -18,12 +17,4 @@ sub async (&) { bootstrap Thread; -my $cv; -foreach $cv (\&yield, \&sync, \&join, \&fast, \&DESTROY, - \&cond_wait, \&cond_signal, \&cond_broadcast) { - fast($cv); -} - -sync(\&new); # not sure if this needs to be sync'd - 1; @@ -202,24 +202,6 @@ AV *initargs; return thr; } -static SV * -fast(sv) -SV *sv; -{ - HV *hvp; - GV *gvp; - CV *cv = sv_2cv(sv, &hvp, &gvp, FALSE); - - if (!cv) - croak("Not a CODE reference"); - if (CvCONDP(cv)) { - COND_DESTROY(CvCONDP(cv)); - Safefree(CvCONDP(cv)); - CvCONDP(cv) = 0; - } - return sv; -} - MODULE = Thread PACKAGE = Thread Thread @@ -233,26 +215,15 @@ new(class, startsv, ...) RETVAL void -sync(sv) - SV * sv - HV * hvp = NO_INIT - GV * gvp = NO_INIT - CODE: - SvFLAGS(sv_2cv(sv, &hvp, &gvp, FALSE)) |= SVp_SYNC; - ST(0) = sv_mortalcopy(sv); - -void -fast(sv) - SV * sv - CODE: - ST(0) = sv_mortalcopy(fast(sv)); - -void join(t) Thread t AV * av = NO_INIT int i = NO_INIT PPCODE: + DEBUG_L(PerlIO_printf(PerlIO_stderr(), + "0x%lx: joining 0x%lx (state 0x%lx)\n", + (unsigned long)thr, (unsigned long)t, + (unsigned long)ThrSTATE(t));); if (ThrSTATE(t) == THR_DETACHED) croak("tried to join a detached thread"); else if (ThrSTATE(t) == THR_JOINED) @@ -271,6 +242,10 @@ void detach(t) Thread t CODE: + DEBUG_L(PerlIO_printf(PerlIO_stderr(), + "0x%lx: detaching 0x%lx (state 0x%lx)\n", + (unsigned long)thr, (unsigned long)t, + (unsigned long)ThrSTATE(t));); if (ThrSTATE(t) == THR_DETACHED) croak("tried to detach an already detached thread"); else if (ThrSTATE(t) == THR_JOINED) @@ -3,6 +3,7 @@ use Thread; $level = 0; sub single_file { + use attrs 'locked'; my $arg = shift; $level++; print "Level $level for $arg\n"; @@ -50,7 +51,6 @@ sub start_baz { $| = 1; srand($$^$^T); -Thread::sync(\&single_file); $foo = new Thread \&start_foo; $bar = new Thread \&start_bar; @@ -3,6 +3,7 @@ use Thread; $global = undef; sub single_file { + use attrs 'locked'; my $who = shift; my $i; @@ -48,7 +49,6 @@ sub start_c { $| = 1; srand($$^$^T); -Thread::sync(\&single_file); $foo = new Thread \&start_a; $bar = new Thread \&start_b; |