ObjFW  Check-in [fa79bc173e]

Overview
Comment:Add of_thread_yield()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fa79bc173ef8193b3f827c95e2c63fd2db7ec917661578c51fb8c968d2a2cb27
User & Date: js on 2016-04-18 21:48:08
Other Links: manifest | tags
Context
2016-04-23
09:43
Never end enums with a comma check-in: 3572e824c6 user: js tags: trunk
2016-04-18
21:48
Add of_thread_yield() check-in: fa79bc173e user: js tags: trunk
21:40
Move of_once() to threading.m check-in: 3f31bd034d user: js tags: trunk
Changes

Modified src/threading.h from [b27d0410b9] to [adb5774a4e].

169
170
171
172
173
174
175










176
177
178
179
180
181
182
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192







+
+
+
+
+
+
+
+
+
+







	return !pthread_key_delete(key);
#elif defined(OF_WINDOWS)
	return TlsFree(key);
#else
# error of_tlskey_free not implemented!
#endif
}

static OF_INLINE void
of_thread_yield(void)
{
#if defined(OF_HAVE_SCHED_YIELD)
	sched_yield();
#elif defined(OF_WINDOWS)
	Sleep(0);
#endif
}

static OF_INLINE bool
of_spinlock_new(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	*spinlock = 0;
	return true;
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
209
210
211
212
213
214
215

216
217
218
219
220
221
222


223






224
225
226
227
228
229
230







-







-
-
+
-
-
-
-
-
-







#endif
}

static OF_INLINE bool
of_spinlock_lock(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
# if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS)
	size_t i;

	for (i = 0; i < OF_SPINCOUNT; i++)
		if (of_spinlock_trylock(spinlock))
			return true;

	while (!of_spinlock_trylock(spinlock))
#  ifndef OF_WINDOWS
		sched_yield();
		of_thread_yield();
#  else
		Sleep(0);
#  endif
# else
	while (!of_spinlock_trylock(spinlock));
# endif

	return true;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return !pthread_spin_lock(spinlock);
#else
	return of_mutex_lock(spinlock);
#endif

Modified src/threading.m from [acfd94987f] to [656c95cd33].

29
30
31
32
33
34
35
36

37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
29
30
31
32
33
34
35

36
37


38






39
40
41
42
43
44
45







-
+

-
-
+
-
-
-
-
-
-







#ifndef OF_HAVE_PTHREADS
void
of_once(of_once_t *control, void (*func)(void))
{
	if (of_atomic_int_cmpswap(control, 0, 1)) {
		func();
		of_atomic_int_inc(control);
	} else {
	} else
		while (*control == 1)
# if defined(HAVE_SCHED_YIELD)
			sched_yield();
			of_thread_yield();
# elif defined(OF_WINDOWS)
			Sleep(0);
# else
			;
# endif
	}
}
#endif

#if !defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) && !defined(OF_WINDOWS)
bool
of_rmutex_new(of_rmutex_t *rmutex)
{