Skip to content

Instantly share code, notes, and snippets.

/mutex.diff Secret

Created February 16, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fa658c590000dcda92b6 to your computer and use it in GitHub Desktop.
Save anonymous/fa658c590000dcda92b6 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/IOLoop.pm b/lib/Mojo/IOLoop.pm
index dddfe26..4aa0603 100644
--- a/lib/Mojo/IOLoop.pm
+++ b/lib/Mojo/IOLoop.pm
@@ -160,17 +160,12 @@ sub _accepting {
# Check if we have acceptors
my $acceptors = $self->{acceptors} ||= {};
- return $self->_remove(delete $self->{accept}) unless keys %$acceptors;
# Check connection limit
my $i = keys %{$self->{connections}};
my $max = $self->max_connections;
return unless $i < $max;
- # Acquire accept mutex
- if (my $cb = $self->lock) { return unless $cb->(!$i) }
- $self->_remove(delete $self->{accept});
-
# Check if multi-accept is desirable
my $multi = $self->multi_accept;
$_->multi_accept($max < $multi ? 1 : $multi)->start for values %$acceptors;
@@ -203,7 +198,7 @@ sub _not_accepting {
sub _recurring {
my $self = shift;
- $self->{accept} ||= $self->recurring($self->accept_interval => \&_accepting);
+ $self->_accepting;
$self->{stop} ||= $self->recurring(1 => \&_stop);
}
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm
index d3f39a6..ae38f79 100644
--- a/lib/Mojo/Server/Prefork.pm
+++ b/lib/Mojo/Server/Prefork.pm
@@ -163,25 +163,7 @@ sub _spawn {
# Accept mutex
weaken $self;
- my $loop = $self->ioloop->lock(
- sub {
-
- # Non-blocking
- return flock $handle, LOCK_EX | LOCK_NB unless shift;
-
- # Blocking ("ualarm" can't be imported on Windows)
- my $lock;
- eval {
- local $SIG{ALRM} = sub { die "alarm\n" };
- my $old = Time::HiRes::ualarm $self->lock_timeout * 1000000;
- $lock = flock $handle, LOCK_EX;
- Time::HiRes::ualarm $old;
- 1;
- } or $lock = $@ eq "alarm\n" ? 0 : die $@;
- return $lock;
- }
- );
- $loop->unlock(sub { flock $handle, LOCK_UN });
+ my $loop = $self->ioloop;
# Heartbeat messages
my $cb = sub { $self->_heartbeat(shift->max_connections ? 0 : 1) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment