Correct threads_mutex locking in main thread destruction.
[p5sagit/p5-mst-13.2.git] / Thread / Semaphore.pm
index d34d6bd..9e5852f 100644 (file)
@@ -10,14 +10,16 @@ sub new {
 sub down {
     use attrs qw(locked method);
     my $s = shift;
-    cond_wait $s until $$s > 0;
-    $$s--;
+    my $inc = @_ ? shift : 1;
+    cond_wait $s until $$s >= $inc;
+    $$s -= $inc;
 }
 
 sub up {
     use attrs qw(locked method);
     my $s = shift;
-    $$s++ > 0 and cond_broadcast $s;
+    my $inc = @_ ? shift : 1;
+    ($$s += $inc) > 0 and cond_broadcast $s;
 }
 
 1;