ObjFW  Check-in [555445ce0a]

Overview
Comment:Remove useless thread-checking.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | runtime
Files: files | file ages | folders
SHA3-256: 555445ce0a7f88b64c4f298416477004890913f79e82e1df155bb9ab30f9bf92
User & Date: js on 2012-04-21 10:56:21
Other Links: branch diff | manifest | tags
Context
2012-04-21
11:31
Merge branch 'master' into runtime check-in: 676e09bf77 user: js tags: runtime
10:56
Remove useless thread-checking. check-in: 555445ce0a user: js tags: runtime
10:35
Merge branch 'master' into runtime check-in: e5d2a616de user: js tags: runtime
Changes

Modified src/runtime/class.m from [5cd9de1e6b] to [a1cee08383].

95
96
97
98
99
100
101
102
103
104

105

106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
}

void
objc_update_dtable(Class cls)
{
	struct objc_method_list *ml;
	struct objc_category **cats;
	struct objc_sparsearray *dtable;
	unsigned int i;


	if (cls->superclass != Nil)

		dtable = objc_sparsearray_copy(cls->superclass->dtable);
	else
		dtable = objc_sparsearray_new();


	for (ml = cls->methodlist; ml != NULL; ml = ml->next)
		for (i = 0; i < ml->count; i++)
			objc_sparsearray_set(dtable,
			    (uint32_t)ml->methods[i].sel.uid,
			    ml->methods[i].imp);

	if ((cats = objc_categories_for_class(cls)) != NULL) {
		for (i = 0; cats[i] != NULL; i++) {
			unsigned int j;

			ml = (cls->info & OBJC_CLASS_INFO_CLASS ?
			    cats[i]->instance_methods : cats[i]->class_methods);

			for (; ml != NULL; ml = ml->next)
				for (j = 0; j < ml->count; j++)
					objc_sparsearray_set(dtable,
					    (uint32_t)ml->methods[j].sel.uid,
					    ml->methods[j].imp);
		}
	}

	if (cls->dtable != NULL)
		objc_sparsearray_free_when_singlethreaded(cls->dtable);

	cls->dtable = dtable;

	if (cls->subclass_list != NULL)
		for (i = 0; cls->subclass_list[i] != NULL; i++)
			objc_update_dtable(cls->subclass_list[i]);
}

static void
add_subclass(Class cls)







<


>
|
>
|
|
|
>



|












|





<
<
<
<
<







95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132





133
134
135
136
137
138
139
}

void
objc_update_dtable(Class cls)
{
	struct objc_method_list *ml;
	struct objc_category **cats;

	unsigned int i;

	if (cls->dtable == NULL) {
		if (cls->superclass != Nil)
			cls->dtable =
			    objc_sparsearray_copy(cls->superclass->dtable);
		else
			cls->dtable = objc_sparsearray_new();
	}

	for (ml = cls->methodlist; ml != NULL; ml = ml->next)
		for (i = 0; i < ml->count; i++)
			objc_sparsearray_set(cls->dtable,
			    (uint32_t)ml->methods[i].sel.uid,
			    ml->methods[i].imp);

	if ((cats = objc_categories_for_class(cls)) != NULL) {
		for (i = 0; cats[i] != NULL; i++) {
			unsigned int j;

			ml = (cls->info & OBJC_CLASS_INFO_CLASS ?
			    cats[i]->instance_methods : cats[i]->class_methods);

			for (; ml != NULL; ml = ml->next)
				for (j = 0; j < ml->count; j++)
					objc_sparsearray_set(cls->dtable,
					    (uint32_t)ml->methods[j].sel.uid,
					    ml->methods[j].imp);
		}
	}






	if (cls->subclass_list != NULL)
		for (i = 0; cls->subclass_list[i] != NULL; i++)
			objc_update_dtable(cls->subclass_list[i]);
}

static void
add_subclass(Class cls)

Modified src/runtime/sparsearray.m from [71ecf956f3] to [a773bc4c5d].

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

		free(s->buckets[i]);
	}

	free(s);
}

void
objc_sparsearray_free_when_singlethreaded(struct objc_sparsearray *s)
{
	size_t i, j;

	for (i = 0; i < 256; i++) {
		if (s->buckets[i]->empty)
			continue;

		for (j = 0; j < 256; j++)
			if (!s->buckets[i]->buckets[j]->empty)
				objc_free_when_singlethreaded(
				    s->buckets[i]->buckets[j]);

		objc_free_when_singlethreaded(s->buckets[i]);
	}

	objc_free_when_singlethreaded(s);
}

void
objc_sparsearray_cleanup(void)
{
	if (empty_level2 != NULL)
		free(empty_level2);
	if (empty_level3 != NULL)
		free(empty_level3);







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







156
157
158
159
160
161
162




















163
164
165
166
167
168
169

		free(s->buckets[i]);
	}

	free(s);
}





















void
objc_sparsearray_cleanup(void)
{
	if (empty_level2 != NULL)
		free(empty_level2);
	if (empty_level3 != NULL)
		free(empty_level3);

Modified src/runtime/threading.m from [7dca0646d4] to [2d30e1cc90].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>

#import "runtime.h"
#import "runtime-private.h"

static objc_mutex_t global_mutex;
static int num_threads = 1;
static void **free_queue = NULL;
static size_t free_queue_cnt = 0;

BOOL
objc_mutex_new(objc_mutex_t *mutex)
{
	if (!of_mutex_new(&mutex->mutex ))
		return NO;








<
<
<







19
20
21
22
23
24
25



26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>

#import "runtime.h"
#import "runtime-private.h"

static objc_mutex_t global_mutex;




BOOL
objc_mutex_new(objc_mutex_t *mutex)
{
	if (!of_mutex_new(&mutex->mutex ))
		return NO;

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

void
objc_global_mutex_free(void)
{
	if (!objc_mutex_free(&global_mutex))
		ERROR("Failed to free global mutex!");
}

void
objc_thread_add(void)
{
	/*
	 * If some class is being initialized, we want to wait for it, thus
	 * we use the global lock instead of atomic operations.
	 */
	objc_global_mutex_lock();
	num_threads++;
	objc_global_mutex_unlock();
}

void
objc_thread_remove(void)
{
	size_t i;

	objc_global_mutex_lock();

	if (free_queue != NULL) {
		for (i = 0; i < free_queue_cnt; i++)
			free(free_queue[i]);

		free(free_queue);

		free_queue = NULL;
		free_queue_cnt = 0;
	}

	num_threads--;
	objc_global_mutex_unlock();
}

void
objc_free_when_singlethreaded(void *ptr)
{
	if (num_threads == 1) {
		free(ptr);
		return;
	}

	if (free_queue == NULL)
		free_queue = malloc(sizeof(void*));
	else
		free_queue = realloc(free_queue, sizeof(void*) *
		    (free_queue_cnt + 1));

	if (free_queue == NULL)
		ERROR("Not enough memory for queue of pointers to free!");

	free_queue[free_queue_cnt++] = ptr;
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
90
91
92
93
94
95
96






















































void
objc_global_mutex_free(void)
{
	if (!objc_mutex_free(&global_mutex))
		ERROR("Failed to free global mutex!");
}