-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathzzz.R
68 lines (49 loc) · 2 KB
/
zzz.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# !diagnostics suppress=.dllInfo,.tbbDllInfo,.tbbMallocDllInfo,.tbbMallocProxyDllInfo
# NOTE: we intentionally do _not_ load tbbmalloc_proxy by default, as its
# intended use is to replace the default allocator, something that may be
# dangerous to do by default. in addition, TBB's documentation recommends
# only loading explicitly via e.g. LD_PRELOAD
.dllInfo <- NULL
.tbbDllInfo <- NULL
.tbbMallocDllInfo <- NULL
.tbbMallocProxyDllInfo <- NULL
loadTbbLibrary <- function(name) {
path <- tbbLibraryPath(name)
if (is.null(path))
return(NULL)
if (!file.exists(path)) {
warning("TBB library ", shQuote(name), " not found.")
return(NULL)
}
dyn.load(path, local = FALSE, now = TRUE)
}
.onLoad <- function(libname, pkgname) {
# on Windows, load RcppParallel first
if (.Platform$OS.type == "windows") {
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname)
}
# load tbb, tbbmalloc
.tbbDllInfo <<- loadTbbLibrary("tbb")
.tbbMallocDllInfo <<- loadTbbLibrary("tbbmalloc")
# load tbbmalloc_proxy, but only if requested
useTbbMallocProxy <- Sys.getenv("RCPP_PARALLEL_USE_TBBMALLOC_PROXY", unset = "FALSE")
if (useTbbMallocProxy %in% c("TRUE", "True", "true", "1"))
.tbbMallocProxyDllInfo <<- loadTbbLibrary("tbbmalloc_proxy")
# load RcppParallel library if available
if (.Platform$OS.type != "windows") {
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname, local = FALSE)
}
}
.onUnload <- function(libpath) {
# unload the package library
if (!is.null(.dllInfo))
library.dynam.unload("RcppParallel", libpath)
# NOTE: we do not explicitly unload tbbmalloc_proxy as switching
# the allocator at runtime can cause issues
# unload tbbmalloc if we loaded it
if (!is.null(.tbbMallocDllInfo))
dyn.unload(.tbbMallocDllInfo[["path"]])
# unload tbb if we loaded it
if (!is.null(.tbbDllInfo))
dyn.unload(.tbbDllInfo[["path"]])
}