From 8e8880d453cb4f914b7392e307d67e1a6079d74a Mon Sep 17 00:00:00 2001 From: gregor herrmann Date: Sat, 30 Sep 2023 00:00:19 +0200 Subject: New upstream version 1.889 --- Changes | 9 ++++++ META.json | 68 ++++++++++++++++++++--------------------- META.yml | 68 ++++++++++++++++++++--------------------- Makefile.PL | 68 ++++++++++++++++++++--------------------- README.md | 2 +- lib/MCE.pm | 7 +++-- lib/MCE.pod | 2 +- lib/MCE/Candy.pm | 4 +-- lib/MCE/Channel.pm | 6 ++-- lib/MCE/Channel/Mutex.pm | 16 +++------- lib/MCE/Channel/MutexFast.pm | 16 +++------- lib/MCE/Channel/Simple.pm | 16 +++------- lib/MCE/Channel/SimpleFast.pm | 16 +++------- lib/MCE/Channel/Threads.pm | 9 ++---- lib/MCE/Channel/ThreadsFast.pm | 9 ++---- lib/MCE/Child.pm | 4 +-- lib/MCE/Core.pod | 2 +- lib/MCE/Core/Input/Generator.pm | 4 +-- lib/MCE/Core/Input/Handle.pm | 4 +-- lib/MCE/Core/Input/Iterator.pm | 4 +-- lib/MCE/Core/Input/Request.pm | 4 +-- lib/MCE/Core/Input/Sequence.pm | 4 +-- lib/MCE/Core/Manager.pm | 4 +-- lib/MCE/Core/Validation.pm | 4 +-- lib/MCE/Core/Worker.pm | 4 +-- lib/MCE/Examples.pod | 2 +- lib/MCE/Flow.pm | 4 +-- lib/MCE/Grep.pm | 4 +-- lib/MCE/Loop.pm | 4 +-- lib/MCE/Map.pm | 4 +-- lib/MCE/Mutex.pm | 11 +++++-- lib/MCE/Mutex/Channel.pm | 41 ++++++++++++++++--------- lib/MCE/Mutex/Channel2.pm | 42 +++++++++++++++++-------- lib/MCE/Mutex/Flock.pm | 28 ++++++++++++----- lib/MCE/Queue.pm | 4 +-- lib/MCE/Relay.pm | 4 +-- lib/MCE/Signal.pm | 7 +++-- lib/MCE/Step.pm | 4 +-- lib/MCE/Stream.pm | 4 +-- lib/MCE/Subs.pm | 4 +-- lib/MCE/Util.pm | 14 ++++++--- xt/channel2_lock.t | 36 +++++++++++++++++----- xt/channel_lock.t | 16 ++++++++-- xt/flock_lock.t | 16 ++++++++-- 44 files changed, 333 insertions(+), 270 deletions(-) diff --git a/Changes b/Changes index 023b221..a5d6b12 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,15 @@ Revision history for Perl module MCE. +1.889 Wed Sep 13 18:00:00 EST 2023 + + * Add Android support. Thank you, Dimitrios Kechagias. + * Revert defer signal-handling in MCE::Channel (send2 method). + * Improve mutex synchronize (aka enter) with guard capability. + Thank you, José Joaquín Atria. + * Fix mutex re-entrant lock on the Windows platform. + * Add mutex guard_lock method. + 1.888 Wed Jun 21 17:00:00 EST 2023 * Fix typos caught by lintian. Thank you, Étienne Mollier. diff --git a/META.json b/META.json index d7b2bdf..c426034 100644 --- a/META.json +++ b/META.json @@ -65,135 +65,135 @@ "provides" : { "MCE" : { "file" : "lib/MCE.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Candy" : { "file" : "lib/MCE/Candy.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel" : { "file" : "lib/MCE/Channel.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::Mutex" : { "file" : "lib/MCE/Channel/Mutex.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::MutexFast" : { "file" : "lib/MCE/Channel/MutexFast.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::Simple" : { "file" : "lib/MCE/Channel/Simple.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::SimpleFast" : { "file" : "lib/MCE/Channel/SimpleFast.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::Threads" : { "file" : "lib/MCE/Channel/Threads.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Channel::ThreadsFast" : { "file" : "lib/MCE/Channel/ThreadsFast.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Child" : { "file" : "lib/MCE/Child.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Input::Generator" : { "file" : "lib/MCE/Core/Input/Generator.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Input::Handle" : { "file" : "lib/MCE/Core/Input/Handle.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Input::Iterator" : { "file" : "lib/MCE/Core/Input/Iterator.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Input::Request" : { "file" : "lib/MCE/Core/Input/Request.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Input::Sequence" : { "file" : "lib/MCE/Core/Input/Sequence.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Manager" : { "file" : "lib/MCE/Core/Manager.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Validation" : { "file" : "lib/MCE/Core/Validation.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Core::Worker" : { "file" : "lib/MCE/Core/Worker.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Flow" : { "file" : "lib/MCE/Flow.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Grep" : { "file" : "lib/MCE/Grep.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Loop" : { "file" : "lib/MCE/Loop.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Map" : { "file" : "lib/MCE/Map.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Mutex" : { "file" : "lib/MCE/Mutex.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Mutex::Channel" : { "file" : "lib/MCE/Mutex/Channel.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Mutex::Channel2" : { "file" : "lib/MCE/Mutex/Channel2.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Mutex::Flock" : { "file" : "lib/MCE/Mutex/Flock.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Queue" : { "file" : "lib/MCE/Queue.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Relay" : { "file" : "lib/MCE/Relay.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Signal" : { "file" : "lib/MCE/Signal.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Step" : { "file" : "lib/MCE/Step.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Stream" : { "file" : "lib/MCE/Stream.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Subs" : { "file" : "lib/MCE/Subs.pm", - "version" : "1.888" + "version" : "1.889" }, "MCE::Util" : { "file" : "lib/MCE/Util.pm", - "version" : "1.888" + "version" : "1.889" } }, "release_status" : "stable", @@ -209,5 +209,5 @@ "url" : "https://github.com/marioroy/mce-perl.git" } }, - "version" : "1.888" + "version" : "1.889" } diff --git a/META.yml b/META.yml index 5a015fe..e92333b 100644 --- a/META.yml +++ b/META.yml @@ -25,103 +25,103 @@ no_index: provides: MCE: file: lib/MCE.pm - version: '1.888' + version: '1.889' MCE::Candy: file: lib/MCE/Candy.pm - version: '1.888' + version: '1.889' MCE::Channel: file: lib/MCE/Channel.pm - version: '1.888' + version: '1.889' MCE::Channel::Mutex: file: lib/MCE/Channel/Mutex.pm - version: '1.888' + version: '1.889' MCE::Channel::MutexFast: file: lib/MCE/Channel/MutexFast.pm - version: '1.888' + version: '1.889' MCE::Channel::Simple: file: lib/MCE/Channel/Simple.pm - version: '1.888' + version: '1.889' MCE::Channel::SimpleFast: file: lib/MCE/Channel/SimpleFast.pm - version: '1.888' + version: '1.889' MCE::Channel::Threads: file: lib/MCE/Channel/Threads.pm - version: '1.888' + version: '1.889' MCE::Channel::ThreadsFast: file: lib/MCE/Channel/ThreadsFast.pm - version: '1.888' + version: '1.889' MCE::Child: file: lib/MCE/Child.pm - version: '1.888' + version: '1.889' MCE::Core::Input::Generator: file: lib/MCE/Core/Input/Generator.pm - version: '1.888' + version: '1.889' MCE::Core::Input::Handle: file: lib/MCE/Core/Input/Handle.pm - version: '1.888' + version: '1.889' MCE::Core::Input::Iterator: file: lib/MCE/Core/Input/Iterator.pm - version: '1.888' + version: '1.889' MCE::Core::Input::Request: file: lib/MCE/Core/Input/Request.pm - version: '1.888' + version: '1.889' MCE::Core::Input::Sequence: file: lib/MCE/Core/Input/Sequence.pm - version: '1.888' + version: '1.889' MCE::Core::Manager: file: lib/MCE/Core/Manager.pm - version: '1.888' + version: '1.889' MCE::Core::Validation: file: lib/MCE/Core/Validation.pm - version: '1.888' + version: '1.889' MCE::Core::Worker: file: lib/MCE/Core/Worker.pm - version: '1.888' + version: '1.889' MCE::Flow: file: lib/MCE/Flow.pm - version: '1.888' + version: '1.889' MCE::Grep: file: lib/MCE/Grep.pm - version: '1.888' + version: '1.889' MCE::Loop: file: lib/MCE/Loop.pm - version: '1.888' + version: '1.889' MCE::Map: file: lib/MCE/Map.pm - version: '1.888' + version: '1.889' MCE::Mutex: file: lib/MCE/Mutex.pm - version: '1.888' + version: '1.889' MCE::Mutex::Channel: file: lib/MCE/Mutex/Channel.pm - version: '1.888' + version: '1.889' MCE::Mutex::Channel2: file: lib/MCE/Mutex/Channel2.pm - version: '1.888' + version: '1.889' MCE::Mutex::Flock: file: lib/MCE/Mutex/Flock.pm - version: '1.888' + version: '1.889' MCE::Queue: file: lib/MCE/Queue.pm - version: '1.888' + version: '1.889' MCE::Relay: file: lib/MCE/Relay.pm - version: '1.888' + version: '1.889' MCE::Signal: file: lib/MCE/Signal.pm - version: '1.888' + version: '1.889' MCE::Step: file: lib/MCE/Step.pm - version: '1.888' + version: '1.889' MCE::Stream: file: lib/MCE/Stream.pm - version: '1.888' + version: '1.889' MCE::Subs: file: lib/MCE/Subs.pm - version: '1.888' + version: '1.889' MCE::Util: file: lib/MCE/Util.pm - version: '1.888' + version: '1.889' recommends: Sereal::Decoder: '3.015' Sereal::Encoder: '3.015' @@ -148,4 +148,4 @@ resources: homepage: https://github.com/marioroy/mce-perl license: https://dev.perl.org/licenses/ repository: https://github.com/marioroy/mce-perl.git -version: '1.888' +version: '1.889' diff --git a/Makefile.PL b/Makefile.PL index bcb632f..b04d86e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,7 +17,7 @@ WriteMakefile( ABSTRACT => 'Many-Core Engine for Perl providing parallel processing capabilities', AUTHOR => 'Mario E. Roy ', NAME => 'MCE', - VERSION => '1.888', + VERSION => '1.889', EXE_FILES => [ @exe_files ], @@ -68,135 +68,135 @@ WriteMakefile( 'provides' => { 'MCE' => { 'file' => 'lib/MCE.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Candy' => { 'file' => 'lib/MCE/Candy.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel' => { 'file' => 'lib/MCE/Channel.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::Mutex' => { 'file' => 'lib/MCE/Channel/Mutex.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::MutexFast' => { 'file' => 'lib/MCE/Channel/MutexFast.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::Simple' => { 'file' => 'lib/MCE/Channel/Simple.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::SimpleFast' => { 'file' => 'lib/MCE/Channel/SimpleFast.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::Threads' => { 'file' => 'lib/MCE/Channel/Threads.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Channel::ThreadsFast' => { 'file' => 'lib/MCE/Channel/ThreadsFast.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Child' => { 'file' => 'lib/MCE/Child.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Input::Generator' => { 'file' => 'lib/MCE/Core/Input/Generator.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Input::Handle' => { 'file' => 'lib/MCE/Core/Input/Handle.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Input::Iterator' => { 'file' => 'lib/MCE/Core/Input/Iterator.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Input::Request' => { 'file' => 'lib/MCE/Core/Input/Request.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Input::Sequence' => { 'file' => 'lib/MCE/Core/Input/Sequence.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Manager' => { 'file' => 'lib/MCE/Core/Manager.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Validation' => { 'file' => 'lib/MCE/Core/Validation.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Core::Worker' => { 'file' => 'lib/MCE/Core/Worker.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Flow' => { 'file' => 'lib/MCE/Flow.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Grep' => { 'file' => 'lib/MCE/Grep.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Loop' => { 'file' => 'lib/MCE/Loop.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Map' => { 'file' => 'lib/MCE/Map.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Mutex' => { 'file' => 'lib/MCE/Mutex.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Mutex::Channel' => { 'file' => 'lib/MCE/Mutex/Channel.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Mutex::Channel2' => { 'file' => 'lib/MCE/Mutex/Channel2.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Mutex::Flock' => { 'file' => 'lib/MCE/Mutex/Flock.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Queue' => { 'file' => 'lib/MCE/Queue.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Relay' => { 'file' => 'lib/MCE/Relay.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Signal' => { 'file' => 'lib/MCE/Signal.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Step' => { 'file' => 'lib/MCE/Step.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Stream' => { 'file' => 'lib/MCE/Stream.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Subs' => { 'file' => 'lib/MCE/Subs.pm', - 'version' => '1.888' + 'version' => '1.889' }, 'MCE::Util' => { 'file' => 'lib/MCE/Util.pm', - 'version' => '1.888' + 'version' => '1.889' } }, 'prereqs' => { diff --git a/README.md b/README.md index 4e7f310..90bcd52 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Many-Core Engine for Perl -This document describes MCE version 1.888. +This document describes MCE version 1.889. Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. diff --git a/lib/MCE.pm b/lib/MCE.pm index 1329a20..0c6ce2d 100644 --- a/lib/MCE.pm +++ b/lib/MCE.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -629,8 +629,9 @@ sub spawn { MCE::Util::_sock_pair($self, qw(_dat_r_sock _dat_w_sock), $_, 1) for (1 .. $_data_channels); - setsockopt($self->{_dat_r_sock}->[0], SOL_SOCKET, SO_RCVBUF, pack('i', 4096)) - if ($^O ne 'aix' && $^O ne 'linux'); + if ($^O !~ /linux|android|aix/) { + setsockopt($self->{_dat_r_sock}->[0], SOL_SOCKET, SO_RCVBUF, pack('i', 4096)); + } if (defined $self->{init_relay}) { # relay unless ($INC{'MCE/Relay.pm'}) { diff --git a/lib/MCE.pod b/lib/MCE.pod index 686e23a..60d7365 100644 --- a/lib/MCE.pod +++ b/lib/MCE.pod @@ -5,7 +5,7 @@ MCE - Many-Core Engine for Perl providing parallel processing capabilities =head1 VERSION -This document describes MCE version 1.888 +This document describes MCE version 1.889 Many-Core Engine (MCE) for Perl helps enable a new level of performance by maximizing all available cores. diff --git a/lib/MCE/Candy.pm b/lib/MCE/Candy.pm index 1e95d04..f25897d 100644 --- a/lib/MCE/Candy.pm +++ b/lib/MCE/Candy.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; our @CARP_NOT = qw( MCE ); @@ -240,7 +240,7 @@ MCE::Candy - Sugar methods and output iterators =head1 VERSION -This document describes MCE::Candy version 1.888 +This document describes MCE::Candy version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel.pm b/lib/MCE/Channel.pm index 92e72a1..3693780 100644 --- a/lib/MCE/Channel.pm +++ b/lib/MCE/Channel.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -55,7 +55,7 @@ sub new { my $impl = defined( $argv{impl} ) ? ucfirst( lc $argv{impl} ) : 'Mutex'; # Replace 'fast' with 'Fast' in the implementation value. - $impl =~ s/fast$/Fast/; + $impl =~ s/fast/Fast/; $impl = 'Threads' if ( $impl eq 'Mutex' && $^O eq 'MSWin32' ); $impl = 'ThreadsFast' if ( $impl eq 'MutexFast' && $^O eq 'MSWin32' ); @@ -131,7 +131,7 @@ MCE::Channel - Queue-like and two-way communication capability =head1 VERSION -This document describes MCE::Channel version 1.888 +This document describes MCE::Channel version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Channel/Mutex.pm b/lib/MCE/Channel/Mutex.pm index 8fd7c01..5136c97 100644 --- a/lib/MCE/Channel/Mutex.pm +++ b/lib/MCE/Channel/Mutex.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use base 'MCE::Channel'; use MCE::Mutex (); @@ -219,17 +219,9 @@ sub send2 { my $data = $freeze->([ @_ ]); local $\ = undef if (defined $\); - local $MCE::Signal::SIG; - - { - local $MCE::Signal::IPC = 1; - ( my $c_mutex = $self->{c_mutex} )->lock2; - + $self->{c_mutex}->synchronize2( sub { print { $self->{c_sock} } pack('i', length $data), $data; - $c_mutex->unlock2; - } - - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; + }); return 1; } @@ -304,7 +296,7 @@ MCE::Channel::Mutex - Channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::Mutex version 1.888 +This document describes MCE::Channel::Mutex version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/MutexFast.pm b/lib/MCE/Channel/MutexFast.pm index a1007ac..b1cc56b 100644 --- a/lib/MCE/Channel/MutexFast.pm +++ b/lib/MCE/Channel/MutexFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use base 'MCE::Channel'; use MCE::Mutex (); @@ -220,17 +220,9 @@ sub send2 { my $data = ''.shift; local $\ = undef if (defined $\); - local $MCE::Signal::SIG; - - { - local $MCE::Signal::IPC = 1; - ( my $c_mutex = $self->{c_mutex} )->lock2; - + $self->{c_mutex}->synchronize2( sub { print { $self->{c_sock} } pack('i', length $data), $data; - $c_mutex->unlock2; - } - - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; + }); return 1; } @@ -308,7 +300,7 @@ MCE::Channel::MutexFast - Fast channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::MutexFast version 1.888 +This document describes MCE::Channel::MutexFast version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/Simple.pm b/lib/MCE/Channel/Simple.pm index 405e09b..fa17548 100644 --- a/lib/MCE/Channel/Simple.pm +++ b/lib/MCE/Channel/Simple.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use base 'MCE::Channel'; @@ -227,16 +227,8 @@ sub send2 { my $data = $freeze->([ @_ ]); local $\ = undef if (defined $\); - local $MCE::Signal::SIG; - - { - local $MCE::Signal::IPC = 1; - - MCE::Util::_sock_ready_w( $self->{c_sock} ) if $is_MSWin32; - print { $self->{c_sock} } pack('i', length $data) . $data; - } - - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; + MCE::Util::_sock_ready_w( $self->{c_sock} ) if $is_MSWin32; + print { $self->{c_sock} } pack('i', length $data) . $data; return 1; } @@ -300,7 +292,7 @@ MCE::Channel::Simple - Channel tuned for one producer and one consumer =head1 VERSION -This document describes MCE::Channel::Simple version 1.888 +This document describes MCE::Channel::Simple version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/SimpleFast.pm b/lib/MCE/Channel/SimpleFast.pm index f2c4d23..a7cc85f 100644 --- a/lib/MCE/Channel/SimpleFast.pm +++ b/lib/MCE/Channel/SimpleFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use base 'MCE::Channel'; @@ -231,16 +231,8 @@ sub send2 { my $data = ''.shift; local $\ = undef if (defined $\); - local $MCE::Signal::SIG; - - { - local $MCE::Signal::IPC = 1; - - MCE::Util::_sock_ready_w( $self->{c_sock} ) if $is_MSWin32; - print { $self->{c_sock} } pack('i', length $data) . $data; - } - - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; + MCE::Util::_sock_ready_w( $self->{c_sock} ) if $is_MSWin32; + print { $self->{c_sock} } pack('i', length $data) . $data; return 1; } @@ -308,7 +300,7 @@ MCE::Channel::SimpleFast - Fast channel tuned for one producer and one consumer =head1 VERSION -This document describes MCE::Channel::SimpleFast version 1.888 +This document describes MCE::Channel::SimpleFast version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/Threads.pm b/lib/MCE/Channel/Threads.pm index 40708b2..5d9ea5d 100644 --- a/lib/MCE/Channel/Threads.pm +++ b/lib/MCE/Channel/Threads.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use threads; use threads::shared; @@ -229,20 +229,15 @@ sub send2 { my $data = $freeze->([ @_ ]); local $\ = undef if (defined $\); - local $MCE::Signal::SIG; { my $c_sock = $self->{c2_sock} || $self->{c_sock}; - local $MCE::Signal::IPC = 1; CORE::lock $self->{cw_mutex}; - MCE::Util::_sock_ready_w( $c_sock ) if $is_MSWin32; print { $c_sock } pack('i', length $data), $data; } - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; - return 1; } @@ -320,7 +315,7 @@ MCE::Channel::Threads - Channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::Threads version 1.888 +This document describes MCE::Channel::Threads version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Channel/ThreadsFast.pm b/lib/MCE/Channel/ThreadsFast.pm index f65a94a..4ebc4de 100644 --- a/lib/MCE/Channel/ThreadsFast.pm +++ b/lib/MCE/Channel/ThreadsFast.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use threads; use threads::shared; @@ -233,20 +233,15 @@ sub send2 { my $data = ''.shift; local $\ = undef if (defined $\); - local $MCE::Signal::SIG; { my $c_sock = $self->{c2_sock} || $self->{c_sock}; - local $MCE::Signal::IPC = 1; CORE::lock $self->{cw_mutex}; - MCE::Util::_sock_ready_w( $c_sock ) if $is_MSWin32; print { $c_sock } pack('i', length $data), $data; } - CORE::kill($MCE::Signal::SIG, $$) if $MCE::Signal::SIG; - return 1; } @@ -326,7 +321,7 @@ MCE::Channel::ThreadsFast - Fast channel for producer(s) and many consumers =head1 VERSION -This document describes MCE::Channel::ThreadsFast version 1.888 +This document describes MCE::Channel::ThreadsFast version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Child.pm b/lib/MCE/Child.pm index 2292935..f0482e9 100644 --- a/lib/MCE/Child.pm +++ b/lib/MCE/Child.pm @@ -11,7 +11,7 @@ no warnings qw( threads recursion uninitialized once redefine ); package MCE::Child; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitExplicitReturnUndef) @@ -1007,7 +1007,7 @@ MCE::Child - A threads-like parallelization module compatible with Perl 5.8 =head1 VERSION -This document describes MCE::Child version 1.888 +This document describes MCE::Child version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Core.pod b/lib/MCE/Core.pod index 62c66f2..ef2e0c6 100644 --- a/lib/MCE/Core.pod +++ b/lib/MCE/Core.pod @@ -5,7 +5,7 @@ MCE::Core - Documentation describing the core MCE API =head1 VERSION -This document describes MCE::Core version 1.888 +This document describes MCE::Core version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Core/Input/Generator.pm b/lib/MCE/Core/Input/Generator.pm index c1a3f7c..5eb06ca 100644 --- a/lib/MCE/Core/Input/Generator.pm +++ b/lib/MCE/Core/Input/Generator.pm @@ -15,7 +15,7 @@ package MCE::Core::Input::Generator; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -220,7 +220,7 @@ MCE::Core::Input::Generator - Sequence of numbers (for task_id > 0) =head1 VERSION -This document describes MCE::Core::Input::Generator version 1.888 +This document describes MCE::Core::Input::Generator version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Handle.pm b/lib/MCE/Core/Input/Handle.pm index c7865f5..cb6ff04 100644 --- a/lib/MCE/Core/Input/Handle.pm +++ b/lib/MCE/Core/Input/Handle.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Handle; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -278,7 +278,7 @@ MCE::Core::Input::Handle - File path and Scalar reference input reader =head1 VERSION -This document describes MCE::Core::Input::Handle version 1.888 +This document describes MCE::Core::Input::Handle version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Iterator.pm b/lib/MCE/Core/Input/Iterator.pm index 694dd8e..0734650 100644 --- a/lib/MCE/Core/Input/Iterator.pm +++ b/lib/MCE/Core/Input/Iterator.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Iterator; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -129,7 +129,7 @@ MCE::Core::Input::Iterator - Iterator reader =head1 VERSION -This document describes MCE::Core::Input::Iterator version 1.888 +This document describes MCE::Core::Input::Iterator version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Request.pm b/lib/MCE/Core/Input/Request.pm index 2143b0b..fb4b00b 100644 --- a/lib/MCE/Core/Input/Request.pm +++ b/lib/MCE/Core/Input/Request.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Request; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -200,7 +200,7 @@ MCE::Core::Input::Request - Array reference and Glob reference input reader =head1 VERSION -This document describes MCE::Core::Input::Request version 1.888 +This document describes MCE::Core::Input::Request version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Input/Sequence.pm b/lib/MCE/Core/Input/Sequence.pm index 6477891..7955709 100644 --- a/lib/MCE/Core/Input/Sequence.pm +++ b/lib/MCE/Core/Input/Sequence.pm @@ -14,7 +14,7 @@ package MCE::Core::Input::Sequence; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -229,7 +229,7 @@ MCE::Core::Input::Sequence - Sequence of numbers (for task_id == 0) =head1 VERSION -This document describes MCE::Core::Input::Sequence version 1.888 +This document describes MCE::Core::Input::Sequence version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Manager.pm b/lib/MCE/Core/Manager.pm index 0305eb6..7c40b17 100644 --- a/lib/MCE/Core/Manager.pm +++ b/lib/MCE/Core/Manager.pm @@ -14,7 +14,7 @@ package MCE::Core::Manager; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -1041,7 +1041,7 @@ MCE::Core::Manager - Core methods for the manager process =head1 VERSION -This document describes MCE::Core::Manager version 1.888 +This document describes MCE::Core::Manager version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Validation.pm b/lib/MCE/Core/Validation.pm index b2e2c4a..3a0b816 100644 --- a/lib/MCE/Core/Validation.pm +++ b/lib/MCE/Core/Validation.pm @@ -14,7 +14,7 @@ package MCE::Core::Validation; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## Items below are folded into MCE. @@ -402,7 +402,7 @@ MCE::Core::Validation - Core validation methods for Many-Core Engine =head1 VERSION -This document describes MCE::Core::Validation version 1.888 +This document describes MCE::Core::Validation version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Core/Worker.pm b/lib/MCE/Core/Worker.pm index 6e5b625..8562fbd 100644 --- a/lib/MCE/Core/Worker.pm +++ b/lib/MCE/Core/Worker.pm @@ -14,7 +14,7 @@ package MCE::Core::Worker; use strict; use warnings; -our $VERSION = '1.888'; +our $VERSION = '1.889'; my $_tid = $INC{'threads.pm'} ? threads->tid() : 0; @@ -738,7 +738,7 @@ MCE::Core::Worker - Core methods for the worker process =head1 VERSION -This document describes MCE::Core::Worker version 1.888 +This document describes MCE::Core::Worker version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Examples.pod b/lib/MCE/Examples.pod index ccd798f..2d8e2d7 100644 --- a/lib/MCE/Examples.pod +++ b/lib/MCE/Examples.pod @@ -5,7 +5,7 @@ MCE::Examples - Various examples and demonstrations =head1 VERSION -This document describes MCE::Examples version 1.888 +This document describes MCE::Examples version 1.889 =head1 INCLUDED WITH THE DISTRIBUTION diff --git a/lib/MCE/Flow.pm b/lib/MCE/Flow.pm index 2249424..e5c6330 100644 --- a/lib/MCE/Flow.pm +++ b/lib/MCE/Flow.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -482,7 +482,7 @@ MCE::Flow - Parallel flow model for building creative applications =head1 VERSION -This document describes MCE::Flow version 1.888 +This document describes MCE::Flow version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Grep.pm b/lib/MCE/Grep.pm index 39a94d6..37b6461 100644 --- a/lib/MCE/Grep.pm +++ b/lib/MCE/Grep.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -453,7 +453,7 @@ MCE::Grep - Parallel grep model similar to the native grep function =head1 VERSION -This document describes MCE::Grep version 1.888 +This document describes MCE::Grep version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Loop.pm b/lib/MCE/Loop.pm index 3acaee5..59e5342 100644 --- a/lib/MCE/Loop.pm +++ b/lib/MCE/Loop.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -364,7 +364,7 @@ MCE::Loop - MCE model for building parallel loops =head1 VERSION -This document describes MCE::Loop version 1.888 +This document describes MCE::Loop version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Map.pm b/lib/MCE/Map.pm index dd78670..b3e62fe 100644 --- a/lib/MCE/Map.pm +++ b/lib/MCE/Map.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -453,7 +453,7 @@ MCE::Map - Parallel map model similar to the native map function =head1 VERSION -This document describes MCE::Map version 1.888 +This document describes MCE::Map version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Mutex.pm b/lib/MCE/Mutex.pm index 9ab4fb4..3a937e5 100644 --- a/lib/MCE/Mutex.pm +++ b/lib/MCE/Mutex.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -64,7 +64,7 @@ MCE::Mutex - Locking for Many-Core Engine =head1 VERSION -This document describes MCE::Mutex version 1.888 +This document describes MCE::Mutex version 1.889 =head1 SYNOPSIS @@ -175,6 +175,13 @@ implementations. Current API available since 1.822. +=head2 $guard = $mutex->guard_lock ( void ) + +This method calls C and returns a guard object. When the guard object is +destroyed, it automatically calls C. + +Current API available since 1.889. + =head2 $mutex->unlock ( void ) Releases the lock. A held lock by an exiting process or thread is released diff --git a/lib/MCE/Mutex/Channel.pm b/lib/MCE/Mutex/Channel.pm index 60d08c2..80fa9c5 100644 --- a/lib/MCE/Mutex/Channel.pm +++ b/lib/MCE/Mutex/Channel.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use if $^O eq 'MSWin32', 'threads'; use if $^O eq 'MSWin32', 'threads::shared'; @@ -29,9 +29,15 @@ sub CLONE { $tid = threads->tid if $INC{'threads.pm'}; } +sub MCE::Mutex::Channel::_guard::DESTROY { + my ($pid, $obj) = @{ $_[0] }; + CORE::syswrite($obj->{_w_sock}, '0'), $obj->{ $pid } = 0 if $obj->{ $pid }; + + return; +} + sub DESTROY { my ($pid, $obj) = ($tid ? $$ .'.'. $tid : $$, @_); - CORE::syswrite($obj->{_w_sock}, '0'), $obj->{$pid } = 0 if $obj->{$pid }; CORE::syswrite($obj->{_r_sock}, '0'), $obj->{$pid.'b'} = 0 if $obj->{$pid.'b'}; @@ -90,14 +96,20 @@ sub new { sub lock { my ($pid, $obj) = ($tid ? $$ .'.'. $tid : $$, shift); - CORE::lock($obj->{_t_lock}), MCE::Util::_sock_ready($obj->{_r_sock}) - if $is_MSWin32; - MCE::Util::_sysread($obj->{_r_sock}, my($b), 1), $obj->{ $pid } = 1 - unless $obj->{ $pid }; + unless ($obj->{ $pid }) { + CORE::lock($obj->{_t_lock}), MCE::Util::_sock_ready($obj->{_r_sock}) + if $is_MSWin32; + MCE::Util::_sysread($obj->{_r_sock}, my($b), 1), $obj->{ $pid } = 1; + } return; } +sub guard_lock { + &lock(@_); + bless([ $tid ? $$ .'.'. $tid : $$, $_[0] ], MCE::Mutex::Channel::_guard::); +} + *lock_exclusive = \&lock; *lock_shared = \&lock; @@ -117,17 +129,16 @@ sub synchronize { return unless ref($code) eq 'CODE'; # lock, run, unlock - inlined for performance - CORE::lock($obj->{_t_lock}), MCE::Util::_sock_ready($obj->{_r_sock}) - if $is_MSWin32; - MCE::Util::_sysread($obj->{_r_sock}, $b, 1), $obj->{ $pid } = 1 - unless $obj->{ $pid }; - + my $guard = bless([ $pid, $obj ], MCE::Mutex::Channel::_guard::); + unless ($obj->{ $pid }) { + CORE::lock($obj->{_t_lock}), MCE::Util::_sock_ready($obj->{_r_sock}) + if $is_MSWin32; + MCE::Util::_sysread($obj->{_r_sock}, $b, 1), $obj->{ $pid } = 1; + } (defined wantarray) ? @ret = wantarray ? $code->(@_) : scalar $code->(@_) : $code->(@_); - CORE::syswrite($obj->{_w_sock}, '0'), $obj->{ $pid } = 0; - return wantarray ? @ret : $ret[-1]; } @@ -176,7 +187,7 @@ MCE::Mutex::Channel - Mutex locking via a pipe or socket =head1 VERSION -This document describes MCE::Mutex::Channel version 1.888 +This document describes MCE::Mutex::Channel version 1.889 =head1 DESCRIPTION @@ -194,6 +205,8 @@ The API is described in L. =item lock_shared +=item guard_lock + =item unlock =item synchronize diff --git a/lib/MCE/Mutex/Channel2.pm b/lib/MCE/Mutex/Channel2.pm index 9d071ef..f72fe0c 100644 --- a/lib/MCE/Mutex/Channel2.pm +++ b/lib/MCE/Mutex/Channel2.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use if $^O eq 'MSWin32', 'threads'; use if $^O eq 'MSWin32', 'threads::shared'; @@ -28,6 +28,13 @@ sub CLONE { $tid = threads->tid() if $INC{'threads.pm'}; } +sub MCE::Mutex::Channel2::_guard::DESTROY { + my ($pid, $obj) = @{ $_[0] }; + CORE::syswrite($obj->{_r_sock}, '0'), $obj->{$pid.'b'} = 0 if $obj->{$pid.'b'}; + + return; +} + ############################################################################### ## ---------------------------------------------------------------------------- ## Public methods. @@ -56,14 +63,20 @@ sub new { sub lock2 { my ($pid, $obj) = ($tid ? $$ .'.'. $tid : $$, shift); - CORE::lock($obj->{_t_lock2}), MCE::Util::_sock_ready($obj->{_w_sock}) - if $is_MSWin32; - MCE::Util::_sysread($obj->{_w_sock}, my($b), 1), $obj->{ $pid.'b' } = 1 - unless $obj->{ $pid.'b' }; + unless ($obj->{ $pid.'b' }) { + CORE::lock($obj->{_t_lock2}), MCE::Util::_sock_ready($obj->{_w_sock}) + if $is_MSWin32; + MCE::Util::_sysread($obj->{_w_sock}, my($b), 1), $obj->{ $pid.'b' } = 1; + } return; } +sub guard_lock2 { + &lock2(@_); + bless([ $tid ? $$ .'.'. $tid : $$, $_[0] ], MCE::Mutex::Channel2::_guard::); +} + *lock_exclusive2 = \&lock2; *lock_shared2 = \&lock2; @@ -83,17 +96,16 @@ sub synchronize2 { return unless ref($code) eq 'CODE'; # lock, run, unlock - inlined for performance - CORE::lock($obj->{_t_lock2}), MCE::Util::_sock_ready($obj->{_w_sock}) - if $is_MSWin32; - MCE::Util::_sysread($obj->{_w_sock}, $b, 1), $obj->{ $pid.'b' } = 1 - unless $obj->{ $pid.'b' }; - + my $guard = bless([ $pid, $obj ], MCE::Mutex::Channel2::_guard::); + unless ($obj->{ $pid.'b' }) { + CORE::lock($obj->{_t_lock2}), MCE::Util::_sock_ready($obj->{_w_sock}) + if $is_MSWin32; + MCE::Util::_sysread($obj->{_w_sock}, $b, 1), $obj->{ $pid.'b' } = 1; + } (defined wantarray) ? @ret = wantarray ? $code->(@_) : scalar $code->(@_) : $code->(@_); - CORE::syswrite($obj->{_r_sock}, '0'), $obj->{ $pid.'b' } = 0; - return wantarray ? @ret : $ret[-1]; } @@ -142,7 +154,7 @@ MCE::Mutex::Channel2 - Provides two mutexes using a single channel =head1 VERSION -This document describes MCE::Mutex::Channel2 version 1.888 +This document describes MCE::Mutex::Channel2 version 1.889 =head1 DESCRIPTION @@ -171,6 +183,8 @@ The API is described in L. =item lock_shared +=item guard_lock + =item unlock =item synchronize @@ -191,6 +205,8 @@ The API is described in L. =item lock_shared2 +=item guard_lock2 + =item unlock2 =item synchronize2 diff --git a/lib/MCE/Mutex/Flock.pm b/lib/MCE/Mutex/Flock.pm index 59582ee..47121d6 100644 --- a/lib/MCE/Mutex/Flock.pm +++ b/lib/MCE/Mutex/Flock.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; use base 'MCE::Mutex'; use Fcntl ':flock'; @@ -24,9 +24,15 @@ sub CLONE { $tid = threads->tid() if $INC{'threads.pm'}; } +sub MCE::Mutex::Flock::_guard::DESTROY { + my ($pid, $obj) = @{ $_[0] }; + CORE::flock ($obj->{_fh}, LOCK_UN), $obj->{ $pid } = 0 if $obj->{ $pid }; + + return; +} + sub DESTROY { my ($pid, $obj) = ($tid ? $$ .'.'. $tid : $$, @_); - $obj->unlock(), close(delete $obj->{_fh}) if $obj->{ $pid }; unlink $obj->{path} if ($obj->{_init} && $obj->{_init} eq $pid); @@ -123,6 +129,11 @@ sub lock { return; } +sub guard_lock { + &lock(@_); + bless([ $tid ? $$ .'.'. $tid : $$, $_[0] ], MCE::Mutex::Flock::_guard::); +} + *lock_exclusive = \&lock; sub lock_shared { @@ -153,15 +164,14 @@ sub synchronize { $obj->_open() unless exists $obj->{ $pid }; # lock, run, unlock - inlined for performance - CORE::flock ($obj->{_fh}, LOCK_EX), $obj->{ $pid } = 1 - unless $obj->{ $pid }; - + my $guard = bless([ $pid, $obj ], MCE::Mutex::Flock::_guard::); + unless ($obj->{ $pid }) { + CORE::flock ($obj->{_fh}, LOCK_EX), $obj->{ $pid } = 1; + } (defined wantarray) ? @ret = wantarray ? $code->(@_) : scalar $code->(@_) : $code->(@_); - CORE::flock ($obj->{_fh}, LOCK_UN), $obj->{ $pid } = 0; - return wantarray ? @ret : $ret[-1]; } @@ -201,7 +211,7 @@ MCE::Mutex::Flock - Mutex locking via Fcntl =head1 VERSION -This document describes MCE::Mutex::Flock version 1.888 +This document describes MCE::Mutex::Flock version 1.889 =head1 DESCRIPTION @@ -219,6 +229,8 @@ The API is described in L. =item lock_shared +=item guard_lock + =item unlock =item synchronize diff --git a/lib/MCE/Queue.pm b/lib/MCE/Queue.pm index 962e923..c7f88f4 100644 --- a/lib/MCE/Queue.pm +++ b/lib/MCE/Queue.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (Subroutines::ProhibitExplicitReturnUndef) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -1506,7 +1506,7 @@ MCE::Queue - Hybrid (normal and priority) queues =head1 VERSION -This document describes MCE::Queue version 1.888 +This document describes MCE::Queue version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Relay.pm b/lib/MCE/Relay.pm index 70b1e3f..531f77f 100644 --- a/lib/MCE/Relay.pm +++ b/lib/MCE/Relay.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized numeric ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -368,7 +368,7 @@ MCE::Relay - Extends Many-Core Engine with relay capabilities =head1 VERSION -This document describes MCE::Relay version 1.888 +This document describes MCE::Relay version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Signal.pm b/lib/MCE/Signal.pm index a2ed0e3..8c75ae3 100644 --- a/lib/MCE/Signal.pm +++ b/lib/MCE/Signal.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized once ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) @@ -128,6 +128,9 @@ sub _make_tmpdir { $_tmp_base_dir = $ENV{TEMP}; } } + elsif (! -w '/tmp' && -e $ENV{TMPDIR} && -d $ENV{TMPDIR} && -w _) { + $_tmp_base_dir = $ENV{TMPDIR}; + } else { $_tmp_base_dir = ($_use_dev_shm && -d '/dev/shm' && -w _) ? '/dev/shm' : '/tmp'; @@ -442,7 +445,7 @@ MCE::Signal - Temporary directory creation/cleanup and signal handling =head1 VERSION -This document describes MCE::Signal version 1.888 +This document describes MCE::Signal version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Step.pm b/lib/MCE/Step.pm index 13326a1..e34e2f5 100644 --- a/lib/MCE/Step.pm +++ b/lib/MCE/Step.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -700,7 +700,7 @@ MCE::Step - Parallel step model for building creative steps =head1 VERSION -This document describes MCE::Step version 1.888 +This document describes MCE::Step version 1.889 =head1 DESCRIPTION diff --git a/lib/MCE/Stream.pm b/lib/MCE/Stream.pm index d143344..19ecd31 100644 --- a/lib/MCE/Stream.pm +++ b/lib/MCE/Stream.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) ## no critic (Subroutines::ProhibitSubroutinePrototypes) @@ -678,7 +678,7 @@ MCE::Stream - Parallel stream model for chaining multiple maps and greps =head1 VERSION -This document describes MCE::Stream version 1.888 +This document describes MCE::Stream version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Subs.pm b/lib/MCE/Subs.pm index 2dd1ca6..7326198 100644 --- a/lib/MCE/Subs.pm +++ b/lib/MCE/Subs.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (Subroutines::ProhibitSubroutinePrototypes) ## no critic (TestingAndDebugging::ProhibitNoStrict) @@ -204,7 +204,7 @@ MCE::Subs - Exports functions mapped directly to MCE methods =head1 VERSION -This document describes MCE::Subs version 1.888 +This document describes MCE::Subs version 1.889 =head1 SYNOPSIS diff --git a/lib/MCE/Util.pm b/lib/MCE/Util.pm index aefb40e..22c2ba6 100644 --- a/lib/MCE/Util.pm +++ b/lib/MCE/Util.pm @@ -11,7 +11,7 @@ use warnings; no warnings qw( threads recursion uninitialized numeric ); -our $VERSION = '1.888'; +our $VERSION = '1.889'; ## no critic (BuiltinFunctions::ProhibitStringyEval) @@ -61,12 +61,16 @@ sub get_ncpu { OS_CHECK: { local $_ = lc $^O; - /linux/ && do { + /linux|android/ && do { my ( $count, $fh ); if ( open $fh, '<', '/proc/stat' ) { $count = grep { /^cpu\d/ } <$fh>; close $fh; } + elsif ( open $fh, '<', '/proc/cpuinfo' ) { + $count = grep { /^processor/ } <$fh>; + close $fh; + } $ncpu = $count if $count; last OS_CHECK; }; @@ -244,7 +248,7 @@ sub _sock_pair { AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n"; } - if ($^O ne 'aix' && $^O ne 'linux') { + if ($^O !~ /aix|linux|android/) { setsockopt($_obj->{$_r_sock}[$_i], SOL_SOCKET, SO_SNDBUF, int $_size); setsockopt($_obj->{$_r_sock}[$_i], SOL_SOCKET, SO_RCVBUF, int $_size); setsockopt($_obj->{$_w_sock}[$_i], SOL_SOCKET, SO_SNDBUF, int $_size); @@ -267,7 +271,7 @@ sub _sock_pair { AF_UNIX, Socket::SOCK_STREAM(), 0 ) or die "socketpair: $!\n"; } - if ($^O ne 'aix' && $^O ne 'linux') { + if ($^O !~ /aix|linux|android/) { setsockopt($_obj->{$_r_sock}, SOL_SOCKET, SO_SNDBUF, int $_size); setsockopt($_obj->{$_r_sock}, SOL_SOCKET, SO_RCVBUF, int $_size); setsockopt($_obj->{$_w_sock}, SOL_SOCKET, SO_SNDBUF, int $_size); @@ -431,7 +435,7 @@ MCE::Util - Utility functions =head1 VERSION -This document describes MCE::Util version 1.888 +This document describes MCE::Util version 1.889 =head1 SYNOPSIS diff --git a/xt/channel2_lock.t b/xt/channel2_lock.t index 69e3746..4e66168 100644 --- a/xt/channel2_lock.t +++ b/xt/channel2_lock.t @@ -11,30 +11,50 @@ my $mutex = MCE::Mutex->new( impl => 'Channel2' ); is($mutex->impl(), 'Channel2', 'implementation name'); -sub task { +sub task1a { $mutex->lock_exclusive; sleep(1) for 1..2; $mutex->unlock; } -sub task2 { - $mutex->lock_exclusive2; +sub task1b { + my $guard = $mutex->guard_lock; sleep(1) for 1..2; - $mutex->unlock2; } -sub spawn { +sub spawn1 { + my ($i) = @_; my $pid = fork; - task(), exit() if $pid == 0; + if ($pid == 0) { + task1a() if ($i % 2 != 0); + task1b() if ($i % 2 == 0); + exit(); + } return $pid; } + +sub task2a { + $mutex->lock_exclusive2; + sleep(1) for 1..2; + $mutex->unlock2; +} +sub task2b { + my $guard = $mutex->guard_lock2; + sleep(1) for 1..2; +} + sub spawn2 { + my ($i) = @_; my $pid = fork; - task2(), exit() if $pid == 0; + if ($pid == 0) { + task2a() if ($i % 2 != 0); + task2b() if ($i % 2 == 0); + exit(); + } return $pid; } my $start = time; -my @pids = map { spawn(), spawn2() } 1..3; +my @pids = map { spawn1($_), spawn2($_) } 1..3; waitpid($_, 0) for @pids; diff --git a/xt/channel_lock.t b/xt/channel_lock.t index 88605c1..968fa47 100644 --- a/xt/channel_lock.t +++ b/xt/channel_lock.t @@ -11,19 +11,29 @@ my $mutex = MCE::Mutex->new( impl => 'Channel' ); is($mutex->impl(), 'Channel', 'implementation name'); -sub task { +sub task1 { $mutex->lock_exclusive; sleep(1) for 1..2; $mutex->unlock; } +sub task2 { + my $guard = $mutex->guard_lock; + sleep(1) for 1..2; +} + sub spawn { + my ($i) = @_; my $pid = fork; - task(), exit() if $pid == 0; + if ($pid == 0) { + task1() if ($i % 2 != 0); + task2() if ($i % 2 == 0); + exit(); + } return $pid; } my $start = time; -my @pids = map { spawn() } 1..3; +my @pids = map { spawn($_) } 1..3; waitpid($_, 0) for @pids; diff --git a/xt/flock_lock.t b/xt/flock_lock.t index f4df863..2e08724 100644 --- a/xt/flock_lock.t +++ b/xt/flock_lock.t @@ -11,19 +11,29 @@ my $mutex = MCE::Mutex->new( impl => 'Flock' ); is($mutex->impl(), 'Flock', 'implementation name'); -sub task { +sub task1 { $mutex->lock_exclusive; sleep 1; $mutex->unlock; } +sub task2 { + my $guard = $mutex->guard_lock; + sleep 1; +} + sub spawn { + my ($i) = @_; my $pid = fork; - task(), exit() if $pid == 0; + if ($pid == 0) { + task1() if ($i % 2 != 0); + task2() if ($i % 2 == 0); + exit(); + } return $pid; } my $start = time; -my @pids = map { spawn() } 1..4; +my @pids = map { spawn($_) } 1..4; waitpid($_, 0) for @pids; -- cgit v1.2.3