#include <security_utilities/cfclass.h>
#include <security_utilities/errors.h>
#include <security_utilities/debugging.h>
+#include <os/lock.h>
#include <list>
#include <security_utilities/globalizer.h>
-#include <auto_zone.h>
+#if( __cplusplus <= 201103L)
+#include <stdatomic.h>
+#endif
SecPointerBase::SecPointerBase(const SecPointerBase& p)
{
}
-
-
-static void CheckForRelease(SecCFObject* ptr)
-{
- CFTypeRef tr = ptr->operator CFTypeRef();
- CFIndex retainCount = CFGetRetainCount(tr);
- if (retainCount == 1 || retainCount == -1)
- {
- ptr->aboutToDestruct();
- }
-}
-
-
-
SecPointerBase::SecPointerBase(SecCFObject *p)
{
if (p && !p->isNew())
{
if (ptr)
{
- CheckForRelease(ptr);
CFRelease(ptr->operator CFTypeRef());
}
}
}
if (ptr)
{
- CheckForRelease(ptr);
CFRelease(ptr->operator CFTypeRef());
}
ptr = p.ptr;
}
if (ptr)
{
- CheckForRelease(ptr);
CFRelease(ptr->operator CFTypeRef());
}
ptr = p;
{
if (ptr)
{
- CheckForRelease(ptr);
CFRelease(ptr->operator CFTypeRef());
}
if (p == NULL)
throw std::bad_alloc();
- ((SecRuntimeBase*) p)->isNew = true;
+ atomic_flag_clear(&((SecRuntimeBase*) p)->isOld);
void *q = ((u_int8_t*) p) + kAlignedRuntimeSize;
- if (SECURITY_DEBUG_SEC_CREATE_ENABLED()) {
- const CFRuntimeClass *rtc = _CFRuntimeGetClassWithTypeID(cfclass.typeID);
- SECURITY_DEBUG_SEC_CREATE(q, rtc ? (char *)rtc->className : NULL, (unsigned int)cfclass.typeID);
- }
return q;
}
SecCFObject::operator delete(void *object) throw()
{
CFTypeRef cfType = reinterpret_cast<CFTypeRef>(reinterpret_cast<const uint8_t *>(object) - kAlignedRuntimeSize);
- if (CF_IS_COLLECTABLE(cfType))
- {
- return;
- }
-
+
CFAllocatorRef allocator = CFGetAllocator(cfType);
CFAllocatorDeallocate(allocator, (void*) cfType);
}
SecCFObject::SecCFObject()
{
mRetainCount = 1;
- mRetainSpinLock = OS_SPINLOCK_INIT;
+ mRetainLock = OS_UNFAIR_LOCK_INIT;
}
uint32_t SecCFObject::updateRetainCount(intptr_t direction, uint32_t *oldCount)
{
- OSSpinLockLock(&mRetainSpinLock);
+ os_unfair_lock_lock(&mRetainLock);
if (oldCount != NULL)
{
uint32_t result = mRetainCount;
- OSSpinLockUnlock(&mRetainSpinLock);
+ os_unfair_lock_unlock(&mRetainLock);
return result;
}
SecCFObject::~SecCFObject()
{
- SECURITY_DEBUG_SEC_DESTROY(this);
+ //SECURITY_DEBUG_SEC_DESTROY(this);
}
bool
Mutex*
-SecCFObject::getMutexForObject()
+SecCFObject::getMutexForObject() const
{
return NULL; // we only worry about descendants of KeychainImpl and ItemImpl
}