package me.nallar.tickthreading.util.concurrent;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

import me.nallar.unsafe.UnsafeAccess;
import sun.misc.Unsafe;

// This class is manipulated by the patcher, MONITORENTER/EXIT instructions are used for performance reasons where possible.
public final class NativeMutex implements Lock {
	private static final Unsafe $ = UnsafeAccess.$;

	@Override
	public void lockInterruptibly() throws InterruptedException {
		$.monitorEnter(this);
	}

	@Override
	public void lock() {
		$.monitorEnter(this);
	}

	@Override
	public void unlock() {
		$.monitorExit(this);
	}

	@Override
	public boolean tryLock() {
		return $.tryMonitorEnter(this);
	}

	@Override
	public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
		throw new UnsupportedOperationException();
	}

	@Override
	public Condition newCondition() {
		throw new UnsupportedOperationException();
	}
}

@@ -243,134 +243,8 @@
 %0D%0A%0D%0A
-// This class is manipulated by the patcher, MONITORENTER/EXIT instructions are used for performance reasons where possible.%0D%0A
 publ
@@ -453,71 +453,401 @@
 %0A%0D%0A%09
-@Override%0D%0A%09public void lock() %7B%0D%0A%09%09$.monitorEnter(this);%0D%0A%09%7D%0D%0A
+/**%0D%0A%09 * If using NativeMutex.lock() on an object which is always an instance of NativeMutex,%0D%0A%09 * use the lockToSynchronized patch to improve performance.%0D%0A%09 */%0D%0A%09@Override%0D%0A%09public void lock() %7B%0D%0A%09%09$.monitorEnter(this);%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * If using NativeMutex.unlock() on an object which is always an instance of NativeMutex,%0D%0A%09 * use the lockToSynchronized patch to improve performance.%0D%0A%09 */
 %0D%0A%09@

Fix NativeMutex documentation.