Rcpp Version 1.0.9
Interrupt.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Interrupt.h: Rcpp R/C++ interface class library -- check for interrupts
4 //
5 // Copyright (C) 2009 - 2013 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp_Interrupt_h
23 #define Rcpp_Interrupt_h
24 
25 #include <R_ext/GraphicsEngine.h>
26 
27 namespace Rcpp {
28 
29  // Internal functions used in the implementation of checkUserInterrupt
30  namespace internal {
31 
32  // Sentinel class for communicating interrupts to the top-level END_RCPP macro
34 
35  // Sentinel object of class "interrupted-error" which is used for
36  // communicating interrupts accross module boundaries without an
37  // exception (which would crash on windows). This is identical to
38  // the existing "try-error" sentinel object used for communicating
39  // errors accross module boundaries.
40  inline SEXP interruptedError() {
41  Rcpp::Shield<SEXP> interruptedError( Rf_mkString("") );
42  Rf_setAttrib( interruptedError, R_ClassSymbol, Rf_mkString("interrupted-error") ) ;
43  return interruptedError;
44  }
45 
46  } // namespace internal
47 
48  // Helper function to check for interrupts. This is invoked within
49  // R_ToplevelExec so it doesn't longjmp
50  namespace {
51 
52  inline void checkInterruptFn(void* /*dummy*/) {
53  R_CheckUserInterrupt();
54  }
55 
56  } // anonymous namespace
57 
58  // Check for interrupts and throw the sentinel exception if one is pending
59  inline void checkUserInterrupt() {
60  if (R_ToplevelExec(checkInterruptFn, NULL) == FALSE)
62  }
63 
64 } // namespace Rcpp
65 
66 #endif
SEXP interruptedError()
Definition: Interrupt.h:40
Rcpp API.
Definition: algo.h:28
void checkUserInterrupt()
Definition: Interrupt.h:59