aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/glib-2.0/glib-2.0-2.24.1/gatomic_armv6.patch
blob: b17f80dbab78f6ac321147768538c0b919ecba8d (plain)
1
2
3
4
5
6
7
8
9
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
--- glib-2.23.6.orig/configure.in
+++ glib-2.23.6/configure.in
@@ -2513,9 +2513,15 @@
         ;;
       arm*)
         AC_MSG_RESULT([arm])
-        AC_DEFINE_UNQUOTED(G_ATOMIC_ARM, 1,
-			   [arm atomic implementation])
-        glib_memory_barrier_needed=no
+        AC_MSG_CHECKING(arm atomic operations type)
+        AC_MSG_RESULT(inline asm)
+        AC_DEFINE_UNQUOTED(G_ATOMIC_ARM, 6,
+                           [armv6 atomic implementation])
+        glib_memory_barrier_needed=yes
+        dnl AC_MSG_RESULT(kernel helper)
+        dnl AC_DEFINE_UNQUOTED(G_ATOMIC_ARM_LINUX, 1,
+        dnl                   [special arm linux implementation])
+        dnl glib_memory_barrier_needed=yes
         ;;
       crisv32*|etraxfs*)
         AC_MSG_RESULT([crisv32])
--- /tmp/gatomic.c	2009-08-27 02:08:32.000000000 +0530
+++ glib-2.21.4/glib/gatomic.c	2009-08-27 02:08:49.000000000 +0530
@@ -561,6 +561,7 @@ g_atomic_pointer_compare_and_exchange (v
 #    error "Your system has an unsupported pointer size"
 #  endif /* GLIB_SIZEOF_VOID_P */
 # elif defined (G_ATOMIC_ARM)
+#  if (G_ATOMIC_ARM < 6)
 static volatile int atomic_spin = 0;
 
 static int atomic_spin_trylock (void)
@@ -651,6 +652,218 @@ g_atomic_pointer_compare_and_exchange (v
 
   return result;
 }
+ #  else /* G_ATOMIC_ARM < 6 */
+ gint
+ g_atomic_int_exchange_and_add (volatile gint *atomic,
+ 			       gint           val)
+ {
+   unsigned long result;
+   int old, tmp;
+ 
+   do {
+     asm volatile (
+       "ldrex %0, [%3]\n"
+       "add %1, %0, %4\n"
+       "strex %2, %1, [%3]\n"
+       : "=&r" (old), "=&r" (tmp), "=&r" (result)
+       : "r" (atomic), "Ir" (val)
+       : "cc", "memory");
+   } while (result);
+   return old;
+ }
+ 
+ void
+ g_atomic_int_add (volatile gint *atomic,
+ 		  gint           val)
+ {
+   unsigned long result;
+   int tmp;
+ 
+   do {
+     asm volatile (
+       "ldrex %0, [%2]\n"
+       "add %0, %0, %3\n"
+       "strex %1, %0, [%2]\n"
+       : "=&r" (tmp), "=&r" (result)
+       : "r" (atomic), "Ir" (val)
+       : "cc", "memory");
+   } while (result);
+ }
+ 
+ gboolean
+ g_atomic_int_compare_and_exchange (volatile gint *atomic,
+ 				   gint           oldval,
+ 				   gint           newval)
+ {
+   unsigned long result;
+   int old;
+ 
+   asm volatile (
+     "ldrex %1, [%2]\n"
+     "mov %0, #1\n"
+     "teq %1, %3\n"
+     "strexeq %0, %4, [%2]\n"
+     : "=&r" (result), "=&r" (old)
+     : "r" (atomic), "Ir" (oldval), "r" (newval)
+     : "cc", "memory");
+   return (result) ? FALSE : TRUE;
+ }
+ 
+ gboolean
+ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
+ 				       gpointer           oldval,
+ 				       gpointer           newval)
+ {
+   unsigned long result;
+   void *old;
+ 
+   asm volatile (
+     "ldrex %1, [%2]\n"
+     "mov %0, #1\n"
+     "teq %1, %3\n"
+     "strexeq %0, %4, [%2]\n"
+     : "=&r" (result), "=&r" (old)
+     : "r" (atomic), "Ir" (oldval), "r" (newval)
+     : "cc", "memory");
+   return (result) ? FALSE : TRUE;
+ }
+ 
+ gint
+ (g_atomic_int_get) (volatile gint *atomic)
+ {
+   return *atomic;
+ }
+ 
+ void
+ (g_atomic_int_set) (volatile gint *atomic,
+                   gint           newval)
+ {
+   unsigned long result;
+ 
+   do {
+     asm volatile (
+       "ldrex %0, [%1]\n"
+       "strex %0, %2, [%1]\n"
+       : "=&r" (result)
+       : "r" (atomic), "r" (newval)
+       : "cc", "memory");
+   } while (result);
+ }
+ 
+ gpointer
+ (g_atomic_pointer_get) (volatile gpointer *atomic)
+ {
+   return *atomic;
+ }
+ 
+ void
+ (g_atomic_pointer_set) (volatile gpointer *atomic,
+                       gpointer           newval)
+ {
+   unsigned long result;
+ 
+   do {
+     asm volatile (
+       "ldrex %0, [%1]\n"
+       "strex %0, %2, [%1]\n"
+       : "=&r" (result)
+       : "r" (atomic), "r" (newval)
+       : "cc", "memory");
+   } while (result);
+ }
+#  endif /* G_ATOMIC_ARM < 6 */
+ # elif defined(G_ATOMIC_ARM_LINUX)
+ /* use special helper functions provided by the linux kernel */
+ 
+ typedef void (_khelper_barrier_t)(void);
+ #define _khelper_barrier (*(_khelper_barrier_t *)0xffff0fa0)
+ #define G_ATOMIC_MEMORY_BARRIER _khelper_barrier()
+ /* scratchbox/qemu explodes on barrier */
+ /*#define G_ATOMIC_MEMORY_BARRIER while(0)*/
+ typedef int (_khelper_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
+ #define _khelper_cmpxchg (*(_khelper_cmpxchg_t *)0xffff0fc0)
+ 
+ gint
+ g_atomic_int_exchange_and_add (volatile gint *atomic,
+ 			       gint           val)
+ {
+   int result;
+   int old, new;
+ 
+   do {
+     old = *atomic;
+     new = old + val;
+     result = _khelper_cmpxchg(old, new, atomic);
+   } while (result);
+   return old;
+ }
+ 
+ void
+ g_atomic_int_add (volatile gint *atomic,
+ 		  gint           val)
+ {
+   int result;
+   int old, new;
+ 
+   do {
+     old = *atomic;
+     new = old + val;
+     result = _khelper_cmpxchg(old, new, atomic);
+   } while (result);
+ }
+ 
+ gboolean
+ g_atomic_int_compare_and_exchange (volatile gint *atomic,
+ 				   gint           oldval,
+ 				   gint           newval)
+ {
+   int result;
+ 
+   result = _khelper_cmpxchg(oldval, newval, atomic);
+   return (result) ? FALSE : TRUE;
+ }
+ 
+ gboolean
+ g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
+ 				       gpointer           oldval,
+ 				       gpointer           newval)
+ {
+   int result;
+ 
+   result = _khelper_cmpxchg(*((int *) &oldval),
+                             *((int *) &newval),
+                             (int *) atomic);
+   return (result) ? FALSE : TRUE;
+ }
+ 
+ gint
+ (g_atomic_int_get) (volatile gint *atomic)
+ {
+   return *atomic;
+ }
+ 
+ void
+ (g_atomic_int_set) (volatile gint *atomic,
+                   gint           newval)
+ {
+   while (_khelper_cmpxchg(*atomic, newval, atomic));
+ }
+ 
+ gpointer
+ (g_atomic_pointer_get) (volatile gpointer *atomic)
+ {
+   return *atomic;
+ }
+ 
+ void
+ (g_atomic_pointer_set) (volatile gpointer *atomic,
+                       gpointer           newval)
+ {
+   while (_khelper_cmpxchg(*((int *) atomic),
+                           *((int *) &newval),
+                           (int *) atomic));
+ }
+
 # elif defined (G_ATOMIC_CRIS) || defined (G_ATOMIC_CRISV32)
 #  ifdef G_ATOMIC_CRIS
 #   define CRIS_ATOMIC_INT_CMP_XCHG(atomic, oldval, newval)		\
@@ -954,7 +1167,8 @@ void
   g_mutex_unlock (g_atomic_mutex);
 }
 #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */   
-#elif defined (G_ATOMIC_OP_MEMORY_BARRIER_NEEDED)
+#elif (defined (G_ATOMIC_OP_MEMORY_BARRIER_NEEDED) && \
+       !defined(G_ATOMIC_ARM) && !defined(G_ATOMIC_ARM_LINUX))
 gint
 (g_atomic_int_get) (volatile gint G_GNUC_MAY_ALIAS *atomic)
 {