ObjFW  Check-in [8e7c6ddf8c]

Overview
Comment:of_spinlock_(un)lock: Add memory barrier
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8e7c6ddf8c87ab5194af730a405821eb4af27c74a906fda7aa566800257d5bfd
User & Date: js on 2016-07-30 21:22:31
Other Links: manifest | tags
Context
2016-07-30
21:46
of_memory_barrier(): Only use mfence on x86_64 check-in: 9feaa90358 user: js tags: trunk
21:22
of_spinlock_(un)lock: Add memory barrier check-in: 8e7c6ddf8c user: js tags: trunk
21:18
atomic.h: Improve memory barrier check-in: 96a128f954 user: js tags: trunk
Changes

Modified src/threading.h from [f81dcfe3c4] to [8449195015].

179
180
181
182
183
184
185
186





187
188
189
190
191
192
193
#endif
}

static OF_INLINE bool
of_spinlock_trylock(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	return of_atomic_int_cmpswap(spinlock, 0, 1);





#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return !pthread_spin_trylock(spinlock);
#else
	return of_mutex_trylock(spinlock);
#endif
}








|
>
>
>
>
>







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#endif
}

static OF_INLINE bool
of_spinlock_trylock(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	if (of_atomic_int_cmpswap(spinlock, 0, 1)) {
		of_memory_enter_barrier();
		return true;
	}

	return false;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return !pthread_spin_trylock(spinlock);
#else
	return of_mutex_trylock(spinlock);
#endif
}

212
213
214
215
216
217
218
219




220
221
222
223
224
225
226
#endif
}

static OF_INLINE bool
of_spinlock_unlock(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	return of_atomic_int_cmpswap(spinlock, 1, 0);




#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return !pthread_spin_unlock(spinlock);
#else
	return of_mutex_unlock(spinlock);
#endif
}








|
>
>
>
>







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#endif
}

static OF_INLINE bool
of_spinlock_unlock(of_spinlock_t *spinlock)
{
#if defined(OF_HAVE_ATOMIC_OPS)
	bool ret = of_atomic_int_cmpswap(spinlock, 1, 0);

	of_memory_leave_barrier();

	return ret;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
	return !pthread_spin_unlock(spinlock);
#else
	return of_mutex_unlock(spinlock);
#endif
}