-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure CTM's metadataCache is thread-safe
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...va/org/embeddedt/modernfix/forge/mixin/bugfix/ctm_resourceutil_cme/ResourceUtilMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.embeddedt.modernfix.forge.mixin.bugfix.ctm_resourceutil_cme; | ||
|
||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin; | ||
import org.embeddedt.modernfix.annotation.RequiresMod; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import team.chisel.ctm.client.util.ResourceUtil; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
@Mixin(ResourceUtil.class) | ||
@RequiresMod("ctm") | ||
@ClientOnlyMixin | ||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
public class ResourceUtilMixin { | ||
@Shadow @Final @Mutable | ||
private static Map metadataCache; | ||
|
||
/** | ||
* @author embeddedt | ||
* @reason quick fix to prevent rare CMEs | ||
*/ | ||
@Inject(method = "<clinit>", at = @At("RETURN")) | ||
private static void synchronizeMetadataCache(CallbackInfo ci) { | ||
if(!(metadataCache instanceof ConcurrentMap)) | ||
metadataCache = Collections.synchronizedMap(metadataCache); | ||
} | ||
} |