]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/qte/qte-4.0.0-snapshot/add-qatomic.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / qte / qte-4.0.0-snapshot / add-qatomic.patch
1
2 #
3 # Patch managed by http://www.holgerschurig.de/patcher.html
4 #
5
6 --- /dev/null
7 +++ qt-embedded-opensource-4.0.0-b1/src/core/arch/arm/qatomic.cpp
8 @@ -0,0 +1,64 @@
9 +#include <qhash.h>
10 +
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
20 +
21 +// use a 4k page for locks
22 +static int locks[256][4] = { UNLOCKED256 };
23 +
24 +int *getLock(volatile void *addr)
25 +{ return locks[qHash(const_cast<void *>(addr)) % 256]; }
26 +
27 +static int *align16(int *lock)
28 +{
29 +    ulong off = (((ulong) lock) % 16);
30 +    return off ? (int *)(ulong(lock) + 16 - off) : lock;
31 +}
32 +
33 +extern "C" {
34 +
35 +    int q_ldcw(volatile int *addr);
36 +
37 +    void q_atomic_lock(int *lock)
38 +    {
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)
42 +           ;
43 +    }
44 +
45 +    void q_atomic_unlock(int *lock)
46 +    { lock[0] = lock[1] = lock[2] = lock[3] = -1; }
47 +
48 +    int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected, void *newval)
49 +    {
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);
55 +           return 1;
56 +        }
57 +       q_atomic_unlock(lock);
58 +       return 0;
59 +    }
60 +
61 +    void *q_atomic_set_ptr(volatile void *ptr, void *newval)
62 +    {
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);
68 +        return oldval;
69 +    }
70 +
71 +}
72 +