ObjFW  Check-in [8a97fac06f]

Overview
Comment:Check return value of of_spinlock_*.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8a97fac06f8887b787a64600398bea21f89ab6837b8b91345ee8a9150543908e
User & Date: js on 2010-01-30 10:47:29
Other Links: manifest | tags
Context
2010-01-30
11:56
Nicer checking for atomic ops. check-in: 5950e1c6a6 user: js tags: trunk
10:47
Check return value of of_spinlock_*. check-in: 8a97fac06f user: js tags: trunk
02:09
Replace some macros with OF_INLINE functions.
This way, there won't be a warning about unused results.
check-in: 839f45a293 user: js tags: trunk
Changes

Modified src/OFObject.m from [415ea37dd0] to [7ae92c5eec].

117
118
119
120
121
122
123
124



125
126
127
128
129
130
131
	}

	((struct pre_ivar*)instance)->memchunks = NULL;
	((struct pre_ivar*)instance)->memchunks_size = 0;
	((struct pre_ivar*)instance)->retain_count = 1;

#ifndef OF_ATOMIC_OPS
	of_spinlock_new(&((struct pre_ivar*)instance)->retain_spinlock);



#endif

	instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN);
	memset(instance, 0, isize);
	instance->isa = self;

	return instance;







|
>
>
>







117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	}

	((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 (!of_spinlock_new(&((struct pre_ivar*)instance)->retain_spinlock)) {
		free(instance);
		@throw [OFInitializationFailedException newWithClass: self];
	}
#endif

	instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN);
	memset(instance, 0, isize);
	instance->isa = self;

	return instance;
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
}

- retain
{
#ifdef OF_ATOMIC_OPS
	of_atomic_inc32(&PRE_IVAR->retain_count);
#else
	of_spinlock_lock(&PRE_IVAR->retain_spinlock);
	PRE_IVAR->retain_count++;
	of_spinlock_unlock(&PRE_IVAR->retain_spinlock);
#endif

	return self;
}

- (int32_t)retainCount
{
	return PRE_IVAR->retain_count;
}

- (void)release
{
#ifdef OF_ATOMIC_OPS
	if (!of_atomic_dec32(&PRE_IVAR->retain_count))
		[self dealloc];
#else
	int32_t c;

	of_spinlock_lock(&PRE_IVAR->retain_spinlock);
	c = --PRE_IVAR->retain_count;
	of_spinlock_unlock(&PRE_IVAR->retain_spinlock);

	if (!c)
		[self dealloc];
#endif
}

- autorelease







|

|


















|

|







500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
}

- retain
{
#ifdef OF_ATOMIC_OPS
	of_atomic_inc32(&PRE_IVAR->retain_count);
#else
	assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock));
	PRE_IVAR->retain_count++;
	assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock));
#endif

	return self;
}

- (int32_t)retainCount
{
	return PRE_IVAR->retain_count;
}

- (void)release
{
#ifdef OF_ATOMIC_OPS
	if (!of_atomic_dec32(&PRE_IVAR->retain_count))
		[self dealloc];
#else
	int32_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];
#endif
}

- autorelease

Modified src/objc_properties.m from [63edddc2b7] to [d54a221003].

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"



#import <objc/objc.h>

#import "OFExceptions.h"

#ifdef OF_THREADS
#import "threading.h"












>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <assert.h>

#import <objc/objc.h>

#import "OFExceptions.h"

#ifdef OF_THREADS
#import "threading.h"
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic)
{
	if (atomic) {
		id *ptr = (id*)((char*)self + offset);
#ifdef OF_THREADS
		unsigned hash = SPINLOCK_HASH(ptr);

		of_spinlock_lock(&spinlocks[hash]);

		@try {
			return [[*ptr retain] autorelease];
		} @finally {
			of_spinlock_unlock(&spinlocks[hash]);
		}
#else
		return [[*ptr retain] autorelease];
#endif
	}

	return *(id*)((char*)self + offset);
}

void
objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, BOOL atomic,
    BOOL copy)
{
	if (atomic) {
		id *ptr = (id*)((char*)self + offset);
#ifdef OF_THREADS
		unsigned hash = SPINLOCK_HASH(ptr);

		of_spinlock_lock(&spinlocks[hash]);

		@try {
#endif
			id old = *ptr;

			switch (copy) {
			case 0:







|




|


















|







43
44
45
46
47
48
49
50
51
52
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
objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic)
{
	if (atomic) {
		id *ptr = (id*)((char*)self + offset);
#ifdef OF_THREADS
		unsigned hash = SPINLOCK_HASH(ptr);

		assert(of_spinlock_lock(&spinlocks[hash]));

		@try {
			return [[*ptr retain] autorelease];
		} @finally {
			assert(of_spinlock_unlock(&spinlocks[hash]));
		}
#else
		return [[*ptr retain] autorelease];
#endif
	}

	return *(id*)((char*)self + offset);
}

void
objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, BOOL atomic,
    BOOL copy)
{
	if (atomic) {
		id *ptr = (id*)((char*)self + offset);
#ifdef OF_THREADS
		unsigned hash = SPINLOCK_HASH(ptr);

		assert(of_spinlock_lock(&spinlocks[hash]));

		@try {
#endif
			id old = *ptr;

			switch (copy) {
			case 0:
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
			default:
				*ptr = [value copy];
			}

			[old release];
#ifdef OF_THREADS
		} @finally {
			of_spinlock_unlock(&spinlocks[hash]);
		}
#endif

		return;
	}

	id *ptr = (id*)((char*)self + offset);







|







92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
			default:
				*ptr = [value copy];
			}

			[old release];
#ifdef OF_THREADS
		} @finally {
			assert(of_spinlock_unlock(&spinlocks[hash]));
		}
#endif

		return;
	}

	id *ptr = (id*)((char*)self + offset);