File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 11use unity_native_plugin_sys:: * ;
2+ use std:: sync:: OnceLock ;
23
34pub trait UnityInterface {
45 fn get_interface_guid ( ) -> UnityInterfaceGUID ;
56 fn new ( interface : * const IUnityInterface ) -> Self ;
67}
78
8- static mut UNITY_INTERFACES : Option < UnityInterfaces > = None ;
9+ static UNITY_INTERFACES : OnceLock < UnityInterfaces > = OnceLock :: new ( ) ;
910
1011pub struct UnityInterfaces {
1112 interfaces : * mut unity_native_plugin_sys:: IUnityInterfaces ,
1213}
1314
15+ // maybe thread safety
16+ unsafe impl Send for UnityInterfaces { }
17+ unsafe impl Sync for UnityInterfaces { }
18+
19+
1420impl UnityInterfaces {
1521 pub fn get ( ) -> & ' static UnityInterfaces {
16- unsafe { UNITY_INTERFACES . as_ref ( ) . unwrap ( ) }
22+ UNITY_INTERFACES . get ( ) . unwrap ( )
1723 }
1824
1925 pub fn set_native_unity_interfaces ( interfaces : * mut unity_native_plugin_sys:: IUnityInterfaces ) {
20- unsafe {
21- UNITY_INTERFACES = if !interfaces. is_null ( ) {
22- Some ( UnityInterfaces { interfaces } )
23- } else {
24- None
25- }
26+ if !interfaces. is_null ( ) {
27+ let unity_interfaces = UnityInterfaces { interfaces } ;
28+ let _ = UNITY_INTERFACES . set ( unity_interfaces) ;
2629 }
2730 }
2831
You can’t perform that action at this time.
0 commit comments