From 3f172614a97589f2600ccea1e5830133bef41fca Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:01:50 +0000 Subject: [PATCH 1/4] fix a todo with Rf_warningcall_immediate() --- src/later_posix.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/later_posix.cpp b/src/later_posix.cpp index dae77c0d..2741ef3a 100644 --- a/src/later_posix.cpp +++ b/src/later_posix.cpp @@ -55,9 +55,7 @@ void set_fd(bool ready) { hot = true; } else { if (read(pipe_out, buf, BUF_SIZE) < 0) { - // TODO: This sets a warning but it doesn't get displayed until - // after the next R command is executed. Can we make it sooner? - Rf_warning("Failed to read out of pipe for later package"); + Rf_warningcall_immediate(R_NilValue, "Failed to read out of pipe for later package"); } hot = false; } From daa00571971d8764ab06c1134aaba58494ccb25d Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:06:33 +0000 Subject: [PATCH 2/4] as.character() is more performant than sprint() --- R/later.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/later.R b/R/later.R index 886c240e..ffa15095 100644 --- a/R/later.R +++ b/R/later.R @@ -104,7 +104,7 @@ create_loop <- function(parent = current_loop(), autorun = NULL) { lockBinding("id", loop) # Add a weak reference to the loop object in our registry. - .loops[[sprintf("%d", id)]] <- new_weakref(loop) + .loops[[as.character(id)]] <- new_weakref(loop) if (id != 0L) { # Inform the C++ layer that there are no more R references when the handle @@ -126,7 +126,7 @@ notify_r_ref_deleted <- function(loop) { res <- notifyRRefDeleted(loop$id) if (res) { - rm(list = sprintf("%d", loop$id), envir = .loops) + rm(list = as.character(loop$id), envir = .loops) } invisible(res) } @@ -140,7 +140,7 @@ destroy_loop <- function(loop) { res <- deleteCallbackRegistry(loop$id) if (res) { - rm(list = sprintf("%d", loop$id), envir = .loops) + rm(list = as.character(loop$id), envir = .loops) } invisible(res) } @@ -155,7 +155,7 @@ exists_loop <- function(loop) { #' @export current_loop <- function() { id <- getCurrentRegistryId() - loop_weakref <- .loops[[sprintf("%d", id)]] + loop_weakref <- .loops[[as.character(id)]] if (is.null(loop_weakref)) { stop("Current loop with id ", id, " not found.") } From 2120f9fded729043e55cb8eaa533dec31b4fde1e Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:10:10 +0000 Subject: [PATCH 3/4] actually apply the pthread_attr that is created --- inst/include/later.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/later.h b/inst/include/later.h index f935e048..f767e152 100644 --- a/inst/include/later.h +++ b/inst/include/later.h @@ -141,7 +141,7 @@ class BackgroundTask { pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_t t; - pthread_create(&t, NULL, BackgroundTask::task_main, this); + pthread_create(&t, &attr, BackgroundTask::task_main, this); pthread_attr_destroy(&attr); #else HANDLE hThread = ::CreateThread( From 0612c1ed3c14573826c64869c8ba63fa3fd2c4b1 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:34:40 +0000 Subject: [PATCH 4/4] enable -DRCPP_NO_MODULES for faster compilation --- src/Makevars.in | 2 +- src/Makevars.win | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makevars.in b/src/Makevars.in index f466648c..f7be559a 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -1,4 +1,4 @@ -PKG_CPPFLAGS = -pthread -DSTRICT_R_HEADERS @pkg_cppflags@ +PKG_CPPFLAGS = -pthread -DSTRICT_R_HEADERS -DRCPP_NO_MODULES @pkg_cppflags@ PKG_LIBS = -pthread @extra_pkg_libs@ #### Debugging flags #### diff --git a/src/Makevars.win b/src/Makevars.win index c0ecc8ae..869cd320 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -1,4 +1,4 @@ -PKG_CPPFLAGS = -DSTRICT_R_HEADERS +PKG_CPPFLAGS = -DSTRICT_R_HEADERS -DRCPP_NO_MODULES PKG_LIBS = -lWs2_32 #### Debugging flags ####