@@ -71,14 +71,25 @@ impl IconInfo {
71
71
}
72
72
73
73
#[ doc( alias = "gtk_icon_info_load_icon_async" ) ]
74
- pub fn load_icon_async < P : FnOnce ( Result < gdk_pixbuf:: Pixbuf , glib:: Error > ) + Send + ' static > (
74
+ pub fn load_icon_async < P : FnOnce ( Result < gdk_pixbuf:: Pixbuf , glib:: Error > ) + ' static > (
75
75
& self ,
76
76
cancellable : Option < & impl IsA < gio:: Cancellable > > ,
77
77
callback : P ,
78
78
) {
79
- let user_data: Box_ < P > = Box_ :: new ( callback) ;
79
+ let main_context = glib:: MainContext :: ref_thread_default ( ) ;
80
+ let is_main_context_owner = main_context. is_owner ( ) ;
81
+ let has_acquired_main_context = ( !is_main_context_owner)
82
+ . then ( || main_context. acquire ( ) . ok ( ) )
83
+ . flatten ( ) ;
84
+ assert ! (
85
+ is_main_context_owner || has_acquired_main_context. is_some( ) ,
86
+ "Async operations only allowed if the thread is owning the MainContext"
87
+ ) ;
88
+
89
+ let user_data: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
90
+ Box_ :: new ( glib:: thread_guard:: ThreadGuard :: new ( callback) ) ;
80
91
unsafe extern "C" fn load_icon_async_trampoline <
81
- P : FnOnce ( Result < gdk_pixbuf:: Pixbuf , glib:: Error > ) + Send + ' static ,
92
+ P : FnOnce ( Result < gdk_pixbuf:: Pixbuf , glib:: Error > ) + ' static ,
82
93
> (
83
94
_source_object : * mut glib:: gobject_ffi:: GObject ,
84
95
res : * mut gio:: ffi:: GAsyncResult ,
@@ -92,7 +103,9 @@ impl IconInfo {
92
103
} else {
93
104
Err ( from_glib_full ( error) )
94
105
} ;
95
- let callback: Box_ < P > = Box_ :: from_raw ( user_data as * mut _ ) ;
106
+ let callback: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
107
+ Box_ :: from_raw ( user_data as * mut _ ) ;
108
+ let callback: P = callback. into_inner ( ) ;
96
109
callback ( result) ;
97
110
}
98
111
let callback = load_icon_async_trampoline :: < P > ;
@@ -169,7 +182,7 @@ impl IconInfo {
169
182
170
183
#[ doc( alias = "gtk_icon_info_load_symbolic_async" ) ]
171
184
pub fn load_symbolic_async <
172
- P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + Send + ' static ,
185
+ P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + ' static ,
173
186
> (
174
187
& self ,
175
188
fg : & gdk:: RGBA ,
@@ -179,9 +192,20 @@ impl IconInfo {
179
192
cancellable : Option < & impl IsA < gio:: Cancellable > > ,
180
193
callback : P ,
181
194
) {
182
- let user_data: Box_ < P > = Box_ :: new ( callback) ;
195
+ let main_context = glib:: MainContext :: ref_thread_default ( ) ;
196
+ let is_main_context_owner = main_context. is_owner ( ) ;
197
+ let has_acquired_main_context = ( !is_main_context_owner)
198
+ . then ( || main_context. acquire ( ) . ok ( ) )
199
+ . flatten ( ) ;
200
+ assert ! (
201
+ is_main_context_owner || has_acquired_main_context. is_some( ) ,
202
+ "Async operations only allowed if the thread is owning the MainContext"
203
+ ) ;
204
+
205
+ let user_data: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
206
+ Box_ :: new ( glib:: thread_guard:: ThreadGuard :: new ( callback) ) ;
183
207
unsafe extern "C" fn load_symbolic_async_trampoline <
184
- P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + Send + ' static ,
208
+ P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + ' static ,
185
209
> (
186
210
_source_object : * mut glib:: gobject_ffi:: GObject ,
187
211
res : * mut gio:: ffi:: GAsyncResult ,
@@ -201,7 +225,9 @@ impl IconInfo {
201
225
} else {
202
226
Err ( from_glib_full ( error) )
203
227
} ;
204
- let callback: Box_ < P > = Box_ :: from_raw ( user_data as * mut _ ) ;
228
+ let callback: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
229
+ Box_ :: from_raw ( user_data as * mut _ ) ;
230
+ let callback: P = callback. into_inner ( ) ;
205
231
callback ( result) ;
206
232
}
207
233
let callback = load_symbolic_async_trampoline :: < P > ;
@@ -274,16 +300,27 @@ impl IconInfo {
274
300
275
301
#[ doc( alias = "gtk_icon_info_load_symbolic_for_context_async" ) ]
276
302
pub fn load_symbolic_for_context_async <
277
- P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + Send + ' static ,
303
+ P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + ' static ,
278
304
> (
279
305
& self ,
280
306
context : & impl IsA < StyleContext > ,
281
307
cancellable : Option < & impl IsA < gio:: Cancellable > > ,
282
308
callback : P ,
283
309
) {
284
- let user_data: Box_ < P > = Box_ :: new ( callback) ;
310
+ let main_context = glib:: MainContext :: ref_thread_default ( ) ;
311
+ let is_main_context_owner = main_context. is_owner ( ) ;
312
+ let has_acquired_main_context = ( !is_main_context_owner)
313
+ . then ( || main_context. acquire ( ) . ok ( ) )
314
+ . flatten ( ) ;
315
+ assert ! (
316
+ is_main_context_owner || has_acquired_main_context. is_some( ) ,
317
+ "Async operations only allowed if the thread is owning the MainContext"
318
+ ) ;
319
+
320
+ let user_data: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
321
+ Box_ :: new ( glib:: thread_guard:: ThreadGuard :: new ( callback) ) ;
285
322
unsafe extern "C" fn load_symbolic_for_context_async_trampoline <
286
- P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + Send + ' static ,
323
+ P : FnOnce ( Result < ( gdk_pixbuf:: Pixbuf , bool ) , glib:: Error > ) + ' static ,
287
324
> (
288
325
_source_object : * mut glib:: gobject_ffi:: GObject ,
289
326
res : * mut gio:: ffi:: GAsyncResult ,
@@ -303,7 +340,9 @@ impl IconInfo {
303
340
} else {
304
341
Err ( from_glib_full ( error) )
305
342
} ;
306
- let callback: Box_ < P > = Box_ :: from_raw ( user_data as * mut _ ) ;
343
+ let callback: Box_ < glib:: thread_guard:: ThreadGuard < P > > =
344
+ Box_ :: from_raw ( user_data as * mut _ ) ;
345
+ let callback: P = callback. into_inner ( ) ;
307
346
callback ( result) ;
308
347
}
309
348
let callback = load_symbolic_for_context_async_trampoline :: < P > ;
0 commit comments