func (tm *TryRWMutex) Unlock() {
	tm.mu.Unlock()
	atomic.AddUint64(&tm.lock, ^(writeOffset - 1))
}
Unlock releases a lock on the mutex.
package sync
import (
	"runtime"
	"sync"
	"sync/atomic"
)
const (
	readOffset  = uint64(1)
	tryMask     = uint64(1099511627775)  
	tryOffset   = uint64(1 << 40)
	writeOffset = uint64(1 << 20)
)
type TryRWMutex struct {
	lock uint64
	mu   sync.RWMutex
}
func (tm *TryRWMutex) Lock() {
	v := atomic.AddUint64(&tm.lock, writeOffset)
	for v > tryOffset {
		runtime.Gosched()
		v = atomic.LoadUint64(&tm.lock)
	}
	tm.mu.Lock()
}
func (tm *TryRWMutex) RLock() {
	v := atomic.AddUint64(&tm.lock, readOffset)
	for v > tryOffset {
		runtime.Gosched()
		v = atomic.LoadUint64(&tm.lock)
	}
	tm.mu.RLock()
}
func (tm *TryRWMutex) RUnlock() {
	tm.mu.RUnlock()
	atomic.AddUint64(&tm.lock, ^(readOffset - 1))
}
func (tm *TryRWMutex) TryLock() bool {
	if atomic.CompareAndSwapUint64(&tm.lock, 0, writeOffset+tryOffset) {
		tm.mu.Lock()
		atomic.AddUint64(&tm.lock, ^(tryOffset - 1))
		return true
	}
	return false
}
func (tm *TryRWMutex) TryRLock() bool {
	v := atomic.AddUint64(&tm.lock, readOffset+tryOffset)
	v = v & tryMask
	if v > writeOffset {
		atomic.AddUint64(&tm.lock, ^(readOffset + tryOffset - 1))
		return false
	}
	tm.mu.RLock()
	atomic.AddUint64(&tm.lock, ^(tryOffset - 1))
	return true
}