This file is indexed.

/usr/include/eiskaltdcpp/dcpp/Atomic.h is in libeiskaltdcpp-dev 2.2.9-3.

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
/*
* Copyright (C) 2010 Gennady Proskurin (https://launchpad.net/~gpr)
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "CriticalSection.h"
#include <boost/version.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include <boost/cstdint.hpp>

namespace dcpp {

// Ordering arguments:

// memory_ordering_weak
// Suitable only for thread-safe accounting of some statistics.
// Value can not be used as "flag" (you cannot do any multi-thread action, based
// on this value) since it does not garantees necessary memory barriers.
class memory_ordering_weak {};

// memory_ordering_strong
// Suitable for any multi-thread purpose
class memory_ordering_strong {};

template <typename DataType, class Ordering = memory_ordering_strong>
class Atomic;


// uint32_t
template <>
class Atomic<boost::uint32_t, memory_ordering_weak> {
        typedef boost::uint32_t value_type;
public:
        Atomic(value_type val) { assign(val); }
        Atomic(const Atomic& other) { assign(static_cast<value_type>(other)); }

        // operator=
        // return void to be safe
        void operator=(value_type val) { assign(val); }
        void operator=(const Atomic& other) {
                return operator=(static_cast<value_type>(other));
        }

#if BOOST_VERSION >= 104800
        // type cast
        operator value_type() const {
                return boost::interprocess::ipcdetail::atomic_read32(&m_value);
        }

        // increment
        void inc() { boost::interprocess::ipcdetail::atomic_inc32(&m_value); }

        // decrement
        void dec() { boost::interprocess::ipcdetail::atomic_dec32(&m_value); }

private:
        mutable value_type m_value;
        void assign(value_type val) { boost::interprocess::ipcdetail::atomic_write32(&m_value, val); }
#else
                // type cast
        operator value_type() const {
                return boost::interprocess::detail::atomic_read32(&m_value);
        }

        // increment
        void inc() { boost::interprocess::detail::atomic_inc32(&m_value); }

        // decrement
        void dec() { boost::interprocess::detail::atomic_dec32(&m_value); }

private:
        mutable value_type m_value;
        void assign(value_type val) { boost::interprocess::detail::atomic_write32(&m_value, val); }
#endif //BOOST_VERSION
};

// int32_t
// just forward all operations to underlying Atomic<uint32_t, ...> variable
template <>
class Atomic<boost::int32_t, memory_ordering_weak> {
        typedef boost::int32_t value_type;
public:
        Atomic(value_type val) : m_value(val) {}
        Atomic(const Atomic& other) : m_value(other) {}

        void operator=(value_type val)          { m_value=val; }
        void operator=(const Atomic& other)     { m_value=other; }
        operator value_type() const             { return static_cast<value_type>(m_value); }

        void inc() { m_value.inc(); }
        void dec() { m_value.dec(); }
private:
        Atomic<boost::uint32_t,memory_ordering_weak> m_value;
};

// memory_ordering_strong
template <typename DataType>
class Atomic<DataType, memory_ordering_strong> {
        typedef DataType value_type;
public:
        Atomic(value_type new_value) : m_value(new_value) {}
        Atomic(const Atomic& other) : m_value(static_cast<value_type>(other)) {}

        void operator=(value_type new_value) {
                FastLock Lock(cs);
                m_value = new_value;
        }
        void operator=(const Atomic& other) {
                FastLock Lock(cs);
                m_value = other;
        }
        operator value_type() const {
                FastLock Lock(cs); // shared (read-only) lock would be sufficient here
                return m_value;
        }

        void inc() {
                FastLock Lock(cs);
                ++m_value;
        }
        void dec() {
                FastLock Lock(cs);
                --m_value;
        }

        // assign new value, return old value
        value_type exchange(value_type new_val) {
                FastLock Lock(cs);
                value_type old_val = m_value;
                m_value = new_val;
                return old_val;
        }
private:
        value_type m_value;
        mutable FastCriticalSection cs;
};

} // namespace dcpp