ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Async-Interrupt/Interrupt.pm
(Generate patch)

Comparing Async-Interrupt/Interrupt.pm (file contents):
Revision 1.5 by root, Fri Jul 3 21:11:22 2009 UTC vs.
Revision 1.6 by root, Sat Jul 11 22:16:50 2009 UTC

106might use (the exception is C<errno>, which is saved and restored by 106might use (the exception is C<errno>, which is saved and restored by
107Async::Interrupt). The callback itself runs as part of the perl context, 107Async::Interrupt). The callback itself runs as part of the perl context,
108so you can call any perl functions and modify any perl data structures (in 108so you can call any perl functions and modify any perl data structures (in
109which case the requirements set out for C<cb> apply as well). 109which case the requirements set out for C<cb> apply as well).
110 110
111=item signal => $signame_or_value
112
113When this parameter is specified, then the Async::Interrupt will hook the
114given signal, that is, it will effectively call C<< ->signal (0) >> each time
115the given signal is caught by the process.
116
117Only one async can hook a given signal, and the signal will be restored to
118defaults when the Async::Interrupt object gets destroyed.
119
111=item pipe => [$fileno_or_fh_for_reading, $fileno_or_fh_for_writing] 120=item pipe => [$fileno_or_fh_for_reading, $fileno_or_fh_for_writing]
112 121
113Specifies two file descriptors (or file handles) that should be signalled 122Specifies two file descriptors (or file handles) that should be signalled
114whenever the async interrupt is signalled. This means a single octet will 123whenever the async interrupt is signalled. This means a single octet will
115be written to it, and before the callback is being invoked, it will be 124be written to it, and before the callback is being invoked, it will be
116read again. Due to races, it is unlikely but possible that multiple octets 125read again. Due to races, it is unlikely but possible that multiple octets
117are written. It is required that the file handles are both in nonblocking 126are written. It is required that the file handles are both in nonblocking
118mode. 127mode.
119 128
120(You can get a portable pipe and set non-blocking mode portably by using 129You can get a portable pipe and set non-blocking mode portably by using
121e.g. L<AnyEvent::Util> from the L<AnyEvent> distribution). 130e.g. L<AnyEvent::Util> from the L<AnyEvent> distribution.
131
132It is also possible to pass in a linux eventfd as both read and write
133handle (which is faster than a pipe).
122 134
123The object will keep a reference to the file handles. 135The object will keep a reference to the file handles.
124 136
125This can be used to ensure that async notifications will interrupt event 137This can be used to ensure that async notifications will interrupt event
126frameworks as well. 138frameworks as well.
130=cut 142=cut
131 143
132sub new { 144sub new {
133 my ($class, %arg) = @_; 145 my ($class, %arg) = @_;
134 146
135 bless \(_alloc $arg{cb}, @{$arg{c_cb}}[0,1], @{$arg{pipe}}[0,1]), $class 147 bless \(_alloc $arg{cb}, @{$arg{c_cb}}[0,1], @{$arg{pipe}}[0,1], $arg{signal}), $class
136} 148}
137 149
138=item ($signal_func, $signal_arg) = $async->signal_func 150=item ($signal_func, $signal_arg) = $async->signal_func
139 151
140Returns the address of a function to call asynchronously. The function has 152Returns the address of a function to call asynchronously. The function has
189the current scope is exited (via an exception, by canceling the Coro 201the current scope is exited (via an exception, by canceling the Coro
190thread, by calling last/goto etc.). 202thread, by calling last/goto etc.).
191 203
192This is the recommended (and fastest) way to implement critical sections. 204This is the recommended (and fastest) way to implement critical sections.
193 205
206=item $async->pipe_enable
207
208=item $async->pipe_disable
209
210Enable/disable signalling the pipe when the interrupt occurs (default is
211enabled). Writing to a pipe is relatively expensive, so it can be disabled
212when you know you are not waiting for it (for example, with L<EV> you
213could disable the pipe in a check watcher, and enable it in a prepare
214watcher).
215
216Note that when C<fd_disable> is in effect, no attempt to read from the
217pipe will be done.
218
194=cut 219=cut
195 220
1961; 2211;
197 222
198=back 223=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines