@@ -7,12 +7,11 @@ import (
7
7
"time"
8
8
9
9
"github.com/go-flutter-desktop/go-flutter/embedder"
10
- "github.com/go-flutter-desktop/go-flutter/internal/currentthread"
11
10
"github.com/go-flutter-desktop/go-flutter/internal/priorityqueue"
12
11
)
13
12
14
13
// EventLoop is a event loop for the main thread that allows for delayed task
15
- // execution.
14
+ // execution.()
16
15
type EventLoop struct {
17
16
// store the task (event) by their priorities
18
17
priorityqueue * priorityqueue.PriorityQueue
@@ -23,19 +22,17 @@ type EventLoop struct {
23
22
24
23
// timeout for non-Rendering events that needs to be processed in a polling manner
25
24
platformMessageRefreshRate time.Duration
26
-
27
- // identifier for the current thread
28
- mainThreadID int64
29
25
}
30
26
27
+ // newEventLoop must ALWAYS be called if the calling goroutine is
28
+ // `runtime.LockOSThread()`
31
29
func newEventLoop (postEmptyEvent func (), onExpiredTask func (* embedder.FlutterTask ) embedder.Result ) * EventLoop {
32
30
pq := priorityqueue .NewPriorityQueue ()
33
31
heap .Init (pq )
34
32
return & EventLoop {
35
33
priorityqueue : pq ,
36
34
postEmptyEvent : postEmptyEvent ,
37
35
onExpiredTask : onExpiredTask ,
38
- mainThreadID : currentthread .ID (),
39
36
40
37
// 25 Millisecond is arbitrary value, not too high (adds too much delay to
41
38
// platform messages) and not too low (heavy CPU consumption).
@@ -49,10 +46,17 @@ func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTas
49
46
}
50
47
}
51
48
52
- // RunOnCurrentThread return true if tasks posted on the
53
- // calling thread will be run on that same thread.
49
+ // RunOnCurrentThread FlutterDocs:
50
+ // May be called from any thread. Should return true if tasks posted on the
51
+ // calling thread will be run on that same thread.
52
+ //
53
+ // The functions PostTask and onExpiredTask should be called from the same
54
+ // thread, this is ensured if the creation of the event loop (through
55
+ // `newEventLoop`) and the PostTask callback (through
56
+ // `a.engine.TaskRunnerPostTask = eventLoop.PostTask`) are done on a calling
57
+ // goroutine which always execute in that thread (`runtime.LockOSThread()`).
54
58
func (t * EventLoop ) RunOnCurrentThread () bool {
55
- return currentthread . ID () == t . mainThreadID
59
+ return true
56
60
}
57
61
58
62
// PostTask posts a Flutter engine tasks to the event loop for delayed execution.
0 commit comments