[Bps-public-commit] r15457 - in IPC-PubSub: lib/IPC/PubSub/Cache

alexmv at bestpractical.com alexmv at bestpractical.com
Mon Aug 25 20:04:49 EDT 2008


Author: alexmv
Date: Mon Aug 25 20:04:49 2008
New Revision: 15457

Modified:
   IPC-PubSub/   (props changed)
   IPC-PubSub/lib/IPC/PubSub/Cache/Memcached.pm

Log:
 r36408 at kohr-ah:  chmrr | 2008-08-25 20:01:54 -0400
  * Force Cache::Memcache queries to never timeout, so we don't get a
    lock but not know it, and deadlock
  * When we lock, lock with the current PID, mostly for debugging
  * Useful return values for lock and unlock


Modified: IPC-PubSub/lib/IPC/PubSub/Cache/Memcached.pm
==============================================================================
--- IPC-PubSub/lib/IPC/PubSub/Cache/Memcached.pm	(original)
+++ IPC-PubSub/lib/IPC/PubSub/Cache/Memcached.pm	Mon Aug 25 20:04:49 2008
@@ -10,6 +10,8 @@
     my $namespace   = shift || $class;
     my $config      = shift || $class->default_config($namespace);
     my $mem = Cache::Memcached->new($config);
+    # Force our connection to never timeout on selects
+    $mem->{select_timeout} = undef;
     bless(\$mem, $class);
 }
 
@@ -63,14 +65,18 @@
 sub lock {
     my ($self, $key) = @_;
     for my $i (1..100) {
-        return if $$self->add("lock:$key" => 1);
+        return 1 if $$self->add("lock:$key" => $$);
         Time::HiRes::usleep(rand(250000)+250000);
     }
+    return 0;
 }
 
 sub unlock {
     my ($self, $chan) = @_;
-    $$self->delete("lock:$chan");
+    my $timeout = $$self->{'select_timeout'};
+    $$self->{'select_timeout'} = undef;
+    return 1 if $$self->delete("lock:$chan");
+    return 0;
 }
 
 sub add_publisher {



More information about the Bps-public-commit mailing list