예제 #1
0
	WriteGuard ReadWriteLock::TryWrite()
	{
		const u32 lock_key(EXCL_ENCODE(exclusive_write, 0));
		const bool success = (atomic_compare_and_swap(&mMutualExclusivityMask, exclusive_none, lock_key) == exclusive_none);
		if (success)
			mWriteEntryThread = GetCurrentThreadId();

		return success ? WriteGuard(this) : WriteGuard(nullptr);
	}
예제 #2
0
	WriteGuard ReadWriteLock::Write()
	{
		const ThreadID threadID = GetCurrentThreadId();
		const u32 lock_key(EXCL_ENCODE(exclusive_write, 0));
		while (atomic_compare_and_swap(&mMutualExclusivityMask, exclusive_none, lock_key) != exclusive_none)
		{
			if (threadID == mWriteEntryThread)
			{
				atomic_increment((u32*)&mReentrancyCount);
				break;
			}
			cond_wait();
		}

		KS_ASSERT(mWriteEntryThread == 0 || mWriteEntryThread == threadID);
		mWriteEntryThread = threadID;

		return WriteGuard(this);
	}
예제 #3
0
파일: rwlock.hpp 프로젝트: wheeland/pgasus
	inline WriteGuard write_guard() {
		return WriteGuard(this);
	}