Skip to content

Commit 55d18a2

Browse files
committed
make the counter update thread-safe
1 parent 90f3cad commit 55d18a2

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

polymorphism/test/include/test_polymorphism/mocking.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef POLYMORPHISM_MOCKING_HPP
22
#define POLYMORPHISM_MOCKING_HPP
33

4+
#include <atomic>
45
#include <cstddef>
56
#include <list>
67
#include <string>
@@ -9,7 +10,7 @@ namespace mocking {
910

1011
struct Mock {
1112
std::list<std::string> collectedSetArguments;
12-
mutable std::size_t numberOfCallsToCoolFeature { 0 };
13+
mutable std::atomic<std::size_t> numberOfCallsToCoolFeature { 0 };
1314

1415
std::string coolFeature() const
1516
{

polymorphism/test/src/test_consume.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ int main()
5656
when("I pass it to a function that expects an argument that fulfils the constraints") = [&] {
5757
auto result = modern::consume(impl);
5858

59-
then("set() should be called twice") = [=] {
59+
then("set() should be called twice") = [&] {
6060
expect(EXPECTED_COOLFEATURE_CALLS == impl.numberOfCallsToCoolFeature);
6161
};
6262

6363
then("the answer to all questions should be given") = [=] {
6464
expect("The answer to all questions is 42"s == result);
6565
};
6666

67-
then("the state of the argument should be modified as a side effect") = [=] {
67+
then("the state of the argument should be modified as a side effect") = [&] {
6868
expect("42"s == impl.coolFeature());
6969
};
7070
};

0 commit comments

Comments
 (0)