diff --git a/src/gallium/frontends/rusticl/api/platform.rs b/src/gallium/frontends/rusticl/api/platform.rs index dc448e01b6b..7641ff33279 100644 --- a/src/gallium/frontends/rusticl/api/platform.rs +++ b/src/gallium/frontends/rusticl/api/platform.rs @@ -44,6 +44,9 @@ pub fn get_platform_ids( return Err(CL_INVALID_VALUE); } + // run initialization code once + Platform::init_once(); + // platforms returns a list of OpenCL platforms available for access through the Khronos ICD Loader. // The cl_platform_id values returned in platforms are ICD compatible and can be used to identify a // specific OpenCL platform. If the platforms argument is NULL, then this argument is ignored. The diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index 41e77a15239..0a3e22e8af5 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -39,8 +39,7 @@ impl Platform { } pub fn get() -> &'static Self { - // SAFETY: no concurrent static mut access due to std::Once - PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() }); + debug_assert!(PLATFORM_ONCE.is_completed()); // SAFETY: no mut references exist at this point unsafe { &PLATFORM } } @@ -60,6 +59,11 @@ impl Platform { } } } + + pub fn init_once() { + // SAFETY: no concurrent static mut access due to std::Once + PLATFORM_ONCE.call_once(|| unsafe { PLATFORM.init() }); + } } impl Drop for Platform {