ObjFW  Diff

Differences From Artifact [1c57171d5d]:

To Artifact [c05874ae6f]:


22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36







-
+








#include <assert.h>

#include <sys/time.h>

#import "OFObject.h"
#import "OFTimer.h"
#ifdef OF_THREADS
#ifdef OF_HAVE_THREADS
# import "OFThread.h"
#endif
#import "OFRunLoop.h"
#import "OFAutoreleasePool.h"

#import "OFAllocFailedException.h"
#import "OFEnumerationMutationException.h"
53
54
55
56
57
58
59
60

61
62

63
64
65
66
67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
53
54
55
56
57
58
59

60
61

62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+

-
+











-
+







#ifdef _WIN32
# include <windows.h>
#endif

#import "OFString.h"

#import "instance.h"
#if defined(OF_ATOMIC_OPS)
#if defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
#elif defined(OF_THREADS)
#elif defined(OF_HAVE_THREADS)
# import "threading.h"
#endif

#if defined(OF_APPLE_RUNTIME) && !defined(__ppc64__)
extern id of_forward(id, SEL, ...);
extern struct stret of_forward_stret(id, SEL, ...);
#endif

struct pre_ivar {
	int32_t retainCount;
	struct pre_mem *firstMem, *lastMem;
#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS)
#if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS)
	of_spinlock_t retainCountSpinlock;
#endif
};

struct pre_mem {
	struct pre_mem *prev, *next;
	id owner;
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209







-
+







		@throw (id)&alloc_failed_exception;
	}

	((struct pre_ivar*)instance)->retainCount = 1;
	((struct pre_ivar*)instance)->firstMem = NULL;
	((struct pre_ivar*)instance)->lastMem = NULL;

#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS)
#if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS)
	if OF_UNLIKELY (!of_spinlock_new(
	    &((struct pre_ivar*)instance)->retainCountSpinlock)) {
		free(instance);
		@throw [OFInitializationFailedException
		    exceptionWithClass: class];
	}
#endif
250
251
252
253
254
255
256
257

258
259

260
261
262
263
264
265
266
250
251
252
253
254
255
256

257
258

259
260
261
262
263
264
265
266







-
+

-
+







	objc_setForwardHandler(of_forward, of_forward_stret);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumeration_mutation_handler);
#endif

#if defined(OF_HAVE_ARC4RANDOM)
#if defined(HAVE_ARC4RANDOM)
	of_hash_seed = arc4random();
#elif defined(OF_HAVE_RANDOM)
#elif defined(HAVE_RANDOM)
	struct timeval t;
	gettimeofday(&t, NULL);
	srandom((unsigned)(t.tv_sec ^ t.tv_usec));
	of_hash_seed = (uint32_t)((random() << 16) | (random() & 0xFFFF));
#else
	struct timeval t;
	gettimeofday(&t, NULL);
621
622
623
624
625
626
627
628

629
630
631
632
633
634
635
621
622
623
624
625
626
627

628
629
630
631
632
633
634
635







-
+







					 object: object1
					 object: object2
					repeats: NO];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_THREADS
#ifdef OF_HAVE_THREADS
- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
	  waitUntilDone: (BOOL)waitUntilDone
{
	void *pool = objc_autoreleasePoolPush();
	OFTimer *timer = [OFTimer timerWithTimeInterval: 0
						 target: self
967
968
969
970
971
972
973
974

975
976

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995

996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
967
968
969
970
971
972
973

974
975

976
977
978
979


980
981
982
983
984
985
986
987
988
989
990
991
992

993
994
995

996
997
998
999
1000
1001
1002
1003
1004



1005
1006
1007
1008
1009
1010
1011







-
+

-
+



-
-













-
+


-
+








-
-
-







{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: selector];
}

- retain
{
#if defined(OF_ATOMIC_OPS)
#if defined(OF_HAVE_ATOMIC_OPS)
	of_atomic_inc_32(&PRE_IVARS->retainCount);
#elif defined(OF_THREADS)
#else
	OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock));
	PRE_IVARS->retainCount++;
	OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock));
#else
	PRE_IVARS->retainCount++;
#endif

	return self;
}

- (unsigned int)retainCount
{
	assert(PRE_IVARS->retainCount >= 0);
	return PRE_IVARS->retainCount;
}

- (void)release
{
#if defined(OF_ATOMIC_OPS)
#if defined(OF_HAVE_ATOMIC_OPS)
	if (of_atomic_dec_32(&PRE_IVARS->retainCount) <= 0)
		[self dealloc];
#elif defined(OF_THREADS)
#else
	size_t c;

	OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock));
	c = --PRE_IVARS->retainCount;
	OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock));

	if (c == 0)
		[self dealloc];
#else
	if (--PRE_IVARS->retainCount == 0)
		[self dealloc];
#endif
}

- autorelease
{
	return _objc_rootAutorelease(self);
}