Skip to content

Commit 701bffe

Browse files
committed
refactor: delete the managed application runner
`proton_app_run` existed because AppKit insists on owning the macOS main thread. It took that thread, ran the platform UI loop plus CEF's native message loop there, and pushed the MoonBit application onto a worker pthread -- which meant every engine call had to marshal back, and the engine grew a second identity: a "managed" mode with its own runtime destroy protocol, its own shutdown handshake, and its own set of APIs that returned PROTON_ERR_UNSUPPORTED because the runner owned the loop. The host loop makes all of that unnecessary. MoonBit's async main now runs on the main thread and `proton_host_loop_poll` advances AppKit and CEF from inside it, so nothing has to cross a thread boundary and every runtime API works in one mode only. Nothing has called `proton_app_run` since the facade stopped using it. What goes with it on macOS: - the PROTON_ENGINE_{RETURN,RETURN_U64,RUN}_ON_MAIN macros and their 44 call sites, plus dialog.m's own copy and notification.m's three hand-written equivalents. proton.c's owner-thread check on every handle is now the only guard, which is what it was always for. - the managed destroy path: begin/finish_managed_runtime_destroy, complete_managed_shutdown_if_ready, and the condition variable the worker thread blocked on. runtime_destroy is a plain function again. - proton_engine_{prepare,run_app_loop,quit_app_loop,finish}_app, which only the runner called, and g_proton_app_terminating, which only finish_app cleared and nothing ever read. - `external_message_pump`, previously off under the runner, is now unconditional -- there is no other way to drive CEF. The `managed_app_runner` feature string and `@native.run_app` go too. proton_smoke's app-entry test and the runtime-info assertion in native_wbtest now assert the removal instead of the behaviour, matching how proton_exports_smoke already tracks retired exports. The Linux and Windows engines still reference the runner; their sweep follows. Neither can be compiled here, so it is kept separate.
1 parent 02ae40e commit 701bffe

21 files changed

Lines changed: 48 additions & 2166 deletions

native/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@ endif()
1111
option(PROTON_WITH_ENGINE "Build Proton with the native browser engine linked" OFF)
1212
set(PROTON_ENGINE_ROOT "" CACHE PATH "Native browser engine runtime/SDK root")
1313
set(PROTON_ENGINE_SOURCES src/engine/proton_engine_none.c)
14-
set(PROTON_APP_RUNNER_SOURCE src/app_runner_stub.c)
1514
set(PROTON_NOTIFICATION_SOURCE src/engine/notification_stub.c)
1615
set(PROTON_PLATFORM_EVENT_SOURCES src/engine/platform_events_stub.c)
1716

1817
if(PROTON_WITH_ENGINE)
1918
if(WIN32)
20-
set(PROTON_APP_RUNNER_SOURCE src/app_runner_win.c)
2119
set(PROTON_ENGINE_SOURCES
2220
src/engine/cef_win/proton_engine_cef_win.c
2321
src/engine/cef_win/proton_win_titlebar.c
2422
)
2523
elseif(APPLE)
2624
enable_language(OBJC CXX OBJCXX)
27-
set(PROTON_APP_RUNNER_SOURCE src/app_runner.m)
2825
set(PROTON_NOTIFICATION_SOURCE src/engine/cef_mac/notification.m)
2926
set(PROTON_PLATFORM_EVENT_SOURCES
3027
src/engine/cef_mac/launch_input.m
@@ -36,7 +33,6 @@ if(PROTON_WITH_ENGINE)
3633
src/engine/cef_mac/menu.m
3734
)
3835
elseif(UNIX)
39-
set(PROTON_APP_RUNNER_SOURCE src/app_runner_linux.c)
4036
set(PROTON_ENGINE_SOURCES
4137
src/engine/cef_linux/proton_engine_cef_linux.c
4238
src/engine/cef_linux/proton_linux_titlebar.c
@@ -67,7 +63,6 @@ add_library(proton SHARED
6763
src/proton_state.c
6864
src/proton_update.c
6965
src/proton.c
70-
${PROTON_APP_RUNNER_SOURCE}
7166
${PROTON_NOTIFICATION_SOURCE}
7267
${PROTON_PLATFORM_EVENT_SOURCES}
7368
src/engine/cef_common/bridge_lifecycle.c

native/README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,13 @@ caller still drains `proton_runtime_poll_*` until the queues are empty. Engine
4545
builds on Windows, macOS, and Linux expose the `runtime_wait` feature. ABI-only
4646
builds return `PROTON_ERR_UNSUPPORTED`.
4747

48-
On macOS, Windows, and Linux, `proton_app_run` owns the calling UI thread and
49-
runs the platform UI loop plus CEF's native message loop there. It creates one
50-
application thread for the MoonBit async scheduler and joins that thread only
51-
after the application entry has returned. Public runtime and window handles
52-
are created and owned by the application thread; native engine operations
53-
marshal to the UI thread. Native callbacks never enter MoonBit. They enqueue
54-
work and signal the facade's wakeup source so the MoonBit scheduler can resume
55-
the waiting task. macOS and Linux use a non-blocking pipe descriptor supplied
56-
by MoonBit. Windows exposes a platform-owned named pipe that MoonBit opens
57-
before activating it. Linux dispatches UI work through the GLib main context
58-
owned by the runner. Under this managed runner, `proton_runtime_run`,
59-
`proton_runtime_quit`, `proton_runtime_do_message_loop_work`,
60-
`proton_runtime_wait`, and `proton_runtime_next_wakeup_delay_ms` return
61-
`PROTON_ERR_UNSUPPORTED`.
48+
The host owns the main thread on every platform. `proton_host_loop_begin`,
49+
`proton_host_loop_poll`, and `proton_host_loop_end` hand it an event loop that
50+
outlives any individual runtime, and `poll` is what advances the platform
51+
toolkit and CEF's external message pump. Runtime and window handles therefore
52+
belong to the main thread, and there is no marshalling layer between the host
53+
and the engine. Native callbacks never enter MoonBit: they enqueue work and
54+
signal the host loop so the MoonBit scheduler can resume the waiting task.
6255

6356
It also exposes `proton_runtime_probe_json`, which validates the configured
6457
runtime layout before initialization. The probe checks `runtime_root`,

native/include/proton_native.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ typedef int64_t proton_window_id_t;
4848
typedef int64_t proton_view_id_t;
4949
typedef int64_t proton_app_instance_id_t;
5050
typedef int64_t proton_update_stage_id_t;
51-
typedef void (*proton_app_entry_t)(void);
5251

5352
enum {
5453
PROTON_OK = 0,
@@ -91,8 +90,6 @@ PROTON_API int32_t proton_app_instance_attach_runtime(
9190
PROTON_API int32_t
9291
proton_app_instance_destroy(proton_app_instance_id_t instance);
9392

94-
PROTON_API int32_t proton_app_run(proton_app_entry_t entry);
95-
9693
PROTON_API int32_t proton_execute_process(const char *config_json,
9794
int32_t *out_exit_code);
9895

native/src/app_runner.h

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)