mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
fix race conditions in atomic operations
This commit is contained in:
parent
1558b85acf
commit
6d9e1270ca
@ -76,7 +76,10 @@ markBitAtomic(uintptr_t* map, unsigned i)
|
||||
{
|
||||
uintptr_t* p = map + wordOf(i);
|
||||
uintptr_t v = static_cast<uintptr_t>(1) << bitOf(i);
|
||||
while (not atomicCompareAndSwap(p, *p, *p | v)) { }
|
||||
for (uintptr_t old = *p;
|
||||
not atomicCompareAndSwap(p, old, old | v);
|
||||
old = *p)
|
||||
{ }
|
||||
}
|
||||
#endif // USE_ATOMIC_OPERATIONS
|
||||
|
||||
|
@ -24,9 +24,12 @@ const unsigned NoByte = 0xFFFF;
|
||||
|
||||
#ifdef USE_ATOMIC_OPERATIONS
|
||||
void
|
||||
atomicIncrement(unsigned* p, int v)
|
||||
atomicIncrement(uint32_t* p, int v)
|
||||
{
|
||||
while (not atomicCompareAndSwap32(p, *p, *p + v)) { }
|
||||
for (uint32_t old = *p;
|
||||
not atomicCompareAndSwap32(p, old, old + v);
|
||||
old = *p)
|
||||
{ }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user