+
+ mtx_lock(&screen->lock);
+
+ /*
+ * if we are pending read or write by any other context or
+ * if reading a resource pending a write, then
+ * flush all the contexts to maintain coherency
+ */
+ if (((status & ETNA_PENDING_WRITE) && rsc->status) ||
+ ((status & ETNA_PENDING_READ) && (rsc->status & ETNA_PENDING_WRITE))) {
+ set_foreach(rsc->pending_ctx, entry) {
+ struct etna_context *extctx = (struct etna_context *)entry->key;
+ struct pipe_context *pctx = &extctx->base;
+
+ if (extctx == ctx)
+ continue;
+
+ pctx->flush(pctx, NULL, 0);
+ /* It's safe to clear the status here. If we need to flush it means
+ * either another context had the resource in exclusive (write) use,
+ * or we transition the resource to exclusive use in our context.
+ * In both cases the new status accurately reflects the resource use
+ * after the flush.
+ */
+ rsc->status = 0;
+ }
+ }
+