This file is indexed.

/usr/include/gdnsd/stats.h is in gdnsd-dev 2.2.0-1ubuntu1.

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
/* Copyright © 2012 Brandon L Black <blblack@gmail.com>
 *
 * This file is part of gdnsd.
 *
 * gdnsd is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gdnsd 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gdnsd.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef GDNSD_STATS_H
#define GDNSD_STATS_H

#include <gdnsd/compiler.h>
#include <gdnsd/dmn.h>

#include <inttypes.h>

/*
 * This header defines two data types named stats_t and stats_uint_t,
 *   and several accessor functions for them.
 *
 * stats_t is used to implement an uint-like peice of data which is
 *   shared (without barriers or locking) between multiple threads
 *   and/or CPUs with the following very important caveats:
 *
 * 1) One thread is the "owner", and is the only thread performing
 *   write operations to the value within stats_t.
 * 2) Non-owner threads only read the data, using stats_get().
 * 3) The usage of the stats_t must be such that there are no data
 *   dependencies on it for correctness.  In other words: pay attention
 *   to the word "stats" in the type name; this is intended for storing
 *   and retrieving statistical data which have no bearing on correct
 *   program execution.
 * 4) Further, it's important to realize that the writes will only
 *   be seen by the non-owner threads "when the CPU feels like it".  On
 *   modern mainstream systems with reasonable cache coherency, this
 *   generally happens "pretty soon", soon enough that it doesn't matter
 *   for stats accounting.  There is no actual gaurantee on when the
 *   update becomes visible in the general case, and it might *never*
 *   become visible on some exotic architectures that gdnsd  doesn't
 *   care to support at this time.
 *
 * stats_uint_t is simply an regular unsigned type of some width that
 *   matches the internal width of stats_t.  You can store the result
 *   of stats_get() in such a type to cache it thread-locally for a while
 *   in cases where that makes sense.
 *
 * The width of the types currently matches uintptr_t (the width of a
 *   pointer), because most mainstream architectures are atomic for
 *   this size of aligned memory access (not atomic in the SMP sense,
 *   atomic in the "you won't read a half-updated value" sense).
 */

typedef uintptr_t stats_uint_t;
typedef struct { stats_uint_t _x; } stats_t;

// stats_own_set() -> set the stats value from the owner thread only
F_NONNULL F_UNUSED
static void stats_own_set(stats_t* s, const stats_uint_t v)
    { dmn_assert(s); s->_x = v; }

// stats_own_inc() -> increment stats value from the owner thread only
F_NONNULL F_UNUSED
static void stats_own_inc(stats_t* s)
    { dmn_assert(s); s->_x++; }

// stats_own_get() -> read the value from the owner thread
F_NONNULL F_UNUSED
static stats_uint_t stats_own_get(const stats_t* s)
    { dmn_assert(s); return s->_x; }

// stats_get() -> read the value from any other thread
F_NONNULL F_UNUSED
static stats_uint_t stats_get(const stats_t* s)
    { dmn_assert(s); return *(const volatile stats_uint_t*)&s->_x; }

#endif // GDNSD_STATS_H