Differences From Artifact [72f139fc0b]:
- File
src/OFObject.m
— part of check-in
[6f4eb004a3]
at
2010-12-18 23:39:20
on branch trunk
— Add support for the new GNU runtime.
Currently, the properties test for nonatomic fails. This is a bug in
the new GNU runtime. (user: js, size: 17930) [annotate] [blame] [check-ins using]
To Artifact [b33c6cd1e8]:
- File src/OFObject.m — part of check-in [88c920bd62] at 2010-12-28 22:18:34 on branch trunk — Make ObjFW work again without threads and without atomic ops. (user: js, size: 18159) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
34 35 36 37 38 39 40 | #ifdef _WIN32 # include <windows.h> #endif #import "OFString.h" | | | | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #ifdef _WIN32 # include <windows.h> #endif #import "OFString.h" #if defined(OF_ATOMIC_OPS) # import "atomic.h" #elif defined(OF_THREADS) # import "threading.h" #endif /* A few macros to reduce #ifdefs */ #ifdef OF_OLD_GNU_RUNTIME # define class_getInstanceSize class_get_instance_size # define class_getName class_get_class_name # define class_getSuperclass class_get_super_class #endif struct pre_ivar { void **memchunks; size_t memchunks_size; int32_t retain_count; #if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS) of_spinlock_t retain_spinlock; #endif }; /* Hopefully no arch needs more than 16 bytes padding */ #define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15) #define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN)) |
︙ | ︙ | |||
139 140 141 142 143 144 145 | @throw (OFAllocFailedException*)&alloc_failed_exception; } ((struct pre_ivar*)instance)->memchunks = NULL; ((struct pre_ivar*)instance)->memchunks_size = 0; ((struct pre_ivar*)instance)->retain_count = 1; | | | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | @throw (OFAllocFailedException*)&alloc_failed_exception; } ((struct pre_ivar*)instance)->memchunks = NULL; ((struct pre_ivar*)instance)->memchunks_size = 0; ((struct pre_ivar*)instance)->retain_count = 1; #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 instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN); |
︙ | ︙ | |||
654 655 656 657 658 659 660 | @throw [OFMemoryNotPartOfObjectException newWithClass: isa pointer: ptr]; } - retain { | | | > > | | > > > | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | @throw [OFMemoryNotPartOfObjectException newWithClass: isa pointer: ptr]; } - retain { #if defined(OF_ATOMIC_OPS) of_atomic_inc_32(&PRE_IVAR->retain_count); #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; } - (size_t)retainCount { assert(PRE_IVAR->retain_count >= 0); return (size_t)PRE_IVAR->retain_count; } - (void)release { #if defined(OF_ATOMIC_OPS) if (of_atomic_dec_32(&PRE_IVAR->retain_count) <= 0) [self dealloc]; #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 { /* * Cache OFAutoreleasePool since class lookups are expensive with the |
︙ | ︙ |