Skip to content

Commit 13466b5

Browse files
committed
fix #419
1 parent c89185c commit 13466b5

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

application.go

-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ func (a *Application) Run() error {
206206

207207
// Attach GL callback functions onto the engine
208208
a.engine.GLMakeCurrent = func() bool {
209-
fmt.Println("-- GLMakeCurrent")
210209
a.window.MakeContextCurrent()
211210
return true
212211
}
@@ -225,7 +224,6 @@ func (a *Application) Run() error {
225224
if a.resourceWindow == nil {
226225
return false
227226
}
228-
fmt.Println("-- GLMakeResourceCurrent")
229227
a.resourceWindow.MakeContextCurrent()
230228
return true
231229
}

event-loop.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"math"
77
"time"
88

9-
"github.com/davecgh/go-spew/spew"
109
"github.com/go-flutter-desktop/go-flutter/embedder"
1110
"github.com/go-flutter-desktop/go-flutter/internal/currentthread"
1211
"github.com/go-flutter-desktop/go-flutter/internal/priorityqueue"
@@ -26,13 +25,12 @@ type EventLoop struct {
2625
platformMessageRefreshRate time.Duration
2726

2827
// identifier for the current thread
29-
mainThreadID int64
28+
mainThreadID currentthread.ThreadID
3029
}
3130

3231
func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTask) embedder.Result) *EventLoop {
3332
pq := priorityqueue.NewPriorityQueue()
3433
heap.Init(pq)
35-
fmt.Println("EventLoop Thread id: " + spew.Sdump(currentthread.ID()))
3634
return &EventLoop{
3735
priorityqueue: pq,
3836
postEmptyEvent: postEmptyEvent,
@@ -54,9 +52,7 @@ func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTas
5452
// RunOnCurrentThread return true if tasks posted on the
5553
// calling thread will be run on that same thread.
5654
func (t *EventLoop) RunOnCurrentThread() bool {
57-
id := currentthread.ID()
58-
fmt.Println("Task Thread id: " + spew.Sdump(id))
59-
return id == t.mainThreadID
55+
return currentthread.Equal(currentthread.ID(), t.mainThreadID)
6056
}
6157

6258
// PostTask posts a Flutter engine tasks to the event loop for delayed execution.

internal/currentthread/thread-id.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package currentthread gives you access to the underlying thread id.
1+
// Package currentthread gives you access to the underlying C thread id.
22
package currentthread
33

44
// //
@@ -8,29 +8,38 @@ package currentthread
88
// /* Platform specific includes */
99
// #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
1010
// #include <windows.h>
11-
// typedef HANDLE thrd_t;
11+
// typedef DWORD thrd_t;
1212
// #else
1313
// #include <pthread.h>
1414
// typedef pthread_t thrd_t;
1515
// #endif
1616
//
17+
// int thrd_equal(thrd_t thr0, thrd_t thr1) {
18+
// #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
19+
// return thr0 == thr1;
20+
// #else
21+
// return pthread_equal(thr0, thr1);
22+
// #endif
23+
// }
24+
//
1725
// thrd_t thrd_current(void) {
1826
// #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
19-
// return GetCurrentThread();
27+
// return GetCurrentThreadId();
2028
// #else
2129
// return pthread_self();
2230
// #endif
2331
// }
24-
// size_t getCurrentThreadID() { return (size_t)thrd_current(); }
2532
import "C"
26-
import (
27-
"fmt"
2833

29-
"github.com/davecgh/go-spew/spew"
30-
)
34+
// ThreadID correspond to an opaque thread identifier
35+
type ThreadID C.thrd_t
3136

3237
// ID returns the id of the current thread
33-
func ID() int64 {
34-
fmt.Println("Real Thread id: " + spew.Sdump(C.thrd_current()))
35-
return (int64)(C.getCurrentThreadID())
38+
func ID() ThreadID {
39+
return (ThreadID)(C.thrd_current())
40+
}
41+
42+
// Equal compares two thread identifiers.
43+
func Equal(t1, t2 ThreadID) bool {
44+
return C.thrd_equal((C.thrd_t)(t1), (C.thrd_t)(t2)) != 0
3645
}

0 commit comments

Comments
 (0)