ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Event/Event.pm
(Generate patch)

Comparing Coro/Event/Event.pm (file contents):
Revision 1.42 by root, Fri Dec 1 02:24:46 2006 UTC vs.
Revision 1.46 by root, Fri Dec 29 12:05:55 2006 UTC

47the current coroutine. 47the current coroutine.
48 48
49While this seems to work superficially, it will eventually cause memory 49While this seems to work superficially, it will eventually cause memory
50corruption. 50corruption.
51 51
52=head1 SEMANTICS
53
54Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.),
55this module cede's to all other coroutines with the same or higher
56priority. When any coroutines of lower priority are ready, it will not
57block but run one of them and then check for events.
58
59The effect is that coroutines with the same or higher priority than
60the blocking coroutine will keep Event from checking for events, while
61coroutines with lower priority are being run, but Event checks for new
62events after every cede.
63
52=head1 FUNCTIONS 64=head1 FUNCTIONS
53 65
54=over 4 66=over 4
55 67
56=cut 68=cut
71use base Exporter::; 83use base Exporter::;
72 84
73our @EXPORT = qw(loop unloop sweep); 85our @EXPORT = qw(loop unloop sweep);
74 86
75BEGIN { 87BEGIN {
76 our $VERSION = 1.9; 88 our $VERSION = '2.0';
77 89
78 local $^W = 0; # avoid redefine warning for Coro::ready; 90 local $^W = 0; # avoid redefine warning for Coro::ready;
79 XSLoader::load __PACKAGE__, $VERSION; 91 XSLoader::load __PACKAGE__, $VERSION;
80} 92}
81 93
116 128
117 shift eq Coro::Event:: 129 shift eq Coro::Event::
118 or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method"; 130 or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method";
119 131
120 my $w = $new->($class, 132 my $w = $new->($class,
121 desc => $flavour, 133 desc => $flavour,
122 @_, 134 @_,
123 parked => 1, 135 parked => 1,
124 ); 136 );
137
125 _install_std_cb($w, $type); 138 _install_std_cb $w, $type;
126 bless $w, $class; # reblessing due to broken Event 139
140 # reblessing due to Event being broken
141 bless $w, $class
127 }; 142 };
128 *{ $flavour } = $coronew; 143 *{ $flavour } = $coronew;
129 *{"do_$flavour"} = sub { 144 *{"do_$flavour"} = sub {
130 unshift @_, Coro::Event::; 145 unshift @_, Coro::Event::;
131 my $e = (&$coronew)->next; 146 @_ = &$coronew;
132 $e->cancel; # $e === $e->w 147 &Coro::schedule while &_next;
133 $e; 148 $_[0]->cancel;
149 &_event
134 }; 150 };
135} 151}
136 152
137# double calls to avoid stack-cloning ;() 153# do schedule in perl to avoid forcing a stack allocation.
138# is about 10% slower, though. 154# this is about 10% slower, though.
139sub next($) { 155sub next($) {
140 &Coro::schedule while &_next; 156 &Coro::schedule while &_next;
141 157
142 $_[0] 158 &_event
143} 159}
144 160
145sub Coro::Event::w { $_[0] } 161sub Coro::Event::w { $_[0] }
146sub Coro::Event::prio { $_[0]{Coro::Event}[3] } 162sub Coro::Event::prio { $_[0]{Coro::Event}[3] }
147sub Coro::Event::hits { $_[0]{Coro::Event}[4] } 163sub Coro::Event::hits { $_[0]{Coro::Event}[4] }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines