ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Storable.pm
(Generate patch)

Comparing Coro/Coro/Storable.pm (file contents):
Revision 1.29 by root, Wed Sep 24 21:31:29 2008 UTC vs.
Revision 1.71 by root, Fri Nov 11 20:22:09 2011 UTC

68 68
69=cut 69=cut
70 70
71package Coro::Storable; 71package Coro::Storable;
72 72
73use strict qw(subs vars); 73use common::sense;
74no warnings;
75 74
76use Coro (); 75use Coro ();
77use Coro::Semaphore (); 76use Coro::Semaphore ();
78 77
79BEGIN { 78BEGIN {
83} 82}
84 83
85use Storable; 84use Storable;
86use base "Exporter"; 85use base "Exporter";
87 86
88our $VERSION = 4.748; 87our $VERSION = 6.07;
89our @EXPORT = qw(thaw freeze nfreeze blocking_thaw blocking_freeze blocking_nfreeze); 88our @EXPORT = qw(thaw freeze nfreeze blocking_thaw blocking_freeze blocking_nfreeze);
90 89
91our $GRANULARITY = 0.01; 90our $GRANULARITY = 0.01;
92 91
93my $lock = new Coro::Semaphore; 92my $lock = new Coro::Semaphore;
97} 96}
98 97
99# wrap xs functions 98# wrap xs functions
100for (qw(net_pstore pstore net_mstore mstore pretrieve mretrieve dclone)) { 99for (qw(net_pstore pstore net_mstore mstore pretrieve mretrieve dclone)) {
101 my $orig = \&{"Storable::$_"}; 100 my $orig = \&{"Storable::$_"};
102 *{"Storable::$_"} = sub { 101 *{"Storable::$_"} = eval 'sub (' . (prototype $orig) . ') {
103 my $guard = $lock->guard; 102 my $guard = $lock->guard;
104 &$orig 103 &$orig
105 }; 104 }';
106 die if $@; 105 die if $@;
107} 106}
108 107
109sub thaw($) { 108sub thaw($) {
110 open my $fh, "<:cede($GRANULARITY)", \$_[0] 109 open my $fh, "<:cede($GRANULARITY)", \$_[0]
114 113
115sub freeze($) { 114sub freeze($) {
116 open my $fh, ">:cede($GRANULARITY)", \my $buf 115 open my $fh, ">:cede($GRANULARITY)", \my $buf
117 or die "cannot open pst via PerlIO::cede: $!"; 116 or die "cannot open pst via PerlIO::cede: $!";
118 Storable::store_fd $_[0], $fh; 117 Storable::store_fd $_[0], $fh;
118 close $fh;
119
119 $buf 120 $buf
120} 121}
121 122
122sub nfreeze($) { 123sub nfreeze($) {
123 open my $fh, ">:cede($GRANULARITY)", \my $buf 124 open my $fh, ">:cede($GRANULARITY)", \my $buf
124 or die "cannot open pst via PerlIO::cede: $!"; 125 or die "cannot open pst via PerlIO::cede: $!";
125 Storable::nstore_fd $_[0], $fh; 126 Storable::nstore_fd $_[0], $fh;
127 close $fh;
128
126 $buf 129 $buf
127} 130}
128 131
129sub blocking_thaw($) { 132sub blocking_thaw($) {
130 open my $fh, "<", \$_[0] 133 open my $fh, "<", \$_[0]

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines