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