Skip to content
Permalink
Browse files

service: avoid taking another lock in the usual case

  • Loading branch information...
dw committed Feb 25, 2019
1 parent 50bfe4c commit e93762b3db65411efb3e6dcb21b4d4525e91344d
Showing with 12 additions and 9 deletions.
  1. +12 −9 mitogen/service.py
@@ -547,15 +547,18 @@ def join(self):
invoker.service.on_shutdown()

def get_invoker(self, name, msg):
self._lock.acquire()
try:
invoker = self._invoker_by_name.get(name)
if not invoker:
service = self._activator.activate(self, name, msg)
invoker = service.invoker_class(service=service)
self._invoker_by_name[name] = invoker
finally:
self._lock.release()
invoker = self._invoker_by_name.get(name)
if invoker is None:
# Avoid acquiring lock if possible.
self._lock.acquire()
try:
invoker = self._invoker_by_name.get(name)
if not invoker:
service = self._activator.activate(self, name, msg)
invoker = service.invoker_class(service=service)
self._invoker_by_name[name] = invoker
finally:
self._lock.release()

return invoker

0 comments on commit e93762b

Please sign in to comment.
You can’t perform that action at this time.