@@ -189,12 +189,9 @@ open class AndroidLooperExecutor: SerialExecutor, @unchecked Sendable {
189
189
}
190
190
}
191
191
192
- //var _signalCount = UInt64(0)
193
-
194
192
/// Increment number of remaining events on eventFd
195
193
func signal( ) throws {
196
194
var value = UInt64 ( 1 )
197
- //logger.info("### AndroidLooperExecutor.signal(): \(value)")
198
195
try withUnsafeBytes ( of: & value) {
199
196
guard try _eventFd. write ( $0) == MemoryLayout< UInt64> . size else {
200
197
throw Errno . outOfRange
@@ -205,43 +202,16 @@ open class AndroidLooperExecutor: SerialExecutor, @unchecked Sendable {
205
202
/// Drain job queue
206
203
fileprivate func drain( ) {
207
204
if let eventsRemaining = try ? eventsRemaining {
208
- //logger.info("### AndroidLooperExecutor.drain(): \(eventsRemaining)")
209
- //var handledSource = 0
210
205
for _ in 0 ..< eventsRemaining {
211
- //handledSource += CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, true) == CFRunLoopRunResult.handledSource ? 1 : 0
212
- //logger.info("### CFRunLoopRunInMode result: \(result)")
213
-
214
206
let job = dequeue ( )
215
207
guard let job else { break }
216
208
job. runSynchronously ( on: asUnownedSerialExecutor ( ) )
217
209
}
218
-
219
- // if handledSource < eventsRemaining {
220
- // try! signal()
221
- //// CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.01, false)
222
- // }
223
210
}
224
211
225
- // always dispatch the pending main queue callbacks
226
- // https://forums.swift.org/t/main-dispatch-queue-in-linux-sdl-app/31708/3
227
- //_dispatch_main_queue_callback_4CF() // check for DispatchQueue.main
228
-
229
212
while CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0.0 , true ) == CFRunLoopRunResult . handledSource {
230
213
// continue handling queued events without a timeout
231
214
}
232
-
233
- // block and wait for a source; this is needed because the no-timeout version is sometimes run before the action gets added
234
- //CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.001, false)
235
-
236
- //assert(Thread.isMainThread)
237
-
238
-
239
- // while CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, true) == CFRunLoopRunResult.handledSource {
240
- // // keep running until we have processed all the pending sources
241
- // //DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: drain)
242
- // //_dispatch_main_queue_callback_4CF()
243
- // }
244
-
245
215
}
246
216
247
217
/// Dequeue a single job
@@ -293,23 +263,29 @@ private extension AndroidMainActor {
293
263
guard !didInstallGlobalExecutor else { return }
294
264
didInstallGlobalExecutor = true
295
265
296
- typealias swift_task_enqueueGlobal_hook_Fn = @convention ( thin) ( UnsafeMutablePointer < Job > , swift_task_enqueueGlobal_original ) -> Void
297
- let swift_task_enqueueGlobal_hook_impl : swift_task_enqueueGlobal_hook_Fn = { job, original in
298
- //logger.info("### swift_task_enqueueGlobal_hook_impl: job: \(job)")
299
- original ( job)
300
- try ! AndroidMainActor . _executor. signal ( )
266
+ // typealias swift_task_enqueueGlobal_hook_Fn = @convention(thin) (UnsafeMutablePointer<Job>, swift_task_enqueueGlobal_original) -> Void
267
+ // let swift_task_enqueueGlobal_hook_impl: swift_task_enqueueGlobal_hook_Fn = { job, original in
268
+ // logger.info("### swift_task_enqueueGlobal_hook_impl: job: \(job.pointee)")
269
+ //
270
+ //// let flags = job.pointee.Flags
271
+ //// let unownedJob = unsafeBitCast(job.pointee, to: UnownedJob.self) // Fatal error: Can't unsafeBitCast between types of different sizes
272
+ //// logger.info("### swift_task_enqueueGlobal_hook_impl: unownedJob: \(unownedJob)")
273
+ //
274
+ // //AndroidMainActor._executor.enqueue(unownedJob)
275
+ //
276
+ // original(job)
277
+ // try! AndroidMainActor._executor.signal()
278
+ // }
279
+ // swift_task_enqueueGlobal_hook = unsafeBitCast(swift_task_enqueueGlobal_hook_impl, to: UnsafeMutableRawPointer?.self)
301
280
302
- }
303
- swift_task_enqueueGlobal_hook = unsafeBitCast ( swift_task_enqueueGlobal_hook_impl, to: UnsafeMutableRawPointer ? . self)
304
-
305
- // this would be a better way to signal the main looper, but unfortunately it is never called: https://github.com/swiftlang/swift/issues/63104
306
- typealias swift_task_enqueueMainExecutor_hook_Fn = @convention ( thin) ( UnsafeMutablePointer < Job > , swift_task_enqueueMainExecutor_original ) -> Void
307
- let swift_task_enqueueMainExecutor_hook_impl : swift_task_enqueueMainExecutor_hook_Fn = { job, original in
308
- //logger.info("### swift_task_enqueueMainExecutor_hook_Fn")
309
- original ( job)
310
- try ! AndroidMainActor . _executor. signal ( ) // signal the main looper to wake a drain the main queue
311
- }
312
- swift_task_enqueueMainExecutor_hook = unsafeBitCast ( swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer ? . self)
281
+ // // this would be a better way to signal the main looper, but unfortunately it is never called: https://github.com/swiftlang/swift/issues/63104
282
+ // typealias swift_task_enqueueMainExecutor_hook_Fn = @convention(thin) (UnsafeMutablePointer<Job>, swift_task_enqueueMainExecutor_original) -> Void
283
+ // let swift_task_enqueueMainExecutor_hook_impl: swift_task_enqueueMainExecutor_hook_Fn = { job, original in
284
+ // //logger.info("### swift_task_enqueueMainExecutor_hook_Fn")
285
+ // original(job)
286
+ // try! AndroidMainActor._executor.signal() // signal the main looper to wake a drain the main queue
287
+ // }
288
+ // swift_task_enqueueMainExecutor_hook = unsafeBitCast(swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer?.self)
313
289
314
290
315
291
// typealias swift_task_enqueueGlobalWithDelay_hook_Fn = @convention(thin) (UInt64, UnsafeMutablePointer<Job>, swift_task_enqueueGlobalWithDelay_original) -> Void
@@ -339,8 +315,8 @@ private extension AndroidMainActor {
339
315
}
340
316
}
341
317
342
- // https://github.com/apple-oss-distributions/libdispatch/blob/bd82a60ee6a73b4eca50af028b48643d51aaf1ea/src/queue.c#L8237
343
- // https://forums.swift.org/t/main-dispatch-queue-in-linux-sdl-app/31708/3
344
- @_silgen_name ( " _dispatch_main_queue_callback_4CF " )
345
- func _dispatch_main_queue_callback_4CF( )
318
+ //// https://github.com/apple-oss-distributions/libdispatch/blob/bd82a60ee6a73b4eca50af028b48643d51aaf1ea/src/queue.c#L8237
319
+ //// https://forums.swift.org/t/main-dispatch-queue-in-linux-sdl-app/31708/3
320
+ // @_silgen_name("_dispatch_main_queue_callback_4CF")
321
+ // func _dispatch_main_queue_callback_4CF()
346
322
#endif
0 commit comments