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.29 by root, Sat Jul 9 22:45:05 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines