| Revision: | 1.42 |
| Committed: | Wed Feb 1 23:59:41 2006 UTC (20 years, 2 months ago) by root |
| Branch: | MAIN |
| CVS Tags: | rel-2_5, rel-3_41, rel-3_55, rel-3_51, rel-2_0, rel-2_1, rel-1_9, rel-3_6, rel-3_62, rel-3_63, rel-3_61, rel-3_4, rel-3_1, rel-3_5, rel-3_3, rel-3_2, rel-3_0, rel-3_01, rel-3_11, stack_sharing, rel-3_501 |
| Changes since 1.41: | +1 -1 lines |
| Log Message: | *** empty log message *** |
| # | Content |
|---|---|
| 1 | =head1 NAME |
| 2 | |
| 3 | Coro::Specific - manage coroutine-specific variables. |
| 4 | |
| 5 | =head1 SYNOPSIS |
| 6 | |
| 7 | use Coro::Specific; |
| 8 | |
| 9 | my $ref = new Coro::Specific; |
| 10 | |
| 11 | $$ref = 5; |
| 12 | print $$ref; |
| 13 | |
| 14 | =head1 DESCRIPTION |
| 15 | |
| 16 | This module can be used to create variables (or better: references to |
| 17 | them) that are specific to the currently executing coroutine. This module |
| 18 | does not automatically load the Coro module (so the overhead will be small |
| 19 | when no coroutines are used). |
| 20 | |
| 21 | =over 4 |
| 22 | |
| 23 | =cut |
| 24 | |
| 25 | package Coro::Specific; |
| 26 | |
| 27 | BEGIN { eval { require warnings } && warnings->unimport ("uninitialized") } |
| 28 | |
| 29 | $VERSION = 1.9; |
| 30 | |
| 31 | =item new |
| 32 | |
| 33 | Create a new coroutine-specific scalar and return a reference to it. The |
| 34 | scalar is guarenteed to be "undef". Once such a scalar has been allocated |
| 35 | you cannot deallocate it (yet), so allocate only when you must. |
| 36 | |
| 37 | =cut |
| 38 | |
| 39 | my $idx; |
| 40 | |
| 41 | sub new { |
| 42 | my $var; |
| 43 | tie $var, Coro::Specific::; |
| 44 | \$var; |
| 45 | } |
| 46 | |
| 47 | sub TIESCALAR { |
| 48 | my $idx = $idx++; |
| 49 | bless \$idx, $_[0]; |
| 50 | } |
| 51 | |
| 52 | sub FETCH { |
| 53 | $Coro::current->{specific}[${$_[0]}]; |
| 54 | } |
| 55 | |
| 56 | sub STORE { |
| 57 | $Coro::current->{specific}[${$_[0]}] = $_[1]; |
| 58 | } |
| 59 | |
| 60 | #sub DESTROY { |
| 61 | # push @idx, $$_[0]; |
| 62 | #} |
| 63 | |
| 64 | 1; |
| 65 | |
| 66 | =back |
| 67 | |
| 68 | =head1 BUGS |
| 69 | |
| 70 | The actual coroutine specific values do not automatically get destroyed |
| 71 | when the Coro::Specific object gets destroyed. |
| 72 | |
| 73 | =head1 AUTHOR |
| 74 | |
| 75 | Marc Lehmann <schmorp@schmorp.de> |
| 76 | http://home.schmorp.de/ |
| 77 | |
| 78 | =cut |
| 79 |