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