This file is indexed.

/usr/include/directfb/direct/atomic.h is in libdirectfb-dev 1.7.7-8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
   (c) Copyright 2012-2013  DirectFB integrated media GmbH
   (c) Copyright 2001-2013  The world wide DirectFB Open Source Community (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Shimokawa <andi@directfb.org>,
              Marek Pikarski <mass@directfb.org>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/



#ifndef __DIRECT__ATOMIC_H__
#define __DIRECT__ATOMIC_H__

#include <direct/types.h>




#if !DIRECT_BUILD_GCC_ATOMICS


#if defined (__SH4__) || defined (__SH4A__)

/*
 * SH4 Atomic Operations
 */

#define D_SYNC_BOOL_COMPARE_AND_SWAP( ptr, old_value, new_value )               \
     ({                                                                         \
          __typeof__(*(ptr)) __temp;                                                \
          __typeof__(*(ptr)) __result;                                              \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%2, %0                            \n"       \
               "    mov            %0, %1                             \n"       \
               "    cmp/eq         %1, %3                             \n"       \
               "    bf             2f                                 \n"       \
               "    mov            %4, %0                             \n"       \
               "2:                                                    \n"       \
               "    movco.l        %0, @%2                            \n"       \
               "    bf             1b                                 \n"       \
               "    synco                                             \n"       \
               : "=&z" (__temp), "=&r" (__result)                               \
               : "r" (ptr), "r" (old_value), "r" (new_value)                    \
               : "t"                                                            \
          );                                                                    \
                                                                                \
          __result == (old_value);                                              \
     })


#define D_SYNC_ADD_AND_FETCH( ptr, value )                                      \
     ({                                                                         \
          __typeof__(*(ptr)) __result;                                              \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%1, %0                            \n"       \
               "    add            %2, %0                             \n"       \
               "    movco.l        %0, @%1                            \n"       \
               "    bf             1b                                 \n"       \
               "    synco                                             \n"       \
               : "=&z" (__result)                                               \
               : "r" (ptr), "r" (value)                                         \
               : "t"                                                            \
          );                                                                    \
                                                                                \
          __result;                                                             \
     })


#define D_SYNC_FETCH_AND_CLEAR( ptr )                                           \
     ({                                                                         \
          __typeof__(*(ptr)) __temp;                                                \
          __typeof__(*(ptr)) __result;                                              \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%2, %0                            \n"       \
               "    mov            %0, %1                             \n"       \
               "    xor            %0, %0                             \n"       \
               "    movco.l        %0, @%2                            \n"       \
               "    bf             1b                                 \n"       \
               "    synco                                             \n"       \
               : "=&z" (__temp), "=&r" (__result)                               \
               : "r" (ptr)                                                      \
               : "t"                                                            \
          );                                                                    \
                                                                                \
          __result;                                                             \
     })


#define D_SYNC_ADD( ptr, value )                                                \
     do {                                                                       \
          __typeof__(*(ptr)) __temp;                                                \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%1, %0                            \n"       \
               "    add            %2, %0                             \n"       \
               "    movco.l        %0, @%1                            \n"       \
               "    bf             1b                                 \n"       \
               : "=&z" (__temp)                                                 \
               : "r" (ptr), "r" (value)                                         \
               : "t"                                                            \
          );                                                                    \
     } while (0)

/*
 * FIFO Push
 *
 *   *iptr = *fptr
 *   *fptr =  iptr
 */
#define D_SYNC_PUSH_SINGLE( fptr, iptr )                                        \
     do {                                                                       \
          unsigned long **__fptr = (unsigned long **)(fptr);                    \
          unsigned long **__iptr = (unsigned long **)(iptr);                    \
          unsigned long  *__temp;                                               \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%1, %0                            \n"       \
               "    mov.l          %0, @%2                            \n"       \
               "    mov            %2, %0                             \n"       \
               "    movco.l        %0, @%1                            \n"       \
               "    bf             1b                                 \n"       \
               "    synco                                             \n"       \
               : "=&z" (__temp)                                                 \
               : "r" (__fptr), "r" (__iptr)                                     \
               : "t"                                                            \
          );                                                                    \
     } while (0)

/*
 * FIFO Pop
 *
 *    iptr = *fptr
 *   *fptr = *iptr  <- if iptr != NULL
 *
 *   return iptr
 */
#define D_SYNC_POP_SINGLE( fptr )                                               \
     ({                                                                         \
          unsigned long **__fptr = (unsigned long **)(fptr);                    \
          unsigned long **__iptr;                                               \
          unsigned long  *__temp;                                               \
                                                                                \
          __asm__ __volatile__ (                                                \
               "1:                                                    \n"       \
               "    movli.l        @%2, %0                            \n"       \
               "    mov            %0, %1                             \n"       \
               "    cmp/eq         #0, %0                             \n"       \
               "    bt             2f                                 \n"       \
               "    mov.l          @%1, %0                            \n"       \
               "2:                                                    \n"       \
               "    movco.l        %0, @%2                            \n"       \
               "    bf             1b                                 \n"       \
               "    synco                                             \n"       \
               : "=&z" (__temp), "=&r" (__iptr)                                 \
               : "r" (__fptr)                                                   \
               : "t"                                                            \
          );                                                                    \
                                                                                \
          (__typeof__(*(fptr))) __iptr;                                             \
     })


#endif


#if defined(ARCH_ARMv7) && !defined(ARCH_IWMMXT)

static inline int _D__atomic_cmpxchg(volatile int *ptr, int old, int _new)
{
	unsigned long oldval, res;

	do {
		__asm__ __volatile__("@ atomic_cmpxchg\n"
		"ldrex	%1, [%2]\n"
		"mov	%0, #0\n"
		"teq	%1, %3\n"
		"strexeq %0, %4, [%2]\n"
		    : "=&r" (res), "=&r" (oldval)
		    : "r" (ptr), "Ir" (old), "r" (_new)
		    : "cc");
	} while (res);

	return oldval;
}

#define D_SYNC_BOOL_COMPARE_AND_SWAP( ptr, old_value, new_value )                    \
     (_D__atomic_cmpxchg( (void*) ptr, (int) old_value, (int) new_value ) == (int) old_value)

#define D_SYNC_FETCH_AND_CLEAR( ptr )                                                \
     ({                                                                              \
          volatile __typeof__((ptr)) __ptr = (ptr);                                                     \
          __typeof__(*(ptr)) __temp;                                                     \
                                                                                     \
          do {                                                                       \
               __temp = (*__ptr);                                                      \
          } while (!D_SYNC_BOOL_COMPARE_AND_SWAP( __ptr, __temp, 0 ));                 \
                                                                                     \
          __temp;                                                                    \
     })

static inline int _D__atomic_add_return(int i, volatile int *v)
{
	unsigned long tmp;
	int result;

	__asm__ __volatile__("@ atomic_add_return\n"
"1:	ldrex	%0, [%2]\n"
"	add	%0, %0, %3\n"
"	strex	%1, %0, [%2]\n"
"	teq	%1, #0\n"
"	bne	1b"
	: "=&r" (result), "=&r" (tmp)
	: "r" (v), "Ir" (i)
	: "cc");

	return result;
}

#define D_SYNC_ADD_AND_FETCH( ptr, value )                                           \
     (_D__atomic_add_return( (int) (value), (volatile int*) (ptr) ))

#endif



#if defined(ARCH_MIPS)

static inline int _D__atomic_cmpxchg(volatile int *ptr, int old, int _new)
{
	unsigned long retval;

        __asm__ __volatile__(
              "	.set	push					\n"
              "	.set	noat					\n"
              "	.set	mips3					\n"
              "1:	ll	%0, %2			# __cmpxchg_u32	\n"
              "	bne	%0, %z3, 2f				\n"
              "	.set	mips0					\n"
              "	move	$1, %z4					\n"
              "	.set	mips3					\n"
              "	sc	$1, %1					\n"
              "	beqz	$1, 1b					\n"
#ifdef CONFIG_SMP
              "	sync						\n"
#endif
              "2:							\n"
              "	.set	pop					\n"
              : "=&r" (retval), "=R" (*ptr)
              : "R" (*ptr), "Jr" (old), "Jr" (_new)
              : "memory");

	return retval;
}

#define D_SYNC_BOOL_COMPARE_AND_SWAP( ptr, old_value, new_value )                    \
     (_D__atomic_cmpxchg( (void*) ptr, (int) old_value, (int) new_value ) == (int) old_value)

#define D_SYNC_FETCH_AND_CLEAR( ptr )                                                \
     ({                                                                              \
          volatile __typeof__((ptr)) __ptr = (ptr);                                                     \
          __typeof__(*(ptr)) __temp;                                                     \
                                                                                     \
          do {                                                                       \
               __temp = (*__ptr);                                                      \
          } while (!D_SYNC_BOOL_COMPARE_AND_SWAP( __ptr, __temp, 0 ));                 \
                                                                                     \
          __temp;                                                                    \
     })

static inline int _D__atomic_add_return(int i, volatile int *v)
{
     int temp;
     
     __asm__ __volatile__(
     "	.set	mips3					\n"
     "1:	ll	%0, %1		# atomic_add		\n"
     "	addu	%0, %2					\n"
     "	sc	%0, %1					\n"
     "	beqz	%0, 2f					\n"
     "	.subsection 2					\n"
     "2:	b	1b					\n"
     "	.previous					\n"
     "	.set	mips0					\n"
     : "=&r" (temp), "=m" (*v)
     : "Ir" (i), "m" (*v));

     return temp;
}

#define D_SYNC_ADD_AND_FETCH( ptr, value )                                           \
     _D__atomic_add_return( (int) (value), (volatile int*) (ptr) )

#endif


#endif  // !DIRECT_BUILD_GCC_ATOMICS



#ifdef WIN32

/*
 * Win32
 */

#ifndef D_SYNC_BOOL_COMPARE_AND_SWAP
#define D_SYNC_BOOL_COMPARE_AND_SWAP( ptr, old_value, new_value )     \
	 0
#endif

#ifndef D_SYNC_FETCH_AND_CLEAR
#define D_SYNC_FETCH_AND_CLEAR( ptr )                                 \
	 0
#endif

#ifndef D_SYNC_ADD_AND_FETCH
#define D_SYNC_ADD_AND_FETCH( ptr, value )                            \
	 0
#endif

#ifndef D_SYNC_ADD
#define D_SYNC_ADD( ptr, value )                                      \
	 0
#endif

#else //WIN32

#ifndef D_SYNC_BOOL_COMPARE_AND_SWAP
#define D_SYNC_BOOL_COMPARE_AND_SWAP( ptr, old_value, new_value )     \
     __sync_bool_compare_and_swap( ptr, old_value, new_value )
#endif

#ifndef D_SYNC_FETCH_AND_CLEAR
#define D_SYNC_FETCH_AND_CLEAR( ptr )                                 \
     __sync_fetch_and_and( ptr, 0 )
#endif

#ifndef D_SYNC_ADD_AND_FETCH
#define D_SYNC_ADD_AND_FETCH( ptr, value )                                      \
     __sync_add_and_fetch( ptr, value )
#if 0
     ({                                                                         \
          int           __val;                                                  \
          volatile int *__ptr = (volatile int *)(void*)(ptr);                   \
                                                                                \
          do {                                                                  \
               __val = *__ptr;                                                  \
          } while (!D_SYNC_BOOL_COMPARE_AND_SWAP( __ptr, __val, __val + value ));   \
                                                                                \
          __val + value;                                                        \
     })
#endif
#endif

#ifndef D_SYNC_ADD
#define D_SYNC_ADD( ptr, value )                                      \
     do { (void) D_SYNC_ADD_AND_FETCH( ptr, value ); } while (0)
#endif

#endif //!WIN32

/*
 * FIFO Push
 *
 *   *iptr = *fptr
 *   *fptr =  iptr
 */

#ifndef D_SYNC_PUSH_SINGLE
#define D_SYNC_PUSH_SINGLE( fptr, iptr )                                        \
     do {                                                                       \
          volatile long **__fptr = (volatile long **)(void*)(fptr);             \
          volatile long **__iptr = (volatile long **)(void*)(iptr);             \
                                                                                \
          do {                                                                  \
               *__iptr = *__fptr;                                               \
          } while (!D_SYNC_BOOL_COMPARE_AND_SWAP( __fptr, *__iptr, __iptr ));   \
     } while (0)
#endif

#ifndef D_SYNC_PUSH_MULTI
#define D_SYNC_PUSH_MULTI( fptr, iptr )                                         \
     do {                                                                       \
          volatile long **__fptr = (volatile long **)(void*)(fptr);             \
          volatile long **__iptr = (volatile long **)(void*)(iptr);             \
          volatile unsigned int   n = 1;                                        \
          unsigned int            r = 0;                                        \
                                                                                \
          while (true) {                                                        \
               *__iptr = *__fptr;                                               \
                                                                                \
               if (D_SYNC_BOOL_COMPARE_AND_SWAP( __fptr, *__iptr, __iptr ))     \
                    break;                                                      \
                                                                                \
               r = ((r + n) & 0x7f);                                            \
                                                                                \
               for (n=0; n<r; n++);                                             \
          }                                                                     \
     } while (0)
#endif


/*
 * FIFO Pop
 *
 *    iptr = *fptr
 *   *fptr = *iptr
 *
 *   return iptr
 */

#ifndef D_SYNC_POP_SINGLE

#ifdef WIN32
#define D_SYNC_POP_SINGLE( fptr )                                                         \
     0
#else
#define D_SYNC_POP_SINGLE( fptr )                                                         \
     ({                                                                                   \
          volatile long **__fptr = (volatile long**)(void*)(fptr);                        \
          volatile long  *__iptr;                                                         \
                                                                                          \
          do {                                                                            \
               __iptr = *__fptr;                                                          \
          } while (__iptr && !D_SYNC_BOOL_COMPARE_AND_SWAP( __fptr, __iptr, *__iptr ));   \
                                                                                          \
          (__typeof__(*(fptr))) __iptr;                                                   \
     })
#endif
#endif

#ifndef D_SYNC_POP_MULTI
#define D_SYNC_POP_MULTI( fptr )                                                \
     ({                                                                         \
          volatile long         **__fptr = (volatile long**)(void*)(fptr);      \
          volatile long          *__iptr;                                       \
          volatile int           n = 1;                                         \
          volatile int           r = 0;                                         \
                                                                                \
          while (true) {                                                        \
               __iptr = *__fptr;                                                \
                                                                                \
               if (D_SYNC_BOOL_COMPARE_AND_SWAP( __fptr, __iptr, *__iptr ))     \
                    break;                                                      \
                                                                                \
               r = ((r + n) & 0x7f);                                            \
                                                                                \
               for (n=0; n<r; n++);                                             \
          }                                                                     \
                                                                                \
          (__typeof__(*(fptr))) __iptr;                                         \
     })
#endif


#ifndef D_SYNC_PUSH
#if DIRECT_BUILD_MULTICORE
#define D_SYNC_PUSH D_SYNC_PUSH_MULTI
#else
#define D_SYNC_PUSH D_SYNC_PUSH_SINGLE
#endif
#endif

#ifndef D_SYNC_POP
#if DIRECT_BUILD_MULTICORE
#define D_SYNC_POP D_SYNC_POP_MULTI
#else
#define D_SYNC_POP D_SYNC_POP_SINGLE
#endif
#endif


#endif