5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- #! [ allow ( dead_code ) ] // FIXME
9
-
8
+ use crate :: builtin :: meta :: ClassName ;
9
+ use crate :: builtin :: StringName ;
10
10
use crate :: init:: InitLevel ;
11
11
use crate :: log;
12
12
use crate :: obj:: * ;
13
+ use crate :: out;
13
14
use crate :: private:: as_storage;
14
15
use crate :: storage:: InstanceStorage ;
15
16
use godot_ffi as sys;
16
17
17
18
use sys:: interface_fn;
18
19
19
- use crate :: builtin:: meta:: ClassName ;
20
- use crate :: builtin:: StringName ;
21
- use crate :: out;
22
20
use std:: any:: Any ;
23
21
use std:: collections:: HashMap ;
24
22
use std:: sync:: { Mutex , MutexGuard , TryLockError } ;
25
23
use std:: { fmt, ptr} ;
26
24
27
- // For now, that variable is needed for class unregistering. It's populated during class
28
- // registering. There is no actual concurrency here, because Godot call register/unregister in main
29
- // thread - Mutex is just casual way to ensure safety in this performance non-critical path.
30
- // Note that we panic on concurrent access instead of blocking - that's fail fast approach. If that
31
- // happen, most likely something changed on Godot side and analysis required to adopt these changes .
25
+ // Needed for class unregistering. The variable is populated during class registering. There is no actual concurrency here, because Godot
26
+ // calls register/unregister in the main thread. Mutex is just casual way to ensure safety in this non-performance-critical path.
27
+ // Note that we panic on concurrent access instead of blocking (fail-fast approach). If that happens, most likely something changed on Godot
28
+ // side and analysis required to adopt these changes.
29
+ // For now, don't use Global<T> because we need try_lock(), which isn't yet provided .
32
30
static LOADED_CLASSES : Mutex < Option < HashMap < InitLevel , Vec < ClassName > > > > = Mutex :: new ( None ) ;
33
31
34
32
// TODO(bromeon): some information coming from the proc-macro API is deferred through PluginComponent, while others is directly
@@ -182,6 +180,7 @@ struct ClassRegistrationInfo {
182
180
godot_params : sys:: GDExtensionClassCreationInfo ,
183
181
#[ cfg( since_api = "4.2" ) ]
184
182
godot_params : sys:: GDExtensionClassCreationInfo2 ,
183
+ #[ allow( dead_code) ] // Currently unused; may be useful for diagnostics in the future.
185
184
init_level : InitLevel ,
186
185
is_editor_plugin : bool ,
187
186
}
@@ -305,7 +304,7 @@ pub fn unregister_classes(init_level: InitLevel) {
305
304
. unwrap_or_default ( ) ;
306
305
out ! ( "Unregistering classes of level {init_level:?}..." ) ;
307
306
for class_name in loaded_classes_current_level. iter ( ) . rev ( ) {
308
- unregister_class_raw ( class_name) ;
307
+ unregister_class_raw ( * class_name) ;
309
308
}
310
309
}
311
310
@@ -315,9 +314,9 @@ fn get_loaded_classes_with_mutex() -> MutexGuard<'static, Option<HashMap<InitLev
315
314
Ok ( it) => it,
316
315
Err ( err) => match err {
317
316
TryLockError :: Poisoned ( _err) => panic ! (
318
- "LOADED_CLASSES poisoned. seems like class registration or deregistration panicked. "
317
+ "global lock for loaded classes poisoned; class registration or deregistration may have panicked"
319
318
) ,
320
- TryLockError :: WouldBlock => panic ! ( "unexpected concurrent access detected to CLASSES " ) ,
319
+ TryLockError :: WouldBlock => panic ! ( "unexpected concurrent access to global lock for loaded classes " ) ,
321
320
} ,
322
321
}
323
322
}
@@ -494,7 +493,7 @@ fn register_class_raw(mut info: ClassRegistrationInfo) {
494
493
assert ! ( !info. is_editor_plugin) ;
495
494
}
496
495
497
- fn unregister_class_raw ( class_name : & ClassName ) {
496
+ fn unregister_class_raw ( class_name : ClassName ) {
498
497
out ! ( "Unregister class: {class_name}" ) ;
499
498
unsafe {
500
499
#[ allow( clippy:: let_unit_value) ]
0 commit comments