org.qbicc.plugin.threadlocal.ThreadLocals Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qbicc-plugin-thread-local Show documentation
Show all versions of qbicc-plugin-thread-local Show documentation
Support for true thread-local fields
package org.qbicc.plugin.threadlocal;
import java.util.concurrent.ConcurrentHashMap;
import org.qbicc.context.AttachmentKey;
import org.qbicc.context.CompilationContext;
import org.qbicc.type.definition.element.FieldElement;
/**
*
*/
public final class ThreadLocals {
private static final AttachmentKey KEY = new AttachmentKey<>();
private final CompilationContext ctxt;
private final ConcurrentHashMap threadLocalFields = new ConcurrentHashMap<>();
private ThreadLocals(final CompilationContext ctxt) {
this.ctxt = ctxt;
}
public static ThreadLocals get(final CompilationContext ctxt) {
ThreadLocals nativeInfo = ctxt.getAttachment(KEY);
if (nativeInfo == null) {
ThreadLocals appearing = ctxt.putAttachmentIfAbsent(KEY, nativeInfo = new ThreadLocals(ctxt));
if (appearing != null) {
nativeInfo = appearing;
}
}
return nativeInfo;
}
public FieldElement getThreadLocalField(FieldElement staticField) {
return threadLocalFields.get(staticField);
}
void registerThreadLocalField(FieldElement staticField, FieldElement injectedField) {
threadLocalFields.put(staticField, injectedField);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy