Skip to content

Commit 580a83e

Browse files
committed
consolidate loaders
1 parent 38de635 commit 580a83e

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

R/hooks.R

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,31 @@
11

2-
dllInfo <- NULL
3-
mallocDllInfo <- NULL
2+
.tbbDllInfo <- NULL
3+
.tbbMallocDllInfo <- NULL
4+
.tbbMallocProxyDllInfo <- NULL
45

5-
.onLoad <- function(libname, pkgname) {
6+
loadTbbLibrary <- function(name) {
67

7-
# load tbb and tbbmalloc on supported platforms
8-
tbb <- tbbLibraryPath("tbb")
9-
if (!is.null(tbb)) {
10-
if (!file.exists(tbb)) {
11-
warning(paste("TBB library", tbb, "not found."))
12-
} else {
13-
dllInfo <<- dyn.load(tbb, local = FALSE, now = TRUE)
14-
}
15-
}
8+
path <- tbbLibraryPath(name)
9+
if (is.null(path))
10+
return(NULL)
1611

17-
tbbMalloc <- tbbLibraryPath("tbbmalloc")
18-
if (!is.null(tbbMalloc)) {
19-
if (!file.exists(tbbMalloc)) {
20-
warning(paste("TBB malloc library", tbbMalloc, "not found."))
21-
} else {
22-
mallocDllInfo <<- dyn.load(tbbMalloc, local = FALSE, now = TRUE)
23-
}
12+
if (!file.exists(path)) {
13+
warning("TBB library ", shQuote(name), " not found.")
14+
return(NULL)
2415
}
2516

26-
# work around roxygen2 issue
27-
documenting <- FALSE
28-
checks <- list(
29-
call("::", as.symbol("devtools"), as.symbol("document")),
30-
call("::", as.symbol("roxygen2"), as.symbol("roxygenize"))
31-
)
32-
33-
for (call in sys.calls()) {
34-
for (check in checks) {
35-
if (identical(call[[1L]], check)) {
36-
documenting <- TRUE
37-
break
38-
}
39-
}
40-
}
17+
dyn.load(path, local = FALSE, now = TRUE)
4118

42-
if (!documenting)
43-
library.dynam("RcppParallel", pkgname, libname)
19+
}
20+
21+
.onLoad <- function(libname, pkgname) {
22+
23+
# load tbb, tbbmalloc, tbbmalloc_proxy
24+
.tbbDllInfo <<- loadTbbLibrary("tbb")
25+
.tbbMallocDllInfo <<- loadTbbLibrary("tbbmalloc")
26+
.tbbMallocProxyDllInfo <<- loadTbbLibrary("tbbmalloc_proxy")
27+
28+
library.dynam("RcppParallel", pkgname, libname)
4429

4530
}
4631

@@ -50,11 +35,9 @@ mallocDllInfo <- NULL
5035
library.dynam.unload("RcppParallel", libpath)
5136

5237
# unload tbb if we loaded it
53-
if (!is.null(dllInfo))
54-
dyn.unload(dllInfo[["path"]])
55-
56-
# unload tbbmalloc if we loaded it
57-
if (!is.null(mallocDllInfo))
58-
dyn.unload(mallocDllInfo[["path"]])
38+
dlls <- list(.tbbDllInfo, .tbbMallocDllInfo, .tbbMallocProxyDllInfo)
39+
for (dll in dlls)
40+
if (!is.null(dll))
41+
dyn.unload(dll[["path"]])
5942

6043
}

R/tbb.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ tbbLibraryPath <- function(name = NULL) {
3030
)
3131

3232
# skip systems that we know not to be compatible
33-
isCompatible <-
34-
!is_sparc() &&
35-
!is.null(tbbLibNames[[sysname]])
36-
33+
isCompatible <- !is_sparc() && !is.null(tbbLibNames[[sysname]])
3734
if (!isCompatible)
3835
return(NULL)
3936

0 commit comments

Comments
 (0)