freedreno/drm: Make ring refcnt atomic again

In general, rings are not shared across contexts/threads.  But this
can happen with texture stateobjs, which can be invalidated by other
contexts.

And while we're here, lets convert the rest of freedreno/drm to
u_atomic

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7342>
This commit is contained in:
Rob Clark 2020-10-24 12:20:57 -07:00 committed by Marge Bot
parent b1b8e0f8d1
commit b2f4bf0105
5 changed files with 7 additions and 8 deletions

View File

@ -251,7 +251,7 @@ void fd_bo_del(struct fd_bo *bo)
{
struct fd_device *dev = bo->dev;
if (!atomic_dec_and_test(&bo->refcnt))
if (!p_atomic_dec_zero(&bo->refcnt))
return;
simple_mtx_lock(&table_lock);

View File

@ -121,14 +121,14 @@ static void fd_device_del_impl(struct fd_device *dev)
void fd_device_del_locked(struct fd_device *dev)
{
if (!atomic_dec_and_test(&dev->refcnt))
if (!p_atomic_dec_zero(&dev->refcnt))
return;
fd_device_del_impl(dev);
}
void fd_device_del(struct fd_device *dev)
{
if (!atomic_dec_and_test(&dev->refcnt))
if (!p_atomic_dec_zero(&dev->refcnt))
return;
simple_mtx_lock(&table_lock);
fd_device_del_impl(dev);

View File

@ -77,7 +77,7 @@ struct fd_pipe * fd_pipe_ref(struct fd_pipe *pipe)
void fd_pipe_del(struct fd_pipe *pipe)
{
if (!atomic_dec_and_test(&pipe->refcnt))
if (!p_atomic_dec_zero(&pipe->refcnt))
return;
pipe->funcs->destroy(pipe);
}

View File

@ -51,8 +51,6 @@
#include "freedreno_drmif.h"
#include "freedreno_ringbuffer.h"
#define atomic_dec_and_test(x) (__sync_add_and_fetch (x, -1) == 0)
struct fd_device_funcs {
int (*bo_new_handle)(struct fd_device *dev, uint32_t size,
uint32_t flags, uint32_t *handle);

View File

@ -28,6 +28,7 @@
#define FREEDRENO_RINGBUFFER_H_
#include <stdio.h>
#include "util/u_atomic.h"
#include "util/u_debug.h"
#include "util/u_dynarray.h"
@ -127,7 +128,7 @@ struct fd_ringbuffer * fd_ringbuffer_new_object(struct fd_pipe *pipe,
static inline void
fd_ringbuffer_del(struct fd_ringbuffer *ring)
{
if (--ring->refcnt > 0)
if (!p_atomic_dec_zero(&ring->refcnt))
return;
ring->funcs->destroy(ring);
@ -137,7 +138,7 @@ static inline
struct fd_ringbuffer *
fd_ringbuffer_ref(struct fd_ringbuffer *ring)
{
ring->refcnt++;
p_atomic_inc(&ring->refcnt);
return ring;
}