… | |
… | |
81 | method. This is less efficient then calling the constructor once and the |
81 | method. This is less efficient then calling the constructor once and the |
82 | next method often, but it does save typing sometimes. |
82 | next method often, but it does save typing sometimes. |
83 | |
83 | |
84 | =cut |
84 | =cut |
85 | |
85 | |
86 | #sub std_cb { |
|
|
87 | # my $w = $_[0]->w; |
|
|
88 | # my $q = $w->private; |
|
|
89 | # $q->[1] = $_[0]; |
|
|
90 | # if ($q->[0]) { # somebody waiting? |
|
|
91 | # $q->[0]->ready; |
|
|
92 | # &Coro::schedule; |
|
|
93 | # } else { |
|
|
94 | # $w->stop; |
|
|
95 | # } |
|
|
96 | #} |
|
|
97 | |
|
|
98 | for my $flavour (qw(idle var timer io signal)) { |
86 | for my $flavour (qw(idle var timer io signal)) { |
99 | push @EXPORT, "do_$flavour"; |
87 | push @EXPORT, "do_$flavour"; |
100 | my $new = \&{"Event::$flavour"}; |
88 | my $new = \&{"Event::$flavour"}; |
101 | my $class = "Coro::Event::$flavour"; |
89 | my $class = "Coro::Event::$flavour"; |
102 | my $type = $flavour eq "io" ? 1 : 0; |
90 | my $type = $flavour eq "io" ? 1 : 0; |
… | |
… | |
125 | $e; |
113 | $e; |
126 | }; |
114 | }; |
127 | } |
115 | } |
128 | |
116 | |
129 | # double calls to avoid stack-cloning ;() |
117 | # double calls to avoid stack-cloning ;() |
130 | # is about 20% slower, though. |
118 | # is about 10% slower, though. |
131 | sub next($) { |
119 | sub next($) { |
132 | &_next0; |
120 | &Coro::schedule if &_next; $_[0]; |
133 | &Coro::schedule; |
|
|
134 | &_next1; |
|
|
135 | } |
121 | } |
136 | |
122 | |
137 | #sub next { |
|
|
138 | # my $w = $_[0]; |
|
|
139 | # my $q = $w->private; |
|
|
140 | # if ($q->[1]) { # event waiting? |
|
|
141 | # $w->again unless $w->is_cancelled; |
|
|
142 | # } elsif ($q->[0]) { |
|
|
143 | # croak "only one coroutine can wait for an event"; |
|
|
144 | # } else { |
|
|
145 | # local $q->[0] = $Coro::current; |
|
|
146 | # &Coro::schedule; |
|
|
147 | # } |
|
|
148 | # pop @$q; |
|
|
149 | #} |
|
|
150 | |
|
|
151 | sub Coro::Event::Ev::w { $_[0][2] } |
123 | sub Coro::Event::w { $_[0]{Coro::Event}[2] } |
152 | sub Coro::Event::Ev::got { $_[0][3] } |
124 | sub Coro::Event::got { $_[0]{Coro::Event}[3] } |
153 | sub Coro::Event::Ev::prio { croak "prio not supported yet, please mail to pcg\@goof.com" } |
125 | sub Coro::Event::prio { croak "prio not supported yet, please mail to pcg\@goof.com" } |
154 | sub Coro::Event::Ev::hits { croak "prio not supported yet, please mail to pcg\@goof.com" } |
126 | sub Coro::Event::hits { croak "prio not supported yet, please mail to pcg\@goof.com" } |
155 | |
127 | |
156 | =item sweep |
128 | =item sweep |
157 | |
129 | |
158 | Similar to Event::one_event and Event::sweep: The idle task is called once |
130 | Similar to Event::one_event and Event::sweep: The idle task is called once |
159 | (this has the effect of jumping back into the Event loop once to serve new |
131 | (this has the effect of jumping back into the Event loop once to serve new |