Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
debug_count.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2017 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
******************************************************************************/
30
31
#ifndef ETL_DEBUG_COUNT_INCLUDED
32
#define ETL_DEBUG_COUNT_INCLUDED
33
34
#include "
platform.h
"
35
#include "atomic.h"
36
37
#include <assert.h>
38
#include <stdint.h>
39
42
43
#if defined(ETL_DEBUG_COUNT)
44
45
#define ETL_DECLARE_DEBUG_COUNT etl::debug_count etl_debug_count
46
#define ETL_SET_DEBUG_COUNT(n) etl_debug_count.set(n)
47
#define ETL_GET_DEBUG_COUNT etl_debug_count.get()
48
#define ETL_INCREMENT_DEBUG_COUNT ++etl_debug_count
49
#define ETL_DECREMENT_DEBUG_COUNT --etl_debug_count
50
#define ETL_ADD_DEBUG_COUNT(n) etl_debug_count += (n)
51
#define ETL_SUBTRACT_DEBUG_COUNT(n) etl_debug_count -= (n)
52
#define ETL_RESET_DEBUG_COUNT etl_debug_count.clear()
53
#define ETL_OBJECT_RESET_DEBUG_COUNT(object) object.etl_debug_count.clear()
54
#define ETL_OBJECT_GET_DEBUG_COUNT(object) object.etl_debug_count.get()
55
56
namespace
etl
57
{
58
//***************************************************************************
64
//***************************************************************************
65
class
debug_count
66
{
67
public
:
68
69
debug_count()
70
: count(0)
71
{
72
}
73
74
~debug_count()
75
{
76
assert(count == 0);
77
}
78
79
debug_count& operator++()
80
{
81
++count;
82
return
*
this
;
83
}
84
85
debug_count& operator--()
86
{
87
--count;
88
assert(count >= 0);
89
return
*
this
;
90
}
91
92
template
<
typename
T>
93
debug_count& operator+=(T n)
94
{
95
count += int32_t(n);
96
return
*
this
;
97
}
98
99
template
<
typename
T>
100
debug_count& operator-=(T n)
101
{
102
count -= int32_t(n);
103
return
*
this
;
104
}
105
106
debug_count& operator=(
const
debug_count& other)
107
{
108
count.store(other.count.load());
109
110
return
*
this
;
111
}
112
113
#if ETL_HAS_ATOMIC
114
void
swap
(debug_count& other) ETL_NOEXCEPT
// NOT ATOMIC
115
{
116
int32_t temp = other.count.load();
117
other.count.store(count.load());
118
count.store(temp);
119
}
120
#else
121
void
swap
(debug_count& other) ETL_NOEXCEPT
122
{
123
swap
(count, other.count);
124
}
125
#endif
126
127
operator
int32_t()
const
128
{
129
return
count;
130
}
131
132
int32_t
get
()
const
133
{
134
return
int32_t(count);
135
}
136
137
void
set(int32_t n)
138
{
139
count = n;
140
}
141
142
void
clear()
143
{
144
count = 0;
145
}
146
147
private
:
148
149
#if ETL_HAS_ATOMIC
150
etl::atomic_int32_t count;
151
#else
152
int32_t count;
153
#endif
154
};
155
}
// namespace etl
156
157
inline
void
swap
(etl::debug_count& lhs, etl::debug_count& rhs)
158
{
159
lhs.swap(rhs);
160
}
161
162
#else
163
#define ETL_DECLARE_DEBUG_COUNT \
164
enum \
165
{ \
166
etl_debug_count_suppressed__ = 0 \
167
}
168
#define ETL_SET_DEBUG_COUNT(n) ((void)0)
169
#define ETL_GET_DEBUG_COUNT 0
170
#define ETL_INCREMENT_DEBUG_COUNT ((void)0)
171
#define ETL_DECREMENT_DEBUG_COUNT ((void)0)
172
#define ETL_ADD_DEBUG_COUNT(n) ((void)0)
173
#define ETL_SUBTRACT_DEBUG_COUNT(n) ((void)0)
174
#define ETL_RESET_DEBUG_COUNT ((void)0)
175
#define ETL_OBJECT_RESET_DEBUG_COUNT(object) ((void)0)
176
#define ETL_OBJECT_GET_DEBUG_COUNT(object) 0
177
#endif
// ETL_DEBUG_COUNT
178
179
#endif
swap
void swap(etl::array_view< T > &lhs, etl::array_view< T > &rhs) ETL_NOEXCEPT
Swaps the values.
Definition
array_view.h:692
etl
Definition
absolute.h:40
etl::get
T & get(array< T, Size > &a)
Definition
array.h:1158
platform.h
include
etl
debug_count.h
Generated on
for Embedded Template Library by
1.17.0