void vrend_renderer_check_fences(void)
{
   struct list_head retired_fences;
   struct vrend_fence *fence, *stor;

   /* No need to check the fence list, fences are retired directly in
    * the polling thread in that case.
    */
   if (vrend_state.use_async_fence_cb)
      return;

   list_inithead(&retired_fences);

   if (vrend_state.sync_thread) {
      flush_eventfd(vrend_state.eventfd);
      mtx_lock(&vrend_state.fence_mutex);
      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &vrend_state.fence_list, fences) {
         /* vrend_free_fences_for_context might have marked the fence invalid
          * by setting fence->ctx to NULL
          */
         if (!fence->ctx) {
            free_fence_locked(fence);
            continue;
         }

         if (need_fence_retire_signal_locked(fence, &vrend_state.fence_list)) {
            list_del(&fence->fences);
            list_addtail(&fence->fences, &retired_fences);
         } else {
            free_fence_locked(fence);
         }
      }
      mtx_unlock(&vrend_state.fence_mutex);
   } else {
      vrend_renderer_force_ctx_0();

      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &vrend_state.fence_list, fences) {
         if (do_wait(fence, /* can_block */ false)) {
            list_del(&fence->fences);
            list_addtail(&fence->fences, &retired_fences);
         } else {
            /* don't bother checking any subsequent ones */
            break;
         }
      }

      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &retired_fences, fences) {
         if (!need_fence_retire_signal_locked(fence, &retired_fences))
            free_fence_locked(fence);
      }
   }

   if (LIST_IS_EMPTY(&retired_fences))
      return;

   /* no need to lock when not using a sync thread */
   vrend_renderer_check_queries_locked();

   LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &retired_fences, fences) {
      struct vrend_context *ctx = fence->ctx;
      ctx->fence_retire(fence->fence_cookie, ctx->fence_retire_data);

      free_fence_locked(fence);
   }
}
void vrend_renderer_check_fences(void)
{
   struct list_head retired_fences;
   struct vrend_fence *fence, *stor;

    
   if (vrend_state.use_async_fence_cb)
      return;

   list_inithead(&retired_fences);

   if (vrend_state.sync_thread) {
      flush_eventfd(vrend_state.eventfd);
      mtx_lock(&vrend_state.fence_mutex);
      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &vrend_state.fence_list, fences) {
          
         if (!fence->ctx) {
            free_fence_locked(fence);
            continue;
         }

         if (need_fence_retire_signal_locked(fence, &vrend_state.fence_list)) {
            list_del(&fence->fences);
            list_addtail(&fence->fences, &retired_fences);
         } else {
            free_fence_locked(fence);
         }
      }
      mtx_unlock(&vrend_state.fence_mutex);
   } else {
      vrend_renderer_force_ctx_0();

      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &vrend_state.fence_list, fences) {
         if (do_wait(fence,   false)) {
            list_del(&fence->fences);
            list_addtail(&fence->fences, &retired_fences);
         } else {
             
            break;
         }
      }

      LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &retired_fences, fences) {
         if (!need_fence_retire_signal_locked(fence, &retired_fences))
            free_fence_locked(fence);
      }
   }

   if (LIST_IS_EMPTY(&retired_fences))
      return;

    
   vrend_renderer_check_queries_locked();

   LIST_FOR_EACH_ENTRY_SAFE(fence, stor, &retired_fences, fences) {
      struct vrend_context *ctx = fence->ctx;
      ctx->fence_retire(fence->fence_cookie, ctx->fence_retire_data);

      free_fence_locked(fence);
   }
}