drm_public void fd_ringbuffer_del(struct fd_ringbuffer *ring)
{
- if (!(ring->flags & FD_RINGBUFFER_OBJECT))
- fd_ringbuffer_reset(ring);
+ if (!atomic_dec_and_test(&ring->refcnt))
+ return;
+
+ fd_ringbuffer_reset(ring);
ring->funcs->destroy(ring);
}
+drm_public struct fd_ringbuffer *
+fd_ringbuffer_ref(struct fd_ringbuffer *ring)
+{
+ STATIC_ASSERT(sizeof(ring->refcnt) <= sizeof(ring->__pad));
+ atomic_inc(&ring->refcnt);
+ return ring;
+}
+
/* ringbuffers which are IB targets should set the toplevel rb (ie.
* the IB source) as it's parent before emitting reloc's, to ensure
* the bookkeeping works out properly.
void *user;
uint32_t flags;
+
+ /* This is a bit gross, but we can't use atomic_t in exported
+ * headers. OTOH, we don't need the refcnt to be publicly
+ * visible. The only reason that this struct is exported is
+ * because fd_ringbuffer_emit needs to be something that can
+ * be inlined for performance reasons.
+ */
+ union {
+#ifdef HAS_ATOMIC_OPS
+ atomic_t refcnt;
+#endif
+ uint64_t __pad;
+ };
};
struct fd_ringbuffer * fd_ringbuffer_new(struct fd_pipe *pipe,
struct fd_ringbuffer * fd_ringbuffer_new_object(struct fd_pipe *pipe,
uint32_t size);
+struct fd_ringbuffer *fd_ringbuffer_ref(struct fd_ringbuffer *ring);
void fd_ringbuffer_del(struct fd_ringbuffer *ring);
void fd_ringbuffer_set_parent(struct fd_ringbuffer *ring,
struct fd_ringbuffer *parent);
#include <assert.h>
#include <inttypes.h>
+#include "xf86atomic.h"
#include "freedreno_ringbuffer.h"
#include "msm_priv.h"
struct msm_ringbuffer {
struct fd_ringbuffer base;
- atomic_t refcnt;
-
/* submit ioctl related tables:
* Note that bos and cmds are tracked by the parent ringbuffer, since
* that is global to the submit ioctl call. The reloc's table is tracked
return (struct msm_ringbuffer *)x;
}
-static void msm_ringbuffer_unref(struct fd_ringbuffer *ring);
-static void msm_ringbuffer_ref(struct fd_ringbuffer *ring);
-
#define INIT_SIZE 0x1000
static pthread_mutex_t idx_lock = PTHREAD_MUTEX_INITIALIZER;
if (msm_cmd->ring->flags & FD_RINGBUFFER_OBJECT) {
/* we could have dropped last reference: */
msm_ring->cmds[i] = NULL;
- msm_ringbuffer_unref(msm_cmd->ring);
+ fd_ringbuffer_del(msm_cmd->ring);
free(U642VOID(cmd->relocs));
}
}
* destroyed after emitted but before flush, so we must hold a ref:
*/
if (added_cmd && (target->flags & FD_RINGBUFFER_OBJECT)) {
- msm_ringbuffer_ref(target);
+ fd_ringbuffer_ref(target);
}
return size;
return to_msm_ringbuffer(ring)->cmd_count;
}
-static void msm_ringbuffer_unref(struct fd_ringbuffer *ring)
+static void msm_ringbuffer_destroy(struct fd_ringbuffer *ring)
{
struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring);
- if (!atomic_dec_and_test(&msm_ring->refcnt))
- return;
-
flush_reset(ring);
delete_cmds(msm_ring);
free(msm_ring);
}
-static void msm_ringbuffer_ref(struct fd_ringbuffer *ring)
-{
- struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring);
- atomic_inc(&msm_ring->refcnt);
-}
-
static const struct fd_ringbuffer_funcs funcs = {
.hostptr = msm_ringbuffer_hostptr,
.flush = msm_ringbuffer_flush,
.emit_reloc = msm_ringbuffer_emit_reloc,
.emit_reloc_ring = msm_ringbuffer_emit_reloc_ring,
.cmd_count = msm_ringbuffer_cmd_count,
- .destroy = msm_ringbuffer_unref,
+ .destroy = msm_ringbuffer_destroy,
};
drm_private struct fd_ringbuffer * msm_ringbuffer_new(struct fd_pipe *pipe,
list_inithead(&msm_ring->cmd_list);
msm_ring->seqno = ++to_msm_device(pipe->dev)->ring_cnt;
- atomic_set(&msm_ring->refcnt, 1);
ring = &msm_ring->base;
+ atomic_set(&ring->refcnt, 1);
+
ring->funcs = &funcs;
ring->size = size;
ring->pipe = pipe; /* needed in ring_cmd_new() */