This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Thread::Queue 3.07
authorJerry D. Hedden <jdhedden@solydxk>
Fri, 23 Oct 2015 23:55:17 +0000 (19:55 -0400)
committerJames E Keenan <jkeenan@cpan.org>
Sat, 24 Oct 2015 13:41:41 +0000 (09:41 -0400)
Committer: Add additional email address for contributor.

Porting/Maintainers.pl
Porting/checkAUTHORS.pl
dist/Thread-Queue/lib/Thread/Queue.pm
dist/Thread-Queue/t/11_limit.t

index f51a188..97442a5 100755 (executable)
@@ -1153,7 +1153,7 @@ use File::Glob qw(:case);
     # correct for this (and Thread::Semaphore, threads, and threads::shared)
     # to be under dist/ rather than cpan/
     'Thread::Queue' => {
-        'DISTRIBUTION' => 'JDHEDDEN/Thread-Queue-3.06.tar.gz',
+        'DISTRIBUTION' => 'JDHEDDEN/Thread-Queue-3.07.tar.gz',
         'FILES'        => q[dist/Thread-Queue],
         'EXCLUDED'     => [
             qr{^examples/},
index 155b8d6..9b161d2 100755 (executable)
@@ -663,6 +663,7 @@ jdhedden\100cpan.org                    jerry\100hedden.us
 +                                       jdhedden\100gmail.com
 +                                       jdhedden\100yahoo.com
 +                                       jhedden\100pn100-02-2-356p.corp.bloomberg.com
++                                       jdhedden\100solydxk
 jeremy\100zawodny.com                   jzawodn\100wcnet.org
 jesse\100sig.bsh.com                    jesse\100ginger
 jfriedl\100yahoo.com                    jfriedl\100yahoo-inc.com
index b1842ca..5a031ff 100644 (file)
@@ -3,7 +3,7 @@ package Thread::Queue;
 use strict;
 use warnings;
 
-our $VERSION = '3.06';
+our $VERSION = '3.07';
 $VERSION = eval $VERSION;
 
 use threads::shared 1.21;
@@ -80,7 +80,7 @@ sub dequeue
 
     # Wait for requisite number of items
     cond_wait(%$self) while ((@$queue < $count) && ! $$self{'ENDED'});
-    cond_signal(%$self) if ((@$queue > $count) || $$self{'ENDED'});
+    cond_signal(%$self) if ((@$queue >= $count) || $$self{'ENDED'});
 
     # If no longer blocking, try getting whatever is left on the queue
     return $self->dequeue_nb($count) if ($$self{'ENDED'});
@@ -135,7 +135,7 @@ sub dequeue_timed
     while ((@$queue < $count) && ! $$self{'ENDED'}) {
         last if (! cond_timedwait(%$self, $timeout));
     }
-    cond_signal(%$self) if ((@$queue > $count) || $$self{'ENDED'});
+    cond_signal(%$self) if ((@$queue >= $count) || $$self{'ENDED'});
 
     # Get whatever we need off the queue if available
     return $self->dequeue_nb($count);
@@ -304,7 +304,7 @@ Thread::Queue - Thread-safe queues
 
 =head1 VERSION
 
-This document describes Thread::Queue version 3.06
+This document describes Thread::Queue version 3.07
 
 =head1 SYNOPSIS
 
@@ -488,10 +488,9 @@ C<limit> does not prevent enqueuing items beyond that count:
     my $q = Thread::Queue->new(1, 2);
     $q->limit = 4;
     $q->enqueue(3, 4, 5);   # Does not block
-    $q->enqueue(6);         # Blocks until at least 2 items are
-                            # dequeued
-    my $size = $q->limit;   # Returns the current limit (may return
-                            # 'undef')
+    $q->enqueue(6);         # Blocks until at least 2 items are dequeued
+
+    my $size = $q->limit;   # Returns the current limit (may return 'undef')
     $q->limit = 0;          # Queue size is now unlimited
 
 =item ->end()
@@ -515,8 +514,7 @@ while it is being examined and/or changed, L<lock|threads::shared/"lock
 VARIABLE"> the queue inside a local block:
 
     {
-        lock($q);   # Keep other threads from changing the queue's
-                    # contents
+        lock($q);   # Keep other threads from changing the queue's contents
         my $item = $q->peek();
         if ($item ...) {
             ...
@@ -595,11 +593,11 @@ of the queue (similar to C<dequeue_nb>) if the count overlaps the head of the
 queue from the specified position (i.e. if queue size + index + count is
 greater than zero):
 
- $q->enqueue(qw/foo bar baz/);
my @nada = $q->extract(-6, 2); # Returns ()         - (3+(-6)+2) <= 0
my @some = $q->extract(-6, 4); # Returns (foo)      - (3+(-6)+4) > 0
-                                # Queue now contains:  bar, baz
-my @rest = $q->extract(-3, 4);  # Returns (bar, baz) - (2+(-3)+4) > 0
   $q->enqueue(qw/foo bar baz/);
   my @nada = $q->extract(-6, 2);   # Returns ()         - (3+(-6)+2) <= 0
   my @some = $q->extract(-6, 4);   # Returns (foo)      - (3+(-6)+4) > 0
+                                     # Queue now contains:  bar, baz
+    my @rest = $q->extract(-3, 4);   # Returns (bar, baz) - (2+(-3)+4) > 0
 
 =back
 
index a2ab918..1bd88b3 100644 (file)
@@ -44,10 +44,6 @@ my $th = threads->create( sub {
     # (6) Get reports from main
     my @items = $rpt->dequeue(5);
     is_deeply(\@items, [4, 3, 4, 3, 'go'], 'Queue reports');
-
-    # Dequeue all items
-    @items = $q->dequeue_nb(99);
-    is_deeply(\@items, [5, 'foo', 6, 7], 'Queue items');
 });
 
 # (2) Read queue limit from thread
@@ -80,16 +76,20 @@ $rpt->enqueue($q->pending);
 # Read an item from queue
 $item = $q->dequeue();
 is($item, 3, 'Dequeued item 3');
-# q = (3, 4, 5); r = (4)
+# q = (4, 5, 'foo'); r = (4, 3, 4)
 # Report back the queue count
 $rpt->enqueue($q->pending);
 # q = (4, 5, 'foo'); r = (4, 3, 4, 3)
 
-# Read an item from queue
-$item = $q->dequeue();
-is($item, 4, 'Dequeued item 4');
+# Read all items from queue
+my @item = $q->dequeue(3);
+is_deeply(\@item, [4, 5, 'foo'], 'Dequeued 3 items');
 # Thread is now unblocked
 
+@item = $q->dequeue(2);
+is_deeply(\@item, [6, 7], 'Dequeued 2 items');
+
+# Thread is now unblocked
 # Handshake with thread
 $rpt->enqueue('go');