// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.fastutil.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.concurrent.ThreadLocalRandom;
import sun.misc.Unsafe;

public class TLRUtil
{
    private static final Unsafe UNSAFE;
    private static final long PROBE;
    
    public static void localInit() {
        ThreadLocalRandom.current();
    }
    
    public static int getProbe() {
        return TLRUtil.UNSAFE.getInt(Thread.currentThread(), TLRUtil.PROBE);
    }
    
    public static int advanceProbe(int probe) {
        probe ^= probe << 13;
        probe ^= probe >>> 17;
        probe ^= probe << 5;
        TLRUtil.UNSAFE.putInt(Thread.currentThread(), TLRUtil.PROBE, probe);
        return probe;
    }
    
    static {
        Unsafe instance;
        try {
            final Field field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            instance = (Unsafe)field.get(null);
        }
        catch (final Exception e1) {
            try {
                final Constructor<Unsafe> c = Unsafe.class.getDeclaredConstructor((Class<?>[])new Class[0]);
                c.setAccessible(true);
                instance = c.newInstance(new Object[0]);
            }
            catch (final Exception e2) {
                throw SneakyThrow.sneakyThrow(e2);
            }
        }
        UNSAFE = instance;
        try {
            PROBE = TLRUtil.UNSAFE.objectFieldOffset(Thread.class.getDeclaredField("threadLocalRandomProbe"));
        }
        catch (final NoSuchFieldException t) {
            throw SneakyThrow.sneakyThrow(t);
        }
    }
}
