From 498f51188f3d944a2addc983a2541658ec717fa4 Mon Sep 17 00:00:00 2001 From: Pierre Champion | Drakirus Date: Sat, 2 May 2020 11:32:50 +0200 Subject: [PATCH] Revert "fixes #133: same task runner for platform&render" --- application.go | 2 -- embedder/embedder.go | 1 - embedder/embedder_helper.c | 2 -- event-loop.go | 22 ++++++++++++--------- internal/currentthread/thread-id.go | 30 ----------------------------- 5 files changed, 13 insertions(+), 44 deletions(-) delete mode 100644 internal/currentthread/thread-id.go diff --git a/application.go b/application.go index ebd2d010..849992c2 100644 --- a/application.go +++ b/application.go @@ -260,8 +260,6 @@ func (a *Application) Run() error { fmt.Printf("go-flutter: engine.Run() returned result code %d (invalid library version)\n", result) case embedder.ResultInvalidArguments: fmt.Printf("go-flutter: engine.Run() returned result code %d (invalid arguments)\n", result) - case embedder.ResultInternalInconsistency: - fmt.Printf("go-flutter: engine.Run() returned result code %d (internal inconsistency)\n", result) default: fmt.Printf("go-flutter: engine.Run() returned result code %d (unknown result code)\n", result) } diff --git a/embedder/embedder.go b/embedder/embedder.go index 2068905d..a22c854c 100644 --- a/embedder/embedder.go +++ b/embedder/embedder.go @@ -30,7 +30,6 @@ const ( ResultSuccess Result = C.kSuccess ResultInvalidLibraryVersion Result = C.kInvalidLibraryVersion ResultInvalidArguments Result = C.kInvalidArguments - ResultInternalInconsistency Result = C.kInternalInconsistency ResultEngineNotRunning Result = -1 ) diff --git a/embedder/embedder_helper.c b/embedder/embedder_helper.c index 9e37d997..db8e2657 100644 --- a/embedder/embedder_helper.c +++ b/embedder/embedder_helper.c @@ -51,9 +51,7 @@ FlutterEngineResult runFlutter(void *user_data, FlutterEngine *engine, FlutterPr FlutterCustomTaskRunners custom_task_runners = {}; custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners); - // Render task and platform task are handled by the same TaskRunner custom_task_runners.platform_task_runner = &platform_task_runner; - custom_task_runners.render_task_runner = &platform_task_runner; Args->custom_task_runners = &custom_task_runners; return FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, Args, user_data, diff --git a/event-loop.go b/event-loop.go index f4665c61..30c12a43 100644 --- a/event-loop.go +++ b/event-loop.go @@ -7,12 +7,11 @@ import ( "time" "github.com/go-flutter-desktop/go-flutter/embedder" - "github.com/go-flutter-desktop/go-flutter/internal/currentthread" "github.com/go-flutter-desktop/go-flutter/internal/priorityqueue" ) // EventLoop is a event loop for the main thread that allows for delayed task -// execution. +// execution.() type EventLoop struct { // store the task (event) by their priorities priorityqueue *priorityqueue.PriorityQueue @@ -23,11 +22,10 @@ type EventLoop struct { // timeout for non-Rendering events that needs to be processed in a polling manner platformMessageRefreshRate time.Duration - - // identifier for the current thread - mainThreadID int64 } +// newEventLoop must ALWAYS be called if the calling goroutine is +// `runtime.LockOSThread()` func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTask) embedder.Result) *EventLoop { pq := priorityqueue.NewPriorityQueue() heap.Init(pq) @@ -35,7 +33,6 @@ func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTas priorityqueue: pq, postEmptyEvent: postEmptyEvent, onExpiredTask: onExpiredTask, - mainThreadID: currentthread.ID(), // 25 Millisecond is arbitrary value, not too high (adds too much delay to // platform messages) and not too low (heavy CPU consumption). @@ -49,10 +46,17 @@ func newEventLoop(postEmptyEvent func(), onExpiredTask func(*embedder.FlutterTas } } -// RunOnCurrentThread return true if tasks posted on the -// calling thread will be run on that same thread. +// RunOnCurrentThread FlutterDocs: +// May be called from any thread. Should return true if tasks posted on the +// calling thread will be run on that same thread. +// +// The functions PostTask and onExpiredTask should be called from the same +// thread, this is ensured if the creation of the event loop (through +// `newEventLoop`) and the PostTask callback (through +// `a.engine.TaskRunnerPostTask = eventLoop.PostTask`) are done on a calling +// goroutine which always execute in that thread (`runtime.LockOSThread()`). func (t *EventLoop) RunOnCurrentThread() bool { - return currentthread.ID() == t.mainThreadID + return true } // PostTask posts a Flutter engine tasks to the event loop for delayed execution. diff --git a/internal/currentthread/thread-id.go b/internal/currentthread/thread-id.go deleted file mode 100644 index a3951b9f..00000000 --- a/internal/currentthread/thread-id.go +++ /dev/null @@ -1,30 +0,0 @@ -// Package currentthread gives you access to the underlying thread id. -package currentthread - -// // -// // Extracted from TinyCThread, a minimalist, portable, threading library for C -// // -// -// /* Platform specific includes */ -// #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__) -// #include -// typedef HANDLE thrd_t; -// #else -// #include -// typedef pthread_t thrd_t; -// #endif -// -// thrd_t thrd_current(void) { -// #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__) -// return GetCurrentThread(); -// #else -// return pthread_self(); -// #endif -// } -// size_t getCurrentThreadID() { return (size_t)thrd_current(); } -import "C" - -// ID returns the id of the current thread -func ID() int64 { - return (int64)(C.getCurrentThreadID()) -}