diff options
author | Yorhel <git@yorhel.nl> | 2008-11-13 20:56:58 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-11-13 20:56:58 +0100 |
commit | 6e1b278a832e7acc241303ecc2b5ab301f0c23ef (patch) | |
tree | ef0947aec507a8a965b767756491b687465d5d05 /lib/VNDB/Util/Misc.pm | |
parent | 66ae05366cf319a1d512bb79a7a7b384884e4a6a (diff) |
Forgot to upload new file *sigh*
Diffstat (limited to 'lib/VNDB/Util/Misc.pm')
-rw-r--r-- | lib/VNDB/Util/Misc.pm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm new file mode 100644 index 00000000..94cdcd1e --- /dev/null +++ b/lib/VNDB/Util/Misc.pm @@ -0,0 +1,28 @@ + +package VNDB::Util::Misc; + +use strict; +use warnings; +use Exporter 'import'; +use Tie::ShareLite ':lock'; + +our @EXPORT = qw|multiCmd|; + + +# Sends a command to Multi +# Argument: the commands to add to the queue, or none to send the queue to Multi +sub multiCmd { + my $self = shift; + + $self->{_multiCmd} = [] if !$self->{_multiCmd}; + return push @{$self->{_multiCmd}}, @_ if @_; + + return if !@{$self->{_multiCmd}}; + + my $s = tie my %s, 'Tie::ShareLite', -key => $self->{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666; + $s->lock(LOCK_EX); + my @q = ( ($s{queue} ? @{$s{queue}} : ()), @{$self->{_multiCmd}} ); + $s{queue} = \@q; + $s->unlock(); + $self->{_multiCmd} = []; +} |