File tree Expand file tree Collapse file tree 6 files changed +50
-2
lines changed Expand file tree Collapse file tree 6 files changed +50
-2
lines changed Original file line number Diff line number Diff line change
1
+ 2018-06-06 Kevin Ushey <
[email protected] >
2
+
3
+ * inst/include/Rcpp/RNGScope.h: Allow suspension of RNG synchronization
4
+ * inst/include/Rcpp/routines.h: Idem
5
+ * src/Rcpp_init.cpp: Idem
6
+ * src/api.cpp: Idem
1
7
2
8
2018-06-02 Lionel Henry <
[email protected] >
3
9
Original file line number Diff line number Diff line change 9
9
\itemize {
10
10
\item The random number \code {Generator } class no longer inhreits from
11
11
\code {RNGScope } (Kevin in \ghpr {837 } fixing \ghit {836 }).
12
+ \item A new class , \code {SuspendRNGSynchronizationScope }, can be created
13
+ and used to ensure that calls to Rcpp functions do not attempt to call
14
+ \code {:: GetRNGstate()} or \code {:: PutRNGstate()} for the duration of
15
+ some code block.
12
16
\item A spurious parenthesis was removed to please gcc8 (Dirk
13
17
fixing \ghit {841 })
14
18
\item The optional \code {Timer } class header now undefines
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ class RNGScope{
30
30
~RNGScope (){ internal::exitRNGScope (); }
31
31
};
32
32
33
+ class SuspendRNGSynchronizationScope {
34
+ public:
35
+ SuspendRNGSynchronizationScope () { internal::beginSuspendRNGSynchronization (); }
36
+ ~SuspendRNGSynchronizationScope () { internal::endSuspendRNGSynchronization (); }
37
+ };
38
+
33
39
} // namespace Rcpp
34
40
35
41
#endif
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ namespace Rcpp{
31
31
namespace internal {
32
32
unsigned long enterRNGScope ();
33
33
unsigned long exitRNGScope ();
34
+ unsigned long beginSuspendRNGSynchronization ();
35
+ unsigned long endSuspendRNGSynchronization ();
34
36
char * get_string_buffer ();
35
37
SEXP get_Rcpp_namespace ();
36
38
}
@@ -86,6 +88,18 @@ namespace Rcpp {
86
88
return fun ();
87
89
}
88
90
91
+ inline attribute_hidden unsigned long beginSuspendRNGSynchronization (){
92
+ typedef unsigned long (*Fun)(void );
93
+ static Fun fun = GET_CALLABLE (" beginSuspendRNGSynchronization" );
94
+ return fun ();
95
+ }
96
+
97
+ inline attribute_hidden unsigned long endSuspendRNGSynchronization (){
98
+ typedef unsigned long (*Fun)(void );
99
+ static Fun fun = GET_CALLABLE (" endSuspendRNGSynchronization" );
100
+ return fun ();
101
+ }
102
+
89
103
inline attribute_hidden char * get_string_buffer (){
90
104
typedef char * (*Fun)(void );
91
105
static Fun fun = GET_CALLABLE (" get_string_buffer" );
Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ void registerFunctions(){
94
94
RCPP_REGISTER (demangle)
95
95
RCPP_REGISTER (enterRNGScope)
96
96
RCPP_REGISTER (exitRNGScope)
97
+ RCPP_REGISTER (beginSuspendRNGSynchronization);
98
+ RCPP_REGISTER (endSuspendRNGSynchronization);
97
99
RCPP_REGISTER (get_Rcpp_namespace)
98
100
RCPP_REGISTER (get_cache)
99
101
RCPP_REGISTER (stack_trace)
Original file line number Diff line number Diff line change @@ -65,18 +65,34 @@ namespace Rcpp {
65
65
66
66
namespace internal {
67
67
68
+ int rngSynchronizationSuspended = 0 ;
69
+
68
70
// [[Rcpp::register]]
69
71
unsigned long enterRNGScope () {
70
- GetRNGstate ();
72
+ if (rngSynchronizationSuspended == 0 )
73
+ GetRNGstate ();
71
74
return 0 ;
72
75
}
73
76
74
77
// [[Rcpp::register]]
75
78
unsigned long exitRNGScope () {
76
- PutRNGstate ();
79
+ if (rngSynchronizationSuspended == 0 )
80
+ PutRNGstate ();
77
81
return 0 ;
78
82
}
79
83
84
+ // [[Rcpp::register]]
85
+ unsigned long beginSuspendRNGSynchronization () {
86
+ ++rngSynchronizationSuspended;
87
+ return rngSynchronizationSuspended;
88
+ }
89
+
90
+ // [[Rcpp::register]]
91
+ unsigned long endSuspendRNGSynchronization () {
92
+ --rngSynchronizationSuspended;
93
+ return rngSynchronizationSuspended;
94
+ }
95
+
80
96
// [[Rcpp::register]]
81
97
char * get_string_buffer () {
82
98
static char buffer[MAXELTSIZE];
You can’t perform that action at this time.
0 commit comments