Skip to content

Commit 97968a6

Browse files
committed
rutabaga: consider virgl initialized if successful
It's only possible to call VirglRenderer::init() once to prevent attempting to initialize virglrenderer twice. But this also prevents us for retrying the initialization if the first time fails. Let's only set the INIT_ONCE atomic when the call to virgl_renderer_init has been successful. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 27b2ce2 commit 97968a6

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/rutabaga_gfx/src/virgl_renderer.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,6 @@ impl VirglRenderer {
301301
}
302302
}
303303

304-
// virglrenderer is a global state backed library that uses thread bound OpenGL contexts.
305-
// Initialize it only once and use the non-send/non-sync Renderer struct to keep things tied
306-
// to whichever thread called this function first.
307-
static INIT_ONCE: AtomicBool = AtomicBool::new(false);
308-
if INIT_ONCE
309-
.compare_exchange(false, true, Ordering::Acquire, Ordering::Acquire)
310-
.is_err()
311-
{
312-
return Err(RutabagaError::AlreadyInUse);
313-
}
314-
315304
unsafe { virgl_set_debug_callback(Some(debug_callback)) };
316305

317306
// Cookie is intentionally never freed because virglrenderer never gets uninitialized.
@@ -335,6 +324,19 @@ impl VirglRenderer {
335324
)
336325
};
337326

327+
if ret == 0 {
328+
// virglrenderer is a global state backed library that uses thread bound OpenGL contexts.
329+
// Initialize it only once and use the non-send/non-sync Renderer struct to keep things tied
330+
// to whichever thread called this function first.
331+
static INIT_ONCE: AtomicBool = AtomicBool::new(false);
332+
if INIT_ONCE
333+
.compare_exchange(false, true, Ordering::Acquire, Ordering::Acquire)
334+
.is_err()
335+
{
336+
return Err(RutabagaError::AlreadyInUse);
337+
}
338+
}
339+
338340
ret_to_res(ret)?;
339341
Ok(Box::new(VirglRenderer {}))
340342
}

0 commit comments

Comments
 (0)