ObjFW  Check-in [212482d8c6]

Overview
Comment:Add of_atomic_cmpswap32 and spinlocks to atomic.h.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 212482d8c68cdca3d2cf64dbff7f14962236b70c45c4fa1cc232ae81d98c0891
User & Date: js on 2010-01-25 22:39:46
Other Links: manifest | tags
Context
2010-01-25
22:40
Use spinlocks in objc_properties.m. check-in: 2be191ec57 user: js tags: trunk
22:39
Add of_atomic_cmpswap32 and spinlocks to atomic.h. check-in: 212482d8c6 user: js tags: trunk
22:34
clang does not reuse constant strings, thus fix test to use the same. check-in: 612a252fdf user: js tags: trunk
Changes

Modified src/atomic.h from [10a1c95236] to [ac71df6e7f].

10
11
12
13
14
15
16

17
18
19

20
21
22
23


24
25
26









 */

#import "objfw-defs.h"

#if !defined(OF_THREADS)
# define of_atomic_inc32(p) ++(*p)
# define of_atomic_dec32(p) --(*p)

#elif defined(OF_HAVE_GCC_ATOMIC_OPS)
# define of_atomic_inc32(p) __sync_add_and_fetch(p, 1)
# define of_atomic_dec32(p) __sync_sub_and_fetch(p, 1)

#elif defined(OF_HAVE_LIBKERN_OSATOMIC_H)
# include <libkern/OSAtomic.h>
# define of_atomic_inc32(p) OSAtomicIncrement32Barrier((int32_t*)(p))
# define of_atomic_dec32(p) OSAtomicDecrement32Barrier((int32_t*)(p))


#else
# error No atomic operations available!
#endif
















>



>




>
>



>
>
>
>
>
>
>
>
>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 */

#import "objfw-defs.h"

#if !defined(OF_THREADS)
# define of_atomic_inc32(p) ++(*p)
# define of_atomic_dec32(p) --(*p)
# define of_atomic_cmpswap32(p, o, n) (*p == o ? ((*p = n) ? 1 : 1) : 0)
#elif defined(OF_HAVE_GCC_ATOMIC_OPS)
# define of_atomic_inc32(p) __sync_add_and_fetch(p, 1)
# define of_atomic_dec32(p) __sync_sub_and_fetch(p, 1)
# define of_atomic_cmpswap32(p, o, n) __sync_bool_compare_and_swap(p, o, n)
#elif defined(OF_HAVE_LIBKERN_OSATOMIC_H)
# include <libkern/OSAtomic.h>
# define of_atomic_inc32(p) OSAtomicIncrement32Barrier((int32_t*)(p))
# define of_atomic_dec32(p) OSAtomicDecrement32Barrier((int32_t*)(p))
# define of_atomic_cmpswap32(p, o, n) \
	OSAtomicCompareAndSwap32Barrier(o, n, (int32_t*)p)
#else
# error No atomic operations available!
#endif

typedef int32_t of_spinlock_t;
#ifdef OF_THREADS
# define of_spinlock_lock(s) while (!of_atomic_cmpswap32(&s, 0, 1));
# define of_spinlock_unlock(s) s = 0
#else
# define of_spinlock_lock(s)
# define of_spinlock_unlock(s)
#endif