From 2288582aa86d56f6762d80930cc1ddaa02cfff1f Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 2 Jun 2016 05:26:54 -0400 Subject: [PATCH] Comment the locking mechanisms in ContextInfoManager Coverity didn't like our non-locking of the get() method. The lock is actually only needed for the registration/unregistration of retrievers, the get() can access the ConcurrentHashMap directly. Add a few comments to help explain this. Signed-off-by: Alexandre Montplaisir Signed-off-by: Mathieu Desnoyers --- .../lttng/ust/agent/context/ContextInfoManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/context/ContextInfoManager.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/context/ContextInfoManager.java index 86ded59b..7a8c80e9 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/context/ContextInfoManager.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/context/ContextInfoManager.java @@ -40,6 +40,10 @@ public final class ContextInfoManager { private final Map contextInfoRetrievers = new ConcurrentHashMap(); private final Map contextInforRetrieverRefs = new HashMap(); + /** + * Lock used to keep the two maps above in sync when retrievers are + * registered or unregistered. + */ private final Object retrieverLock = new Object(); /** Singleton class, constructor should not be accessed directly */ @@ -163,6 +167,13 @@ public final class ContextInfoManager { * was none */ public IContextInfoRetriever getContextInfoRetriever(String retrieverName) { + /* + * Note that this method does not take the retrieverLock, it lets + * concurrent threads access the ConcurrentHashMap directly. + * + * It's fine for a get() to happen during a registration or + * unregistration, it's first-come-first-serve. + */ return contextInfoRetrievers.get(retrieverName); } -- 2.34.1