+struct tc_flush_payload {
+ struct threaded_context *tc;
+ struct pipe_fence_handle *fence;
+ unsigned flags;
+};
+
+static void
+tc_flush_queries(struct threaded_context *tc)
+{
+ struct threaded_query *tq, *tmp;
+ LIST_FOR_EACH_ENTRY_SAFE(tq, tmp, &tc->unflushed_queries, head_unflushed) {
+ LIST_DEL(&tq->head_unflushed);
+
+ /* Memory release semantics: due to a possible race with
+ * tc_get_query_result, we must ensure that the linked list changes
+ * are visible before setting tq->flushed.
+ */
+ p_atomic_set(&tq->flushed, true);
+ }
+}
+
+static void
+tc_call_flush(struct pipe_context *pipe, union tc_payload *payload)
+{
+ struct tc_flush_payload *p = (struct tc_flush_payload *)payload;
+ struct pipe_screen *screen = pipe->screen;
+
+ pipe->flush(pipe, p->fence ? &p->fence : NULL, p->flags);
+ screen->fence_reference(screen, &p->fence, NULL);
+
+ if (!(p->flags & PIPE_FLUSH_DEFERRED))
+ tc_flush_queries(p->tc);
+}
+