kokkos-execution 0.0.1
Loading...
Searching...
No Matches
counter.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
3
4#include "Kokkos_Core.hpp"
5
7
9struct Counter {
10 static inline std::atomic<unsigned int> default_constructions{0};
11 static inline std::atomic<unsigned int> destructions{0};
12 static inline std::atomic<unsigned int> copy_constructions{0};
13 static inline std::atomic<unsigned int> copy_assignments{0};
14 static inline std::atomic<unsigned int> move_constructions{0};
15 static inline std::atomic<unsigned int> move_assignments{0};
16
17 static inline std::atomic<unsigned int> next_id{0};
18
19 unsigned int id{0};
20
21 Counter() noexcept
22 : id(next_id.fetch_add(1, std::memory_order_relaxed)) {
23 default_constructions.fetch_add(1, std::memory_order_relaxed);
24 }
25
26 ~Counter() noexcept {
27 destructions.fetch_add(1, std::memory_order_relaxed);
28 }
29
30 Counter(const Counter&) noexcept
31 : id(next_id.fetch_add(1, std::memory_order_relaxed)) {
32 copy_constructions.fetch_add(1, std::memory_order_relaxed);
33 }
34
35 Counter& operator=(const Counter&) noexcept {
36 copy_assignments.fetch_add(1, std::memory_order_relaxed);
37 return *this;
38 }
39
40 Counter(Counter&&) noexcept
41 : id(next_id.fetch_add(1, std::memory_order_relaxed)) {
42 move_constructions.fetch_add(1, std::memory_order_relaxed);
43 }
44
45 Counter& operator=(Counter&&) noexcept {
46 move_assignments.fetch_add(1, std::memory_order_relaxed);
47 return *this;
48 }
49
50 template <typename... Args>
51 KOKKOS_FUNCTION void operator()(Args&&...) const noexcept {
52 }
53
54 static void reset() {
56 destructions = 0;
61 }
62};
63
64} // namespace Tests::Utils::Functors
65
66#endif // KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_COUNTER_HPP
static std::atomic< unsigned int > move_assignments
Definition counter.hpp:15
static std::atomic< unsigned int > copy_constructions
Definition counter.hpp:12
Counter & operator=(Counter &&) noexcept
Definition counter.hpp:45
static std::atomic< unsigned int > destructions
Definition counter.hpp:11
void operator()(Args &&...) const noexcept
Definition counter.hpp:51
Counter(Counter &&) noexcept
Definition counter.hpp:40
static std::atomic< unsigned int > next_id
Definition counter.hpp:17
static std::atomic< unsigned int > default_constructions
Definition counter.hpp:10
static std::atomic< unsigned int > move_constructions
Definition counter.hpp:14
static std::atomic< unsigned int > copy_assignments
Definition counter.hpp:13
Counter & operator=(const Counter &) noexcept
Definition counter.hpp:35
Counter(const Counter &) noexcept
Definition counter.hpp:30