… | |
… | |
118 | delete ((pop @destroy)->{_coro_state}) while @destroy; |
118 | delete ((pop @destroy)->{_coro_state}) while @destroy; |
119 | &schedule; |
119 | &schedule; |
120 | } |
120 | } |
121 | }; |
121 | }; |
122 | |
122 | |
123 | # we really need priorities... |
|
|
124 | my @ready; # the ready queue. hehe, rather broken ;) |
|
|
125 | |
|
|
126 | # static methods. not really. |
123 | # static methods. not really. |
127 | |
124 | |
128 | =head2 STATIC METHODS |
125 | =head2 STATIC METHODS |
129 | |
126 | |
130 | Static methods are actually functions that operate on the current process only. |
127 | Static methods are actually functions that operate on the current process only. |
… | |
… | |
160 | into the ready queue, so calling this function usually means you will |
157 | into the ready queue, so calling this function usually means you will |
161 | never be called again. |
158 | never be called again. |
162 | |
159 | |
163 | =cut |
160 | =cut |
164 | |
161 | |
165 | my $prev; |
|
|
166 | |
|
|
167 | sub schedule { |
|
|
168 | # should be done using priorities :( |
|
|
169 | ($prev, $current) = ($current, shift @ready || $idle); |
|
|
170 | Coro::State::transfer($prev, $current); |
|
|
171 | } |
|
|
172 | |
|
|
173 | =item cede |
162 | =item cede |
174 | |
163 | |
175 | "Cede" to other processes. This function puts the current process into the |
164 | "Cede" to other processes. This function puts the current process into the |
176 | ready queue and calls C<schedule>, which has the effect of giving up the |
165 | ready queue and calls C<schedule>, which has the effect of giving up the |
177 | current "timeslice" to other coroutines of the same or higher priority. |
166 | current "timeslice" to other coroutines of the same or higher priority. |
178 | |
167 | |
179 | =cut |
168 | =cut |
180 | |
|
|
181 | sub cede { |
|
|
182 | $current->ready; |
|
|
183 | &schedule; |
|
|
184 | } |
|
|
185 | |
169 | |
186 | =item terminate |
170 | =item terminate |
187 | |
171 | |
188 | Terminates the current process. |
172 | Terminates the current process. |
189 | |
173 | |
… | |
… | |
232 | =item $process->ready |
216 | =item $process->ready |
233 | |
217 | |
234 | Put the current process into the ready queue. |
218 | Put the current process into the ready queue. |
235 | |
219 | |
236 | =cut |
220 | =cut |
237 | |
|
|
238 | sub ready { |
|
|
239 | push @ready, $_[0]; |
|
|
240 | } |
|
|
241 | |
221 | |
242 | =item $process->cancel |
222 | =item $process->cancel |
243 | |
223 | |
244 | Like C<terminate>, but terminates the specified process instead. |
224 | Like C<terminate>, but terminates the specified process instead. |
245 | |
225 | |