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.16 by root, Thu May 6 15:05:57 2004 UTC vs.
Revision 1.28 by root, Sat Jul 9 04:11:30 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.
20 21
21Although the module will work with threads, it is not reentrant, so use 22NOTICE: the threads created by this module will automatically be killed
22appropriate locking yourself. 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.
23 28
24=over 4 29=over 4
25 30
26=cut 31=cut
27 32
28package Linux::AIO; 33package Linux::AIO;
29 34
30use base 'Exporter'; 35use base 'Exporter';
31 36
32BEGIN { 37BEGIN {
33 $VERSION = 1.1; 38 $VERSION = 1.61;
34 39
35 @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);
36 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); 41 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs);
37 42
38 require XSLoader; 43 require XSLoader;
39 XSLoader::load Linux::AIO, $VERSION; 44 XSLoader::load Linux::AIO, $VERSION;
40} 45}
43 48
44Set the minimum number of AIO threads to C<$nthreads>. The default is 49Set the minimum number of AIO threads to C<$nthreads>. The default is
45C<1>, which means a single asynchronous operation can be done at one time 50C<1>, which means a single asynchronous operation can be done at one time
46(the number of outstanding operations, however, is unlimited). 51(the number of outstanding operations, however, is unlimited).
47 52
48It is recommended to keep the number of threads low, as many linux 53It is recommended to keep the number of threads low, as some linux
49kernel versions will scale negatively with the number of threads (higher 54kernel versions will scale negatively with the number of threads (higher
50parallelity => MUCH higher latency). 55parallelity => MUCH higher latency).
56
57=item Linux::AIO::max_parallel $nthreads
58
59Sets the maximum number of AIO threads to C<$nthreads>. If more than
60the specified number of threads are currently running, kill them. This
61function blocks until the limit is reached.
62
63This module automatically runs C<max_parallel 0> at program end, to ensure
64that all threads are killed and that there are no outstanding requests.
51 65
52=item $fileno = Linux::AIO::poll_fileno 66=item $fileno = Linux::AIO::poll_fileno
53 67
54Return the I<request result pipe filehandle>. This filehandle must be 68Return the I<request result pipe filehandle>. This filehandle must be
55polled for reading by some mechanism outside this module (e.g. Event 69polled for reading by some mechanism outside this module (e.g. Event
66 80
67 Event->io (fd => Linux::AIO::poll_fileno, 81 Event->io (fd => Linux::AIO::poll_fileno,
68 poll => 'r', async => 1, 82 poll => 'r', async => 1,
69 cb => \&Linux::AIO::poll_cb ); 83 cb => \&Linux::AIO::poll_cb );
70 84
85=item Linux::AIO::poll_wait
86
87Wait till the result filehandle becomes ready for reading (simply does a
88select on the filehandle. This is useful if you want to synchronously wait
89for some requests to finish).
71 90
72=item Linux::AIO::nreqs 91=item Linux::AIO::nreqs
73 92
74Returns the number of requests currently outstanding. 93Returns the number of requests currently outstanding.
75 94
101 120
102Currently, the stats are always 64-bit-stats, i.e. instead of returning an 121Currently, the stats are always 64-bit-stats, i.e. instead of returning an
103error when stat'ing a large file, the results will be silently truncated 122error when stat'ing a large file, the results will be silently truncated
104unless perl itself is compiled with large file support. 123unless perl itself is compiled with large file support.
105 124
125=item aio_unlink $pathname, $callback
126
127Asynchronously unlink a file.
128
106=cut 129=cut
107 130
108min_parallel 1; 131min_parallel 1;
109 132
110END { 133END {
126 149
127L<Coro>. 150L<Coro>.
128 151
129=head1 AUTHOR 152=head1 AUTHOR
130 153
131 Marc Lehmann <pcg@goof.com> 154 Marc Lehmann <schmorp@schmorp.de>
132 http://www.goof.com/pcg/marc/ 155 http://home.schmorp.de/
133 156
134=cut 157=cut
135 158

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines