2017-08-25 01:40:42 +03:00
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author: Vassil Vassilev <vvasilev@cern.ch>
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
2017-09-15 14:40:40 +03:00
# ifndef CLING_ENTERUSERCODERAII_H
# define CLING_ENTERUSERCODERAII_H
2017-08-25 01:40:42 +03:00
# include "cling/Interpreter/Interpreter.h"
# include "cling/Interpreter/InterpreterCallbacks.h"
namespace cling {
2017-08-30 22:36:03 +03:00
///\brief Unlocks and then upon destruction locks the interpreter again.
2017-09-15 14:40:40 +03:00
struct EnterUserCodeRAII {
2017-09-15 13:04:05 +03:00
/// Callbacks used to un/lock.
InterpreterCallbacks * fCallbacks ;
/// Info provided to ReturnedFromUserCode().
void * fStateInfo = nullptr ;
2017-09-15 14:40:40 +03:00
EnterUserCodeRAII ( InterpreterCallbacks * callbacks ) : fCallbacks ( callbacks ) {
2017-08-30 22:36:03 +03:00
if ( fCallbacks )
fStateInfo = fCallbacks - > EnteringUserCode ( ) ;
}
2017-08-25 01:40:42 +03:00
2017-09-15 14:40:40 +03:00
EnterUserCodeRAII ( Interpreter & interp ) :
EnterUserCodeRAII ( interp . getCallbacks ( ) ) { }
2017-08-25 01:40:42 +03:00
2017-09-15 14:40:40 +03:00
~ EnterUserCodeRAII ( ) {
2017-08-30 22:36:03 +03:00
if ( fCallbacks )
fCallbacks - > ReturnedFromUserCode ( fStateInfo ) ;
}
} ;
2017-09-15 13:04:05 +03:00
struct LockCompilationDuringUserCodeExecutionRAII {
/// Callbacks used to un/lock.
InterpreterCallbacks * fCallbacks ;
/// Info provided to UnlockCompilationDuringUserCodeExecution().
void * fStateInfo = nullptr ;
LockCompilationDuringUserCodeExecutionRAII ( InterpreterCallbacks * callbacks ) :
fCallbacks ( callbacks ) {
if ( fCallbacks )
fStateInfo = fCallbacks - > LockCompilationDuringUserCodeExecution ( ) ;
}
LockCompilationDuringUserCodeExecutionRAII ( Interpreter & interp ) :
LockCompilationDuringUserCodeExecutionRAII ( interp . getCallbacks ( ) ) { }
~ LockCompilationDuringUserCodeExecutionRAII ( ) {
if ( fCallbacks )
fCallbacks - > UnlockCompilationDuringUserCodeExecution ( fStateInfo ) ;
}
} ;
2017-08-25 01:40:42 +03:00
}
2017-09-15 14:40:40 +03:00
# endif // CLING_ENTERUSERCODERAII_H