static void vrend_renderer_use_threaded_sync(void)
{
   struct virgl_gl_ctx_param ctx_params;

   ctx_params.shared = true;
   ctx_params.major_ver = vrend_state.gl_major_ver;
   ctx_params.minor_ver = vrend_state.gl_minor_ver;

   vrend_state.stop_sync_thread = false;

   vrend_state.sync_context = vrend_clicbs->create_gl_context(0, &ctx_params);
   if (vrend_state.sync_context == NULL) {
      vrend_printf( "failed to create sync opengl context\n");
      return;
   }

   if (!vrend_state.use_async_fence_cb) {
      vrend_state.eventfd = create_eventfd(0);
      if (vrend_state.eventfd == -1) {
         vrend_printf( "Failed to create eventfd\n");
         vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
         return;
      }
   }

   cnd_init(&vrend_state.fence_cond);
   mtx_init(&vrend_state.fence_mutex, mtx_plain);

   vrend_state.sync_thread = u_thread_create(thread_sync, NULL);
   if (!vrend_state.sync_thread) {
      if (vrend_state.eventfd != -1) {
         close(vrend_state.eventfd);
         vrend_state.eventfd = -1;
      }
      vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
      cnd_destroy(&vrend_state.fence_cond);
      mtx_destroy(&vrend_state.fence_mutex);
   }
}
static void vrend_renderer_use_threaded_sync(void)
{
   struct virgl_gl_ctx_param ctx_params;

   ctx_params.shared = true;
   ctx_params.major_ver = vrend_state.gl_major_ver;
   ctx_params.minor_ver = vrend_state.gl_minor_ver;

   vrend_state.stop_sync_thread = false;

   vrend_state.sync_context = vrend_clicbs->create_gl_context(0, &ctx_params);
   if (vrend_state.sync_context == NULL) {
      vrend_printf( "failed to create sync opengl context\n");
      return;
   }

   if (!vrend_state.use_async_fence_cb) {
      vrend_state.eventfd = create_eventfd(0);
      if (vrend_state.eventfd == -1) {
         vrend_printf( "Failed to create eventfd\n");
         vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
         return;
      }
   }

   cnd_init(&vrend_state.fence_cond);
   mtx_init(&vrend_state.fence_mutex, mtx_plain);

   vrend_state.sync_thread = u_thread_create(thread_sync, NULL);
   if (!vrend_state.sync_thread) {
      if (vrend_state.eventfd != -1) {
         close(vrend_state.eventfd);
         vrend_state.eventfd = -1;
      }
      vrend_clicbs->destroy_gl_context(vrend_state.sync_context);
      cnd_destroy(&vrend_state.fence_cond);
      mtx_destroy(&vrend_state.fence_mutex);
   }
}