Commit 3fe0d740 authored by Ronald S. Bultje's avatar Ronald S. Bultje

Use a single atomic integer for flush

parent 718f9254
......@@ -2369,7 +2369,7 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) {
t->a = f->a + col_sb128_start + tile_row * f->sb128w;
t->bx < ts->tiling.col_end; t->bx += sb_step)
{
if (atomic_load_explicit(&t->tile_thread.flush, memory_order_acquire))
if (atomic_load_explicit(c->frame_thread.flush, memory_order_acquire))
return 1;
if (decode_sb(t, root_bl, c->intra_edge.root[root_bl]))
return 1;
......@@ -2400,7 +2400,7 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) {
t->lf_mask = f->lf.mask + sb128y * f->sb128w + col_sb128_start;
t->bx < ts->tiling.col_end; t->bx += sb_step)
{
if (atomic_load_explicit(&t->tile_thread.flush, memory_order_acquire))
if (atomic_load_explicit(c->frame_thread.flush, memory_order_acquire))
return 1;
if (root_bl == BL_128X128) {
t->cur_sb_cdef_idx_ptr = t->lf_mask->cdef_idx;
......
......@@ -88,6 +88,10 @@ struct Dav1dContext {
struct {
Dav1dThreadPicture *out_delayed;
unsigned next;
// dummy is a pointer to prevent compiler errors about atomic_load()
// not taking const arguments; the const attribute is not taken
// from pointers
atomic_int flush_mem, *flush;
} frame_thread;
// reference/entropy state
......@@ -288,7 +292,6 @@ struct Dav1dTileContext {
struct thread_data td;
struct FrameTileThreadData *fttd;
int die;
atomic_int flush;
} tile_thread;
};
......
......@@ -93,6 +93,8 @@ int dav1d_open(Dav1dContext **const c_out,
c->apply_grain = s->apply_grain;
c->operating_point = s->operating_point;
c->all_layers = s->all_layers;
c->frame_thread.flush = &c->frame_thread.flush_mem;
atomic_init(c->frame_thread.flush, 0);
c->n_fc = s->n_frame_threads;
c->fc = dav1d_alloc_aligned(sizeof(*c->fc) * s->n_frame_threads, 32);
if (!c->fc) goto error;
......@@ -134,7 +136,6 @@ int dav1d_open(Dav1dContext **const c_out,
t->tile_thread.fttd = &f->tile_thread;
pthread_create(&t->tile_thread.td.thread, NULL, dav1d_tile_task, t);
}
atomic_init(&t->tile_thread.flush, 0);
}
f->libaom_cm = av1_alloc_ref_mv_common();
if (!f->libaom_cm) goto error;
......@@ -340,11 +341,7 @@ void dav1d_flush(Dav1dContext *const c) {
// mark each currently-running frame as flushing, so that we
// exit out as quickly as the running thread checks this flag
for (unsigned n = 0; n < c->n_fc; n++) {
Dav1dFrameContext *const f = &c->fc[n];
for (int m = 0; m < f->n_tc; m++)
atomic_store(&f->tc[m].tile_thread.flush, 1);
}
atomic_store(c->frame_thread.flush, 1);
for (unsigned n = 0, next = c->frame_thread.next; n < c->n_fc; n++, next++) {
if (next == c->n_fc) next = 0;
Dav1dFrameContext *const f = &c->fc[next];
......@@ -356,12 +353,11 @@ void dav1d_flush(Dav1dContext *const c) {
assert(!f->cur.data[0]);
}
pthread_mutex_unlock(&f->frame_thread.td.lock);
for (int m = 0; m < f->n_tc; m++)
atomic_store(&f->tc[m].tile_thread.flush, 0);
Dav1dThreadPicture *const out_delayed = &c->frame_thread.out_delayed[next];
if (out_delayed->p.data[0])
dav1d_thread_picture_unref(out_delayed);
}
atomic_store(c->frame_thread.flush, 0);
c->frame_thread.next = 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment