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