Fix an error in new lockfree parallel_range_next_iter_get() helper.

Reading the shared state->iter value after storing it in the 'reference' var could in theory
lead to a race condition setting state->iter value above state->stop, which would be 'deadly'.

This **may** be the cause of T48422, though I was not able to reproduce that issue so far.
This commit is contained in:
2016-05-14 18:02:34 +02:00
parent b9996a3cc3
commit a83bc4f597

View File

@@ -784,13 +784,13 @@ BLI_INLINE bool parallel_range_next_iter_get(
{ {
uint32_t n, olditer, previter, newiter; uint32_t n, olditer, previter, newiter;
if (state->iter >= state->stop) { if (UNLIKELY(state->iter >= state->stop)) {
return false; return false;
} }
do { do {
olditer = state->iter; olditer = state->iter;
n = min_ii(state->chunk_size, state->stop - state->iter); n = min_ii(state->chunk_size, state->stop - olditer);
newiter = olditer + n; newiter = olditer + n;
previter = atomic_cas_uint32((uint32_t *)&state->iter, olditer, newiter); previter = atomic_cas_uint32((uint32_t *)&state->iter, olditer, newiter);
} while (UNLIKELY(previter != olditer)); } while (UNLIKELY(previter != olditer));