@@ -36,13 +36,13 @@ # include #endif #import "OFString.h" -#ifdef OF_ATOMIC_OPS +#if defined(OF_ATOMIC_OPS) # import "atomic.h" -#else +#elif defined(OF_THREADS) # import "threading.h" #endif /* A few macros to reduce #ifdefs */ #ifdef OF_OLD_GNU_RUNTIME @@ -53,11 +53,11 @@ struct pre_ivar { void **memchunks; size_t memchunks_size; int32_t retain_count; -#ifndef OF_ATOMIC_OPS +#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS) of_spinlock_t retain_spinlock; #endif }; /* Hopefully no arch needs more than 16 bytes padding */ @@ -141,11 +141,11 @@ ((struct pre_ivar*)instance)->memchunks = NULL; ((struct pre_ivar*)instance)->memchunks_size = 0; ((struct pre_ivar*)instance)->retain_count = 1; -#ifndef OF_ATOMIC_OPS +#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS) if (!of_spinlock_new(&((struct pre_ivar*)instance)->retain_spinlock)) { free(instance); @throw [OFInitializationFailedException newWithClass: self]; } #endif @@ -656,16 +656,18 @@ pointer: ptr]; } - retain { -#ifdef OF_ATOMIC_OPS +#if defined(OF_ATOMIC_OPS) of_atomic_inc_32(&PRE_IVAR->retain_count); -#else +#elif defined(OF_THREADS) assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock)); PRE_IVAR->retain_count++; assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock)); +#else + PRE_IVAR->retain_count++; #endif return self; } @@ -675,22 +677,25 @@ return (size_t)PRE_IVAR->retain_count; } - (void)release { -#ifdef OF_ATOMIC_OPS +#if defined(OF_ATOMIC_OPS) if (of_atomic_dec_32(&PRE_IVAR->retain_count) <= 0) [self dealloc]; -#else +#elif defined(OF_THREADS) size_t c; assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock)); c = --PRE_IVAR->retain_count; assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock)); if (!c) [self dealloc]; +#else + if (--PRE_IVAR->retain_count <= 0) + [self dealloc]; #endif } - autorelease {