2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifndef DISABLE_FALSE_SHARING_PADDING
27 #define CPU_LEVEL1_DCACHE_LINESIZE 64 // Until we know better via configure/getconf
34 using atomic_t = std::atomic<base_t>;
36 stat_t_trait() : stat_t_trait(base_t(0)) {
38 stat_t_trait(const base_t value)
40 new(&counter) atomic_t(value);
42 stat_t_trait& operator=(const base_t& value) {
49 stat_t_trait(stat_t_trait&&) = delete;
50 stat_t_trait& operator=(const stat_t_trait&) = delete;
51 stat_t_trait& operator=(stat_t_trait&&) = delete;
52 stat_t_trait(const stat_t_trait&) = delete;
53 base_t operator++(int) {
59 base_t operator--(int) {
65 base_t operator+=(base_t arg) {
68 base_t operator-=(base_t arg) {
74 void store(base_t value) {
77 operator base_t() const {
83 return *reinterpret_cast<atomic_t *>(&counter); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
85 const atomic_t& ref() const {
86 return *reinterpret_cast<const atomic_t *>(&counter); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
88 typename std::aligned_storage_t<sizeof(atomic_t), CPU_LEVEL1_DCACHE_LINESIZE> counter;
91 using stat_t = stat_t_trait<uint64_t>;
92 using stat32_t = stat_t_trait<uint32_t>;
93 using stat16_t = stat_t_trait<uint16_t>;
97 using stat_t = std::atomic<uint64_t>;
98 using stat32_t = std::atomic<uint32_t>;
99 using stat16_t = std::atomic<uint16_t>;
101 using stat_t_trait = std::atomic<T>;