public ThreadLock() { mLockCount = 0; mRead = LOCK_TYPE.LT_WRITE; mReadLockCount = 0; mShowLockError = 0; }
public void unlock(LOCK_TYPE read = LOCK_TYPE.LT_WRITE, bool showDebug = false) { Interlocked.Exchange(ref mLockCount, 0); if (showDebug) { UnityUtility.logError("unlock : read : " + (mRead == LOCK_TYPE.LT_READ ? "true" : "false") + ", read count : " + mReadLockCount); } }
public void unlock(LOCK_TYPE read, bool showDebug = false) { mLock = false; if (showDebug) { UnityUtility.logError("unlock : read : " + (mRead == LOCK_TYPE.LT_READ ? "true" : "false") + ", read count : " + mReadLockCount); } }
public void waitForUnlock(LOCK_TYPE read = LOCK_TYPE.LT_WRITE, bool showDebug = false) { while (Interlocked.Exchange(ref mLockCount, 1) != 0) { } mRead = read; if (showDebug) { UnityUtility.logError("lock : read : " + (mRead == LOCK_TYPE.LT_READ ? "true" : "false") + ", read count : " + mReadLockCount); } }
public void waitForUnlock(LOCK_TYPE read, bool showDebug = false) { while (mLock) { } // 解锁后立即上锁 mLock = true; mLock = true; mRead = read; if (showDebug) { UnityUtility.logError("lock : read : " + (mRead == LOCK_TYPE.LT_READ ? "true" : "false") + ", read count : " + mReadLockCount); } }