… | |
… | |
111 | use base 'Exporter'; |
111 | use base 'Exporter'; |
112 | |
112 | |
113 | our $VERSION; |
113 | our $VERSION; |
114 | |
114 | |
115 | BEGIN { |
115 | BEGIN { |
116 | $VERSION = '1.7'; |
116 | $VERSION = '1.81'; |
117 | |
117 | |
118 | our @BDB_REQ = qw( |
118 | our @BDB_REQ = qw( |
119 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
119 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
120 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
120 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
121 | db_open db_close db_compact db_sync db_upgrade |
121 | db_open db_close db_compact db_sync db_upgrade |
… | |
… | |
703 | |
703 | |
704 | You can still queue as many requests as you want. Therefore, |
704 | You can still queue as many requests as you want. Therefore, |
705 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
705 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
706 | as a stop gap to shield against fatal memory overflow (with large values). |
706 | as a stop gap to shield against fatal memory overflow (with large values). |
707 | |
707 | |
708 | =item BDB::set_sync_prepare $cb |
708 | =item $old_cb = BDB::set_sync_prepare $cb |
709 | |
709 | |
710 | Sets a callback that is called whenever a request is created without an |
710 | Sets a callback that is called whenever a request is created without an |
711 | explicit callback. It has to return two code references. The first is used |
711 | explicit callback. It has to return two code references. The first is used |
712 | as the request callback (it should save the return status), and the second |
712 | as the request callback (it should save the return status), and the second |
713 | is called to wait until the first callback has been called (it must set |
713 | is called to wait until the first callback has been called (it must set |
714 | C<$!> to the return status). |
714 | C<$!> to the return status). |
715 | |
715 | |
716 | This mechanism can be used to include BDB into other event mechanisms, |
716 | This mechanism can be used to include BDB into other event mechanisms, |
717 | such as L<AnyEvent::BDB> or L<Coro::BDB>. |
717 | such as L<Coro::BDB>. |
718 | |
718 | |
719 | The default implementation works like this: |
719 | To allow other, callback-based, events to be executed while callback-less |
|
|
720 | ones are run, you could use this sync prepare function: |
720 | |
721 | |
721 | sub { |
722 | sub { |
722 | my $status; |
723 | my $status; |
723 | ( |
724 | ( |
724 | sub { $status = $! }, |
725 | sub { $status = $! }, |
725 | sub { BDB::poll while !defined $status; $! = $status }, |
726 | sub { BDB::poll while !defined $status; $! = $status }, |
726 | ) |
727 | ) |
727 | } |
728 | } |
728 | |
729 | |
729 | It simply blocks the process till the request has finished and then sets |
730 | It works by polling for results till the request has finished and then |
730 | C<$!> to the return value. This means that if you don't use a callback, |
731 | sets C<$!> to the return value. This means that if you don't use a |
731 | BDB will simply fall back to synchronous operations. |
732 | callback, BDB would simply fall back to synchronous operations. |
|
|
733 | |
|
|
734 | By default, or if the sync prepare function is set to C<undef>, is to |
|
|
735 | execute callback-less BDB requests in the foreground thread, setting C<$!> |
|
|
736 | to the return value, without polling for other events. |
732 | |
737 | |
733 | =back |
738 | =back |
734 | |
739 | |
735 | =head3 STATISTICAL INFORMATION |
740 | =head3 STATISTICAL INFORMATION |
736 | |
741 | |
… | |
… | |
758 | |
763 | |
759 | =back |
764 | =back |
760 | |
765 | |
761 | =cut |
766 | =cut |
762 | |
767 | |
763 | set_sync_prepare { |
768 | set_sync_prepare (undef); |
764 | my $status; |
|
|
765 | ( |
|
|
766 | sub { |
|
|
767 | $status = $!; |
|
|
768 | }, |
|
|
769 | sub { |
|
|
770 | BDB::poll while !defined $status; |
|
|
771 | $! = $status; |
|
|
772 | }, |
|
|
773 | ) |
|
|
774 | }; |
|
|
775 | |
769 | |
776 | min_parallel 8; |
770 | min_parallel 8; |
777 | |
771 | |
778 | END { flush } |
772 | END { flush } |
779 | |
773 | |