See #1180 for more
On Unix we override R_PolledEvents() with
libr::set(R_PolledEvents, Some(r_polled_events));
We can't do this on Windows, this concept does not exist there.
There are 2 places on a Unix system where R_PolledEvents() is really called from that we are missing right now on Windows:
I think for the most part this isn't the end of the world. For tasks that typically get run in polled_events() at interrupt time, they instead get run in the main run_event_loop() at idle time.
But we do do this in polled_events() which isn't replicated elsewhere
if let Some(text) = self.debug_filter.check_timeout() {
self.emit_stdout(text);
}
We could consider removing our polled_events() hook altogether. If it isn't being invoked on Windows right now, how useful is it really? That would force us to remove interrupt tasks as a concept altogether, something we have been interested in. It would be worth finding a case where interrupt tasks are very useful on Mac that we are currently lacking on Windows before discarding this idea.
If we want to keep interrupt tasks, on both OSes, we have access to hook into R_ProcessEvents():
- Unix:
ptr_R_ProcessEvents, settable at any moment
- Windows:
Rp->Callback which sets a static ptr_ProcessEvents, settable only at startup
We'd have to reconcile the fact that we can't set Rp->Callback at any moment on windows, meaning RLocalPolledEventsSuspended wouldn't be precisely reproducible for process events, but maybe we could have a global atomic boolean that we flip instead, and our callback would just bail if that is set to false (i.e. suspended).
We also would need to reconcile with the fact that we currently manually call R_ProcessEvents(), and typically we seem to be expecting that tasks dont run at that time (i.e. the comment says we are typically suspended), so that might need some thinking as well
fn process_idle_events() {
// Process regular R events. We're normally running with polled
// events disabled so that won't run here. We also run with
// interrupts disabled, so on Windows those won't get run here
// either (i.e. if `UserBreak` is set), but it will reset `UserBreak`
// so we need to ensure we handle interrupts right before calling
// this.
unsafe { R_ProcessEvents() };
See #1180 for more
On Unix we override
R_PolledEvents()withWe can't do this on Windows, this concept does not exist there.
There are 2 places on a Unix system where
R_PolledEvents()is really called from that we are missing right now on Windows:R_ProcessEvents() ->R_PolledEvents()`R_CheckUserInterrupt()R_CheckUserInterrupt()timeR_runHandlers() -> R_PolledEvents()R_runHandlers()is a unix concept as wellSys.sleep() -> Rsleep() -> R_runHandlers() -> R_PolledEvents()Rsleep()on Unix also callsR_CheckUserInterrupt(), so usingR_ProcessEvents()would work hereRsleep()on Windows directly callsR_ProcessEvents()I think for the most part this isn't the end of the world. For tasks that typically get run in
polled_events()at interrupt time, they instead get run in the mainrun_event_loop()at idle time.But we do do this in
polled_events()which isn't replicated elsewhereWe could consider removing our
polled_events()hook altogether. If it isn't being invoked on Windows right now, how useful is it really? That would force us to remove interrupt tasks as a concept altogether, something we have been interested in. It would be worth finding a case where interrupt tasks are very useful on Mac that we are currently lacking on Windows before discarding this idea.If we want to keep interrupt tasks, on both OSes, we have access to hook into
R_ProcessEvents():ptr_R_ProcessEvents, settable at any momentRp->Callbackwhich sets a staticptr_ProcessEvents, settable only at startupWe'd have to reconcile the fact that we can't set
Rp->Callbackat any moment on windows, meaningRLocalPolledEventsSuspendedwouldn't be precisely reproducible for process events, but maybe we could have a global atomic boolean that we flip instead, and our callback would just bail if that is set tofalse(i.e. suspended).We also would need to reconcile with the fact that we currently manually call
R_ProcessEvents(), and typically we seem to be expecting that tasks dont run at that time (i.e. the comment says we are typically suspended), so that might need some thinking as well