ref: 3fe0d740ba96760bc413cea98d40719fb411a67a
parent: 718f9254f19268f02f082530322d91c78f1ab2a3
author: Ronald S. Bultje <[email protected]>
date: Wed Nov 28 06:24:01 EST 2018
Use a single atomic integer for flush
--- a/src/decode.c
+++ b/src/decode.c
@@ -2369,7 +2369,7 @@
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 @@
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;
--- a/src/internal.h
+++ b/src/internal.h
@@ -88,6 +88,10 @@
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 thread_data td;
struct FrameTileThreadData *fttd;
int die;
- atomic_int flush;
} tile_thread;
};
--- a/src/lib.c
+++ b/src/lib.c
@@ -93,6 +93,8 @@
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 @@
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 @@
// 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 @@
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;
}