Skip to content
Snippets Groups Projects
Commit 35886895 authored by Steve Lhomme's avatar Steve Lhomme Committed by Felix Paul Kühne
Browse files

va_surface: fix potential double use of a buffer

Substracting 1 to refcount first, means it goes back to unused state
temporarily. It may be picked by another thread as well before calling
atomic_fetch_sub().

In the end we don't need the -1,+1 it's already in the "used once" state (2)
after the atomic_compare_exchange() call.
parent caf41ce2
No related branches found
No related tags found
1 merge request!1902va_surface: fix potential double use of a buffer
Pipeline #220160 passed with stage
in 15 minutes and 21 seconds
......@@ -122,13 +122,10 @@ static vlc_va_surface_t *GetSurface(va_pool_t *va_pool)
{
for (unsigned i = 0; i < va_pool->surface_count; i++) {
vlc_va_surface_t *surface = &va_pool->surface[i];
uintptr_t expected = 1;
uintptr_t expected = 1; // exists but unused
if (atomic_compare_exchange_strong(&surface->refcount, &expected, 2))
{
/* the copy should have added an extra reference */
atomic_fetch_sub(&surface->refcount, 1);
va_surface_AddRef(surface);
return surface;
}
}
......@@ -139,7 +136,7 @@ vlc_va_surface_t *va_pool_Get(va_pool_t *va_pool)
{
vlc_va_surface_t *surface;
if (va_pool->surface_count == 0)
if (unlikely(va_pool->surface_count == 0))
return NULL;
vlc_sem_wait(&va_pool->available_surfaces);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment