Correction to early output in the parallel range implementation

The used heuristic of checking the value prior to lock is not totally safe
because assignment is not atomic and check might not give proper result.
This commit is contained in:
Sergey Sharybin 2015-05-18 12:44:59 +05:00
parent b88597c218
commit 40091ff83a
1 changed files with 6 additions and 8 deletions

View File

@ -508,16 +508,14 @@ BLI_INLINE bool parallel_range_next_iter_get(
int * __restrict iter, int * __restrict count)
{
bool result = false;
BLI_spin_lock(&state->lock);
if (state->iter < state->stop) {
BLI_spin_lock(&state->lock);
if (state->iter < state->stop) {
*count = min_ii(state->chunk_size, state->stop - state->iter);
*iter = state->iter;
state->iter += *count;
result = true;
}
BLI_spin_unlock(&state->lock);
*count = min_ii(state->chunk_size, state->stop - state->iter);
*iter = state->iter;
state->iter += *count;
result = true;
}
BLI_spin_unlock(&state->lock);
return result;
}