service: avoid taking another lock in the usual case

pull/607/head
David Wilson 6 years ago
parent 50bfe4c746
commit e93762b3db

@ -547,15 +547,18 @@ class Pool(object):
invoker.service.on_shutdown() invoker.service.on_shutdown()
def get_invoker(self, name, msg): def get_invoker(self, name, msg):
self._lock.acquire() invoker = self._invoker_by_name.get(name)
try: if invoker is None:
invoker = self._invoker_by_name.get(name) # Avoid acquiring lock if possible.
if not invoker: self._lock.acquire()
service = self._activator.activate(self, name, msg) try:
invoker = service.invoker_class(service=service) invoker = self._invoker_by_name.get(name)
self._invoker_by_name[name] = invoker if not invoker:
finally: service = self._activator.activate(self, name, msg)
self._lock.release() invoker = service.invoker_class(service=service)
self._invoker_by_name[name] = invoker
finally:
self._lock.release()
return invoker return invoker

Loading…
Cancel
Save