MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / Foo

Class Foo

tests/unittests/unittests.cpp:152–183  ·  view source on GitHub ↗

Note: Not thread safe!

Source from the content-addressed store, hash-verified

150
151// Note: Not thread safe!
152struct Foo
153{
154 static int& nextId() { static int i; return i; }
155 static int& createCount() { static int c; return c; }
156 static int& destroyCount() { static int c; return c; }
157 static bool& destroyedInOrder() { static bool d = true; return d; }
158 static void reset() { createCount() = 0; destroyCount() = 0; nextId() = 0; destroyedInOrder() = true; lastDestroyedId() = -1; }
159
160 Foo() { id = nextId()++; ++createCount(); }
161 Foo(Foo const&) MOODYCAMEL_DELETE_FUNCTION;
162 Foo(Foo&& other) { id = other.id; other.id = -1; }
163 void operator=(Foo&& other) { id = other.id; other.id = -1; }
164 ~Foo()
165 {
166 ++destroyCount();
167 if (id == -2) {
168 // Double free!
169 destroyedInOrder() = false;
170 }
171 else if (id != -1) {
172 if (id <= lastDestroyedId()) {
173 destroyedInOrder() = false;
174 }
175 lastDestroyedId() = id;
176 }
177 id = -2;
178 }
179
180private:
181 int id;
182 static int& lastDestroyedId() { static int i = -1; return i; }
183};
184
185struct Copyable {
186 Copyable(int id) : copied(false), id(id) { }

Callers 3

leftovers_destroyedMethod · 0.70
block_index_resizedMethod · 0.70
full_apiMethod · 0.70

Calls

no outgoing calls

Tested by 3

leftovers_destroyedMethod · 0.56
block_index_resizedMethod · 0.56
full_apiMethod · 0.56