ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/BDB.pm
Revision: 1.4
Committed: Fri Apr 25 04:28:50 2008 UTC (16 years, 1 month ago) by root
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Coro::BDB - truly asynchronous bdb access
4    
5     =head1 SYNOPSIS
6    
7     use BDB;
8     use Coro::BDB;
9    
10     # can now use any of the bdb requests
11    
12     =head1 DESCRIPTION
13    
14     This module implements a thin wrapper around the L<BDB|BDB> module.
15    
16     Each BDB request that could block and doesn't get passed a callback will
17     normally block all coroutines. after loading this module, this will no
18     longer be the case.
19    
20     It will also register an AnyEvent handler (this will be done when the
21     module gets loaded and thus detects the event model at the same time, so
22     you need to laod your event module before Coro::BDB).
23    
24     This module does not export anything (unlike Coro::AIO), as BDB already
25     supports leaving out the callback.
26    
27     The AnyEvent watcher can be disabled by executing C<undef
28     $Coro::BDB::WATCHER>. Please notify the author of when and why you think
29     this was necessary.
30    
31     =over 4
32    
33     =cut
34    
35     package Coro::BDB;
36    
37     no warnings;
38     use strict;
39    
40     use Coro ();
41     use AnyEvent;
42     use BDB ();
43    
44     use base Exporter::;
45    
46 root 1.4 our $VERSION = 4.6;
47 root 1.1 our $WATCHER;
48    
49 root 1.2 if (AnyEvent::detect =~ /^AnyEvent::Impl::(?:Coro)?EV$/) {
50 root 1.3 $WATCHER = EV::io (BDB::poll_fileno, &EV::READ, \&BDB::poll_cb);
51 root 1.1 } else {
52     our $FH; open $FH, "<&=" . BDB::poll_fileno;
53     $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb);
54     }
55    
56     BDB::set_sync_prepare {
57     my $status;
58     my $current = $Coro::current;
59     (
60     sub {
61     $status = $!;
62     $current->ready; undef $current;
63     },
64     sub {
65     Coro::schedule while defined $current;
66     $! = $status;
67     },
68     )
69     };
70    
71     =back
72    
73     =head1 SEE ALSO
74    
75     L<BDB> of course.
76    
77     =head1 AUTHOR
78    
79     Marc Lehmann <schmorp@schmorp.de>
80     http://home.schmorp.de/
81    
82     =cut
83    
84     1