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

Comparing Linux-AIO/AIO.pm (file contents):
Revision 1.14 by root, Wed May 5 13:54:37 2004 UTC vs.
Revision 1.26 by root, Thu Jul 7 23:17:23 2005 UTC

16Instead, in this module a number of (non-posix) threads are started that 16Instead, in this module a number of (non-posix) threads are started that
17execute your read/writes and signal their completion. You don't need 17execute your read/writes and signal their completion. You don't need
18thread support in your libc or perl, and the threads created by this 18thread support in your libc or perl, and the threads created by this
19module will not be visible to the pthreads library. 19module will not be visible to the pthreads library.
20 20
21NOTICE: the threads created by this module will automatically be killed
22when the thread calling min_parallel exits. Make sure you only ever call
23min_parallel from the same thread that loaded this module.
24
25Although the module will work with threads, it is not reentrant, so use
26appropriate locking yourself.
27
21=over 4 28=over 4
22 29
23=cut 30=cut
24 31
25package Linux::AIO; 32package Linux::AIO;
26 33
27use base 'Exporter'; 34use base 'Exporter';
28 35
29BEGIN { 36BEGIN {
30 $VERSION = '1.0'; 37 $VERSION = 1.6;
31 38
32 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat); 39 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink);
33 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); 40 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs);
34 41
35 require XSLoader; 42 require XSLoader;
36 XSLoader::load Linux::AIO, $VERSION; 43 XSLoader::load Linux::AIO, $VERSION;
37} 44}
38 45
39=item Linux::AIO::min_parallel $nthreads 46=item Linux::AIO::min_parallel $nthreads
40 47
41Set the minimum number of AIO threads to C<$nthreads>. You I<have> to call 48Set the minimum number of AIO threads to C<$nthreads>. The default is
42this function with a positive number at least once, otherwise no threads 49C<1>, which means a single asynchronous operation can be done at one time
43will be started and you aio-operations will seem to hang. 50(the number of outstanding operations, however, is unlimited).
44 51
45It is recommended to keep the number of threads low, as many linux 52It is recommended to keep the number of threads low, as some linux
46kernel versions will scale negatively with the number of threads (higher 53kernel versions will scale negatively with the number of threads (higher
47parallelity => MUCH higher latency). 54parallelity => MUCH higher latency).
55
56=item Linux::AIO::max_parallel $nthreads
57
58Sets the maximum number of AIO threads to C<$nthreads>. If more than
59the specified number of threads are currently running, kill them. This
60function blocks until the limit is reached.
61
62This module automatically runs C<max_parallel 0> at program end, to ensure
63that all threads are killed and that there are no outstanding requests.
48 64
49=item $fileno = Linux::AIO::poll_fileno 65=item $fileno = Linux::AIO::poll_fileno
50 66
51Return the I<request result pipe filehandle>. This filehandle must be 67Return the I<request result pipe filehandle>. This filehandle must be
52polled for reading by some mechanism outside this module (e.g. Event 68polled for reading by some mechanism outside this module (e.g. Event
63 79
64 Event->io (fd => Linux::AIO::poll_fileno, 80 Event->io (fd => Linux::AIO::poll_fileno,
65 poll => 'r', async => 1, 81 poll => 'r', async => 1,
66 cb => \&Linux::AIO::poll_cb ); 82 cb => \&Linux::AIO::poll_cb );
67 83
84=item Linux::AIO::poll_wait
85
86Wait till the result filehandle becomes ready for reading (simply does a
87select on the filehandle. This is useful if you want to synchronously wait
88for some requests to finish).
68 89
69=item Linux::AIO::nreqs 90=item Linux::AIO::nreqs
70 91
71Returns the number of requests currently outstanding. 92Returns the number of requests currently outstanding.
72 93
98 119
99Currently, the stats are always 64-bit-stats, i.e. instead of returning an 120Currently, the stats are always 64-bit-stats, i.e. instead of returning an
100error when stat'ing a large file, the results will be silently truncated 121error when stat'ing a large file, the results will be silently truncated
101unless perl itself is compiled with large file support. 122unless perl itself is compiled with large file support.
102 123
124=item aio_unlink $pathname, $callback
125
126Asynchronously unlink a file.
127
103=cut 128=cut
129
130min_parallel 1;
104 131
105END { 132END {
106 max_parallel 0; 133 max_parallel 0;
107} 134}
108 135
121 148
122L<Coro>. 149L<Coro>.
123 150
124=head1 AUTHOR 151=head1 AUTHOR
125 152
126 Marc Lehmann <pcg@goof.com> 153 Marc Lehmann <schmorp@schmorp.de>
127 http://www.goof.com/pcg/marc/ 154 http://home.schmorp.de/
128 155
129=cut 156=cut
130 157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines