@@ -54,30 +54,6 @@ mod single_threaded {
54
54
}
55
55
}
56
56
57
- pub ( crate ) fn on_inc_ref ( & self ) {
58
- let refc = self . godot_ref_count . get ( ) + 1 ;
59
- self . godot_ref_count . set ( refc) ;
60
-
61
- out ! (
62
- " Storage::on_inc_ref (rc={}) <{}>" , // -- {:?}",
63
- refc,
64
- type_name:: <T >( ) ,
65
- //self.user_instance
66
- ) ;
67
- }
68
-
69
- pub ( crate ) fn on_dec_ref ( & self ) {
70
- let refc = self . godot_ref_count . get ( ) - 1 ;
71
- self . godot_ref_count . set ( refc) ;
72
-
73
- out ! (
74
- " | Storage::on_dec_ref (rc={}) <{}>" , // -- {:?}",
75
- refc,
76
- type_name:: <T >( ) ,
77
- //self.user_instance
78
- ) ;
79
- }
80
-
81
57
pub fn is_bound ( & self ) -> bool {
82
58
// Needs to borrow mutably, otherwise it succeeds if shared borrows are alive.
83
59
self . user_instance . try_borrow_mut ( ) . is_err ( )
@@ -115,6 +91,30 @@ mod single_threaded {
115
91
pub ( super ) fn godot_ref_count ( & self ) -> u32 {
116
92
self . godot_ref_count . get ( )
117
93
}
94
+
95
+ pub ( crate ) fn on_inc_ref ( & self ) {
96
+ let refc = self . godot_ref_count . get ( ) + 1 ;
97
+ self . godot_ref_count . set ( refc) ;
98
+
99
+ out ! (
100
+ " Storage::on_inc_ref (rc={}) <{}>" , // -- {:?}",
101
+ refc,
102
+ type_name:: <T >( ) ,
103
+ //self.user_instance
104
+ ) ;
105
+ }
106
+
107
+ pub ( crate ) fn on_dec_ref ( & self ) {
108
+ let refc = self . godot_ref_count . get ( ) - 1 ;
109
+ self . godot_ref_count . set ( refc) ;
110
+
111
+ out ! (
112
+ " | Storage::on_dec_ref (rc={}) <{}>" , // -- {:?}",
113
+ refc,
114
+ type_name:: <T >( ) ,
115
+ //self.user_instance
116
+ ) ;
117
+ }
118
118
}
119
119
}
120
120
@@ -180,24 +180,6 @@ mod multi_threaded {
180
180
}
181
181
}
182
182
183
- pub ( crate ) fn on_inc_ref ( & self ) {
184
- self . godot_ref_count . fetch_add ( 1 , Ordering :: Relaxed ) ;
185
- out ! (
186
- " Storage::on_inc_ref (rc={}) <{:?}>" ,
187
- self . godot_ref_count( ) ,
188
- self . base,
189
- ) ;
190
- }
191
-
192
- pub ( crate ) fn on_dec_ref ( & self ) {
193
- self . godot_ref_count . fetch_sub ( 1 , Ordering :: Relaxed ) ;
194
- out ! (
195
- " | Storage::on_dec_ref (rc={}) <{:?}>" ,
196
- self . godot_ref_count( ) ,
197
- self . base,
198
- ) ;
199
- }
200
-
201
183
pub fn is_bound ( & self ) -> bool {
202
184
// Needs to borrow mutably, otherwise it succeeds if shared borrows are alive.
203
185
self . write_ignoring_poison ( ) . is_none ( )
@@ -225,6 +207,35 @@ mod multi_threaded {
225
207
} )
226
208
}
227
209
210
+ pub fn get_gd ( & self ) -> Gd < T >
211
+ where
212
+ T : Inherits < <T as GodotClass >:: Base > ,
213
+ {
214
+ self . base . clone ( ) . cast ( )
215
+ }
216
+
217
+ pub ( super ) fn godot_ref_count ( & self ) -> u32 {
218
+ self . godot_ref_count . load ( Ordering :: Relaxed )
219
+ }
220
+
221
+ pub ( crate ) fn on_inc_ref ( & self ) {
222
+ self . godot_ref_count . fetch_add ( 1 , Ordering :: Relaxed ) ;
223
+ out ! (
224
+ " Storage::on_inc_ref (rc={}) <{:?}>" ,
225
+ self . godot_ref_count( ) ,
226
+ self . base,
227
+ ) ;
228
+ }
229
+
230
+ pub ( crate ) fn on_dec_ref ( & self ) {
231
+ self . godot_ref_count . fetch_sub ( 1 , Ordering :: Relaxed ) ;
232
+ out ! (
233
+ " | Storage::on_dec_ref (rc={}) <{:?}>" ,
234
+ self . godot_ref_count( ) ,
235
+ self . base,
236
+ ) ;
237
+ }
238
+
228
239
/// Returns a write guard (even if poisoned), or `None` when the lock is held by another thread.
229
240
/// This might need adjustment if threads should await locks.
230
241
#[ must_use]
@@ -247,17 +258,6 @@ mod multi_threaded {
247
258
}
248
259
}
249
260
250
- pub fn get_gd ( & self ) -> Gd < T >
251
- where
252
- T : Inherits < <T as GodotClass >:: Base > ,
253
- {
254
- self . base . clone ( ) . cast ( )
255
- }
256
-
257
- pub ( super ) fn godot_ref_count ( & self ) -> u32 {
258
- self . godot_ref_count . load ( Ordering :: Relaxed )
259
- }
260
-
261
261
// fn __static_type_check() {
262
262
// enforce_sync::<InstanceStorage<T>>();
263
263
// }
@@ -267,10 +267,12 @@ mod multi_threaded {
267
267
// This type can be accessed concurrently from multiple threads, so it should be Sync. That implies however that T must be Sync too
268
268
// (and possibly Send, because with `&mut` access, a `T` can be extracted as a value using mem::take() etc.).
269
269
// Which again means that we need to infest half the codebase with T: Sync + Send bounds, *and* make it all conditional on
270
- // `#[cfg(feature = "experimental-threads")]`. Until the multi-threading design is clarified, we'll thus leave it as is.
270
+ // `#[cfg(feature = "experimental-threads")]`.
271
+ //
272
+ // A better design would be a distinct Gds<T: Sync> pointer, which requires synchronized.
273
+ // This needs more design on the multi-threading front (#18).
271
274
//
272
275
// The following code + __static_type_check() above would make sure that InstanceStorage is Sync.
273
-
274
276
// Make sure storage is Sync in multi-threaded case, as it can be concurrently accessed through aliased Gd<T> pointers.
275
277
// fn enforce_sync<T: Sync>() {}
276
278
}
0 commit comments