@@ -38,7 +38,7 @@ struct FakeCheckCheckCompletion {
38
38
static std::atomic<size_t > n_calls;
39
39
bool operator ()()
40
40
{
41
- ++ n_calls;
41
+ n_calls. fetch_add ( 1 , std::memory_order_relaxed) ;
42
42
return true ;
43
43
}
44
44
void swap (FakeCheckCheckCompletion& x){};
@@ -88,15 +88,15 @@ struct MemoryCheck {
88
88
//
89
89
// Really, copy constructor should be deletable, but CCheckQueue breaks
90
90
// if it is deleted because of internal push_back.
91
- fake_allocated_memory += b ;
91
+ fake_allocated_memory. fetch_add (b, std::memory_order_relaxed) ;
92
92
};
93
93
MemoryCheck (bool b_) : b(b_)
94
94
{
95
- fake_allocated_memory += b ;
95
+ fake_allocated_memory. fetch_add (b, std::memory_order_relaxed) ;
96
96
};
97
- ~MemoryCheck (){
98
- fake_allocated_memory -= b;
99
-
97
+ ~MemoryCheck ()
98
+ {
99
+ fake_allocated_memory. fetch_sub (b, std::memory_order_relaxed);
100
100
};
101
101
void swap (MemoryCheck& x) { std::swap (b, x.b ); };
102
102
};
@@ -117,9 +117,9 @@ struct FrozenCleanupCheck {
117
117
{
118
118
if (should_freeze) {
119
119
std::unique_lock<std::mutex> l (m);
120
- nFrozen = 1 ;
120
+ nFrozen. store ( 1 , std::memory_order_relaxed) ;
121
121
cv.notify_one ();
122
- cv.wait (l, []{ return nFrozen == 0 ;});
122
+ cv.wait (l, []{ return nFrozen. load (std::memory_order_relaxed) == 0 ;});
123
123
}
124
124
}
125
125
void swap (FrozenCleanupCheck& x){std::swap (should_freeze, x.should_freeze );};
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
262
262
control.Add (vChecks);
263
263
}
264
264
bool r =control.Wait ();
265
- BOOST_REQUIRE (r || end_fails);
265
+ BOOST_REQUIRE (r != end_fails);
266
266
}
267
267
}
268
268
tg.interrupt_all ();
@@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
337
337
tg.join_all ();
338
338
}
339
339
340
- // Test that a new verification cannot occur until all checks
340
+ // Test that a new verification cannot occur until all checks
341
341
// have been destructed
342
342
BOOST_AUTO_TEST_CASE (test_CheckQueue_FrozenCleanup)
343
343
{
@@ -361,11 +361,14 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
361
361
std::unique_lock<std::mutex> l (FrozenCleanupCheck::m);
362
362
// Wait until the queue has finished all jobs and frozen
363
363
FrozenCleanupCheck::cv.wait (l, [](){return FrozenCleanupCheck::nFrozen == 1 ;});
364
- // Try to get control of the queue a bunch of times
365
- for (auto x = 0 ; x < 100 && !fails; ++x) {
366
- fails = queue->ControlMutex .try_lock ();
367
- }
368
- // Unfreeze
364
+ }
365
+ // Try to get control of the queue a bunch of times
366
+ for (auto x = 0 ; x < 100 && !fails; ++x) {
367
+ fails = queue->ControlMutex .try_lock ();
368
+ }
369
+ {
370
+ // Unfreeze (we need lock n case of spurious wakeup)
371
+ std::unique_lock<std::mutex> l (FrozenCleanupCheck::m);
369
372
FrozenCleanupCheck::nFrozen = 0 ;
370
373
}
371
374
// Awaken frozen destructor
0 commit comments