This file is indexed.

/usr/include/qb/qbatomic.h is in libqb-dev 0.16.0.real-1ubuntu3.

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
/*
 * Copyright (C) 2003 Sebastian Wilhelmi
 *
 * This file is part of libqb.
 *
 * libqb 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.1 of the License, or
 * (at your option) any later version.
 *
 * libqb 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 libqb.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * Copied from the glib code base (glib/gatomic.h) and namespaced
 * for libqb.
 */

#ifndef QB_ATOMIC_H_DEFINED
#define QB_ATOMIC_H_DEFINED

/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */

#include <stdint.h>
#include <qb/qbdefs.h>
#include <qb/qbconfig.h>

/**
 * @file
 * Basic atomic integer and pointer operations
 *
 * The following functions can be used to atomically access integers and
 * pointers. They are implemented as inline assembler function on most
 * platforms and use slower fall-backs otherwise. Using them can sometimes
 * save you from using a performance-expensive pthread_mutex to protect the
 * integer or pointer.
 *
 * The most important usage is reference counting. Using
 * qb_atomic_int_inc() and qb_atomic_int_dec_and_test() makes reference
 * counting a very fast operation.
 *
 * You must not directly read integers or pointers concurrently
 * accessed by multiple threads, but use the atomic accessor functions
 * instead. That is, always use qb_atomic_int_get() and qb_atomic_pointer_get()
 * for read outs. They provide the neccessary synchonization mechanisms
 * like memory barriers to access memory locations concurrently.
 *
 * If you are using those functions for anything apart from
 * simple reference counting, you should really be aware of the implications
 * of doing that. There are literally thousands of ways to shoot yourself
 * in the foot. So if in doubt, use a pthread_mutex. If you don't know, what
 * memory barriers are, do not use anything but qb_atomic_int_inc() and
 * qb_atomic_int_dec_and_test().
 *
 * It is not safe to set an integer or pointer just by assigning
 * to it, when it is concurrently accessed by other threads with the following
 * functions. Use qb_atomic_int_compare_and_exchange() or
 * qb_atomic_pointer_compare_and_exchange() respectively.
 */

void qb_atomic_init(void);

/**
 * Atomically adds val to the integer pointed to by atomic.
 * It returns the value of *atomic just before the addition
 * took place. Also acts as a memory barrier.
 *
 * @param atomic a pointer to an integer
 * @param val the value to add to *atomic
 * @return the value of *atomic before the addition.
 */
int32_t qb_atomic_int_exchange_and_add(volatile int32_t QB_GNUC_MAY_ALIAS *
				      atomic, int32_t val);
/**
 * Atomically adds val to the integer pointed to by atomic.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to an integer
 * @param val the value to add to *atomic
 */
void qb_atomic_int_add(volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val);

/**
 * Compares oldval with the integer pointed to by atomic and
 * if they are equal, atomically exchanges *atomic with newval.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to an integer
 * @param oldval the assumed old value of *atomic
 * @param newval the new value of *atomic
 *
 * @return QB_TRUE, if *atomic was equal oldval. QB_FALSE otherwise.
 */
int32_t qb_atomic_int_compare_and_exchange(volatile int32_t QB_GNUC_MAY_ALIAS *
					  atomic, int32_t oldval,
					  int32_t newval);

/**
 * Compares oldval with the pointer pointed to by atomic and
 * if they are equal, atomically exchanges *atomic with newval.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to a void*
 * @param oldval the assumed old value of *atomic
 * @param newval the new value of *atomic
 *
 * @return QB_TRUE if atomic was equal oldval, else QB_FALSE.
 */
int32_t qb_atomic_pointer_compare_and_exchange(volatile void* QB_GNUC_MAY_ALIAS
					      * atomic, void* oldval,
					      void* newval);

/**
 * Reads the value of the integer pointed to by atomic.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to an integer
 *
 * @return the value of atomic
 */
int32_t qb_atomic_int_get(volatile int32_t QB_GNUC_MAY_ALIAS * atomic);

/**
 * Sets the value of the integer pointed to by atomic.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to an integer
 * @param newval the new value
 */
void qb_atomic_int_set(volatile int32_t QB_GNUC_MAY_ALIAS * atomic,
		      int32_t newval);

/**
 * Reads the value of the pointer pointed to by atomic.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to a void*.
 * @return the value to add to atomic.
 */
void* qb_atomic_pointer_get(volatile void* QB_GNUC_MAY_ALIAS * atomic);

/**
 * Sets the value of the pointer pointed to by atomic.
 * Also acts as a memory barrier.
 *
 * @param atomic a pointer to a void*
 * @param newval the new value
 *
 */
void qb_atomic_pointer_set(volatile void* QB_GNUC_MAY_ALIAS * atomic,
			  void* newval);

#ifndef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED
#define qb_atomic_int_get(atomic) 		((int32_t)*(atomic))
#define qb_atomic_int_set(atomic, newval) 	((void) (*(atomic) = (newval)))
#define qb_atomic_pointer_get(atomic) 		((void*)*(atomic))
#define qb_atomic_pointer_set(atomic, newval)	((void*) (*(atomic) = (newval)))
#else
#define qb_atomic_int_get(atomic) \
 ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \
  (qb_atomic_int_get) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
#define qb_atomic_int_set(atomic, newval) \
 ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \
  (qb_atomic_int_set) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
#define qb_atomic_pointer_get(atomic) \
 ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \
  (qb_atomic_pointer_get) ((volatile void* QB_GNUC_MAY_ALIAS *) (volatile void *) (atomic)))
#define qb_atomic_pointer_set(atomic, newval) \
 ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \
  (qb_atomic_pointer_set) ((volatile void* QB_GNUC_MAY_ALIAS *) (volatile void *) (atomic), (newval)))
#endif /* QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED */

/**
 * Atomically increments the integer pointed to by atomic by 1.
 *
 * @param atomic a pointer to an integer.
 */
#define qb_atomic_int_inc(atomic) (qb_atomic_int_add ((atomic), 1))

/**
 * Atomically decrements the integer pointed to by atomic by 1.
 *
 * @param atomic a pointer to an integer
 *
 * @return QB_TRUE if the integer pointed to by atomic is 0
 *     after decrementing it
 */
#define qb_atomic_int_dec_and_test(atomic) \
  (qb_atomic_int_exchange_and_add ((atomic), -1) == 1)

/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */

#endif /* QB_ATOMIC_H_DEFINED */