3 # Patch managed by http://www.holgerschurig.de/patcher.html
7 +++ qt-embedded-opensource-4.0.0-b1/src/core/arch/arm/qatomic.cpp
11 +#define UNLOCKED {-1,-1,-1,-1}
12 +#define UNLOCKED2 UNLOCKED,UNLOCKED
13 +#define UNLOCKED4 UNLOCKED2,UNLOCKED2
14 +#define UNLOCKED8 UNLOCKED4,UNLOCKED4
15 +#define UNLOCKED16 UNLOCKED8,UNLOCKED8
16 +#define UNLOCKED32 UNLOCKED16,UNLOCKED16
17 +#define UNLOCKED64 UNLOCKED32,UNLOCKED32
18 +#define UNLOCKED128 UNLOCKED64,UNLOCKED64
19 +#define UNLOCKED256 UNLOCKED128,UNLOCKED128
21 +// use a 4k page for locks
22 +static int locks[256][4] = { UNLOCKED256 };
24 +int *getLock(volatile void *addr)
25 +{ return locks[qHash(const_cast<void *>(addr)) % 256]; }
27 +static int *align16(int *lock)
29 + ulong off = (((ulong) lock) % 16);
30 + return off ? (int *)(ulong(lock) + 16 - off) : lock;
35 + int q_ldcw(volatile int *addr);
37 + void q_atomic_lock(int *lock)
39 + // ldcw requires a 16-byte aligned address
40 + volatile int *x = align16(lock);
41 + // FIXME WHERE IS q_ldcw ??? while (q_ldcw(x) == 0)
45 + void q_atomic_unlock(int *lock)
46 + { lock[0] = lock[1] = lock[2] = lock[3] = -1; }
48 + int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected, void *newval)
50 + int *lock = getLock(ptr);
51 + q_atomic_lock(lock);
52 + if (*reinterpret_cast<void * volatile *>(ptr) == expected) {
53 + *reinterpret_cast<void * volatile *>(ptr) = newval;
54 + q_atomic_unlock(lock);
57 + q_atomic_unlock(lock);
61 + void *q_atomic_set_ptr(volatile void *ptr, void *newval)
63 + int *lock = getLock(ptr);
64 + q_atomic_lock(lock);
65 + void *oldval = *reinterpret_cast<void * volatile *>(ptr);
66 + *reinterpret_cast<void * volatile *>(ptr) = newval;
67 + q_atomic_unlock(lock);