X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..7e6b461318c8a779d91381531435a68ee4e8b6ed:/OSX/libsecurity_utilities/lib/seccfobject.h diff --git a/OSX/libsecurity_utilities/lib/seccfobject.h b/OSX/libsecurity_utilities/lib/seccfobject.h index 2717d755..29e9a5d3 100644 --- a/OSX/libsecurity_utilities/lib/seccfobject.h +++ b/OSX/libsecurity_utilities/lib/seccfobject.h @@ -29,23 +29,36 @@ #include #include #include "threading.h" +#include + +#if( __cplusplus <= 201103L) +#include +#endif namespace Security { class CFClass; -#define SECCFFUNCTIONS(OBJTYPE, APIPTR, ERRCODE, CFCLASS) \ -\ -void *operator new(size_t size) throw(std::bad_alloc) \ -{ return SecCFObject::allocate(size, CFCLASS); } \ +#define SECCFFUNCTIONS_BASE(OBJTYPE, APIPTR) \ \ operator APIPTR() const \ { return (APIPTR)(this->operator CFTypeRef()); } \ \ OBJTYPE *retain() \ { SecCFObject::handle(true); return this; } \ -APIPTR handle(bool retain = true) \ -{ return (APIPTR)SecCFObject::handle(retain); } \ +APIPTR CF_RETURNS_RETAINED handle() \ +{ return (APIPTR)SecCFObject::handle(true); } \ +APIPTR handle(bool retain) \ +{ return (APIPTR)SecCFObject::handle(retain); } + +#define SECCFFUNCTIONS_CREATABLE(OBJTYPE, APIPTR, CFCLASS) \ +SECCFFUNCTIONS_BASE(OBJTYPE, APIPTR)\ +\ +void *operator new(size_t size) throw(std::bad_alloc) \ +{ return SecCFObject::allocate(size, CFCLASS); } + +#define SECCFFUNCTIONS(OBJTYPE, APIPTR, ERRCODE, CFCLASS) \ +SECCFFUNCTIONS_CREATABLE(OBJTYPE, APIPTR, CFCLASS) \ \ static OBJTYPE *required(APIPTR ptr) \ { if (OBJTYPE *p = dynamic_cast(SecCFObject::required(ptr, ERRCODE))) \ @@ -60,7 +73,7 @@ static OBJTYPE *optional(APIPTR ptr) \ struct SecRuntimeBase: CFRuntimeBase { - bool isNew; + atomic_flag isOld; }; class SecCFObject @@ -72,16 +85,16 @@ private: static const size_t kAlignedRuntimeSize = SECALIGNUP(sizeof(SecRuntimeBase), 4); uint32_t mRetainCount; - OSSpinLock mRetainSpinLock; + os_unfair_lock mRetainLock; public: // For use by SecPointer only. Returns true once the first time it's called after the object has been created. bool isNew() { SecRuntimeBase *base = reinterpret_cast(reinterpret_cast(this) - kAlignedRuntimeSize); - bool isNew = base->isNew; - base->isNew = false; - return isNew; + + // atomic flags start clear, and like to go high. + return !atomic_flag_test_and_set(&(base->isOld)); } static SecCFObject *optional(CFTypeRef) throw(); @@ -94,7 +107,7 @@ public: uint32_t getRetainCount() {return updateRetainCount(0, NULL);} static void operator delete(void *object) throw(); - operator CFTypeRef() const throw() + virtual operator CFTypeRef() const throw() { return reinterpret_cast(reinterpret_cast(this) - kAlignedRuntimeSize); } @@ -107,7 +120,7 @@ public: virtual CFStringRef copyFormattingDesc(CFDictionaryRef dict); virtual CFStringRef copyDebugDesc(); virtual void aboutToDestruct(); - virtual Mutex* getMutexForObject(); + virtual Mutex* getMutexForObject() const; virtual bool mayDelete(); };