From: Alexandre Montplaisir Date: Thu, 2 Jun 2016 09:26:54 +0000 (-0400) Subject: Comment the locking mechanisms in ContextInfoManager X-Git-Tag: v2.8.1~1 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2288582aa86d56f6762d80930cc1ddaa02cfff1f;p=lttng-ust.git 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 --- 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); }