Esempio n. 1
0
void ZRefCountedWithFinalization::sDecRefCount(ZRefCountedWithFinalization* iObject)
	{
	if (!iObject)
		return;

	#if ZCONFIG_Thread_Preemptive

		for (;;)
			{
			int oldRefCount = ZAtomic_Get(&iObject->fRefCount);
			if (oldRefCount == 1)
				{
				iObject->Finalize();
				break;
				}
			else
				{
				if (ZAtomic_CompareAndSwap(&iObject->fRefCount, oldRefCount, oldRefCount - 1))
					break;
				// We'll only have to loop if we were preempted between the call to
				// ZAtomic_Get and the call to ZAtomic_CompareAndSwap, so we'll very
				// likely succeed next time round the loop.
				}
			}
	#else

		if (ZThreadSafe_DecAndTest(iObject->fRefCount))
			{
			ZThreadSafe_Set(iObject->fRefCount, 1);
			iObject->Finalize();
			}

	#endif
	}
Esempio n. 2
0
void ZCountedWithoutFinalize::Release()
	{
	if (ZThreadSafe_DecAndTest(fRefCount))
		delete this;
	}